Skip to content

Commit

Permalink
Modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minahlee committed Sep 2, 2016
1 parent c777135 commit 954127f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,21 @@ public void testCreateNewButton() throws Exception {
ZeppelinITUtils.sleep(1000, false);
waitForParagraph(1, "READY");

String oldIntpTag = driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText();

collector.checkThat("Paragraph is created above",
driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(),
CoreMatchers.not(StringUtils.EMPTY));
CoreMatchers.equalTo(StringUtils.EMPTY));
setTextOfParagraph(1, " this is above ");


newPara = driver.findElement(By.xpath(getParagraphXPath(2) + "//div[contains(@class,'new-paragraph')][2]"));
action.moveToElement(newPara).click().build().perform();

waitForParagraph(3, "READY");

String lastIntpTag = driver.findElement(By.xpath(getParagraphXPath(3) + "//div[contains(@class, 'editor')]")).getText();

collector.checkThat("Paragraph is created below",
driver.findElement(By.xpath(getParagraphXPath(3) + "//div[contains(@class, 'editor')]")).getText(),
CoreMatchers.not(StringUtils.EMPTY));
CoreMatchers.equalTo(StringUtils.EMPTY));
setTextOfParagraph(3, " this is below ");

collector.checkThat("Compare interpreter name tag", oldIntpTag, CoreMatchers.equalTo(lastIntpTag));

collector.checkThat("The output field of paragraph1 contains",
driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(),
CoreMatchers.equalTo(" this is above "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ public void testNotebookCreateWithParagraphs() throws IOException {
assertEquals("compare note name", expectedNoteName, newNoteName);
assertEquals("initial paragraph check failed", 3, newNote.getParagraphs().size());
for (Paragraph p : newNote.getParagraphs()) {
if (StringUtils.isEmpty(p.getText()) ||
p.getText().trim().equals(newNote.getLastInterpreterName())) {
if (StringUtils.isEmpty(p.getText())) {
continue;
}
assertTrue("paragraph title check failed", p.getTitle().startsWith("title"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package org.apache.zeppelin.notebook;

import com.google.common.base.Optional;

import org.apache.commons.lang.StringUtils;
import org.apache.zeppelin.interpreter.Interpreter;
import org.apache.zeppelin.interpreter.InterpreterFactory;
import org.apache.zeppelin.interpreter.InterpreterSetting;
Expand Down Expand Up @@ -83,71 +80,47 @@ public void runNormalTest() {
}

@Test
public void putDefaultReplNameIfInterpreterSettingAbsent() {
when(interpreterFactory.getDefaultInterpreterSetting(anyString()))
.thenReturn(null);

public void addParagraphWithEmptyReplNameTest() {
Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName();

assertEquals(StringUtils.EMPTY, note.getLastReplName());
assertEquals(StringUtils.EMPTY, note.getLastInterpreterName());
Paragraph p = note.addParagraph();
assertNull(p.getText());
}

@Test
public void putDefaultReplNameIfInterpreterSettingPresent() {
InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class);
when(interpreterSetting.getName()).thenReturn("spark");
when(interpreterFactory.getDefaultInterpreterSetting(anyString()))
.thenReturn(interpreterSetting);
public void addParagraphWithLastReplNameTest() {
when(interpreterFactory.getInterpreter(anyString(), eq("spark"))).thenReturn(interpreter);

Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName();
Paragraph p1 = note.addParagraph();
p1.setText("%spark ");
Paragraph p2 = note.addParagraph();

assertEquals("spark", note.getLastReplName());
assertEquals("%spark", note.getLastInterpreterName());
assertEquals("%spark\n", p2.getText());
}

@Test
public void addParagraphWithLastReplName() {
InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class);
when(interpreterSetting.getName()).thenReturn("spark");
when(interpreterFactory.getDefaultInterpreterSetting(anyString()))
.thenReturn(interpreterSetting);
public void insertParagraphWithLastReplNameTest() {
when(interpreterFactory.getInterpreter(anyString(), eq("spark"))).thenReturn(interpreter);

Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName(); //set lastReplName

Paragraph p = note.addParagraph();
Paragraph p1 = note.addParagraph();
p1.setText("%spark ");
Paragraph p2 = note.insertParagraph(note.getParagraphs().size());

assertEquals("%spark ", p.getText());
assertEquals("%spark\n", p2.getText());
}

@Test
public void insertParagraphWithLastReplName() {
InterpreterSetting interpreterSetting = Mockito.mock(InterpreterSetting.class);
when(interpreterSetting.getName()).thenReturn("spark");
when(interpreterFactory.getDefaultInterpreterSetting(anyString()))
.thenReturn(interpreterSetting);
public void insertParagraphWithInvalidReplNameTest() {
when(interpreterFactory.getInterpreter(anyString(), eq("invalid"))).thenReturn(null);

Note note = new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener);
note.putDefaultReplName(); //set lastReplName

Paragraph p = note.insertParagraph(note.getParagraphs().size());
Paragraph p1 = note.addParagraph();
p1.setText("%invalid ");
Paragraph p2 = note.insertParagraph(note.getParagraphs().size());

assertEquals("%spark ", p.getText());
assertNull(p2.getText());
}

@Test
public void setLastReplName() {
String paragraphId = "HelloWorld";
Note note = Mockito.spy(new Note(repo, interpreterFactory, jobListenerFactory, index, credentials, noteEventListener));
Paragraph mockParagraph = Mockito.mock(Paragraph.class);
when(note.getParagraph(paragraphId)).thenReturn(mockParagraph);
when(mockParagraph.getRequiredReplName()).thenReturn("spark");

note.setLastReplName(paragraphId);

assertEquals("spark", note.getLastReplName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void getRevisionTest() throws IOException {
Map<String, Object> config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("%md checkpoint test text");
p1.setText("checkpoint test text");
notebookRepo.save(note, null);

// second checkpoint
Expand All @@ -245,7 +245,7 @@ public void getRevisionTest() throws IOException {
Paragraph p2 = note.addParagraph();
config.put("enabled", false);
p2.setConfig(config);
p2.setText("%md get revision when modified note test text");
p2.setText("get revision when modified note test text");
notebookRepo.save(note, null);
note = notebookRepo.get(TEST_NOTE_ID, null);
int paragraphCount_3 = note.getParagraphs().size();
Expand Down Expand Up @@ -282,7 +282,7 @@ public void getRevisionFailTest() throws IOException {
Map<String, Object> config = p1.getConfig();
config.put("enabled", true);
p1.setConfig(config);
p1.setText("%md get revision when modified note test text");
p1.setText("get revision when modified note test text");
notebookRepo.save(note, null);
int paragraphCount_2 = note.getParagraphs().size();

Expand Down

0 comments on commit 954127f

Please sign in to comment.