zjffdu commented on a change in pull request #3432: [ZEPPELIN-4068] Implement MongoNotebookRepo. URL: https://github.com/apache/zeppelin/pull/3432#discussion_r317863077
########## File path: zeppelin-plugins/notebookrepo/mongo/src/test/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepoTest.java ########## @@ -0,0 +1,109 @@ +package org.apache.zeppelin.notebook.repo; + +import static org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_MONGO_URI; +import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import java.io.IOException; +import java.net.ServerSocket; +import java.util.Map; +import de.flapdoodle.embed.mongo.MongodExecutable; +import de.flapdoodle.embed.mongo.MongodStarter; +import de.flapdoodle.embed.mongo.config.IMongodConfig; +import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; +import de.flapdoodle.embed.mongo.config.Net; +import de.flapdoodle.embed.mongo.distribution.Version; +import de.flapdoodle.embed.process.runtime.Network; +import org.apache.zeppelin.conf.ZeppelinConfiguration; +import org.apache.zeppelin.notebook.Note; +import org.apache.zeppelin.notebook.NoteInfo; +import org.apache.zeppelin.notebook.Paragraph; +import org.apache.zeppelin.user.AuthenticationInfo; + +public class MongoNotebookRepoTest { + + private MongodExecutable mongodExecutable; + + private ZeppelinConfiguration zConf; + + private MongoNotebookRepo notebookRepo; + + @Before + public void setUp() throws IOException { + String bindIp = "localhost"; + int port = new ServerSocket(0).getLocalPort(); + + IMongodConfig mongodConfig = new MongodConfigBuilder() + .version(Version.Main.PRODUCTION) + .net(new Net(bindIp, port, Network.localhostIsIPv6())) + .build(); + + mongodExecutable = MongodStarter.getDefaultInstance() + .prepare(mongodConfig); + mongodExecutable.start(); + + System.setProperty(ZEPPELIN_NOTEBOOK_MONGO_URI.getVarName(), "mongodb://" + bindIp + ":" + port); + zConf = new ZeppelinConfiguration(); + notebookRepo = new MongoNotebookRepo(); + notebookRepo.init(zConf); + } + + @After + public void tearDown() throws IOException { + if (mongodExecutable != null) { + mongodExecutable.stop(); + } + } + + @Test + public void testBasics() throws IOException { + assertEquals(0, notebookRepo.list(AuthenticationInfo.ANONYMOUS).size()); + + // create note1 + Note note1 = new Note(); + note1.setPath("/my_project/my_note1"); + Paragraph p1 = note1.insertNewParagraph(0, AuthenticationInfo.ANONYMOUS); + p1.setText("%md hello world"); + p1.setTitle("my title"); + notebookRepo.save(note1, AuthenticationInfo.ANONYMOUS); + + Map<String, NoteInfo> noteInfos = notebookRepo.list(AuthenticationInfo.ANONYMOUS); + assertEquals(1, noteInfos.size()); + assertEquals(note1.getId(), noteInfos.get(note1.getId()).getId()); + assertEquals(note1.getName(), noteInfos.get(note1.getId()).getNoteName()); Review comment: It's better to also verify the paragraph title and text ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services