Skip to content

Commit

Permalink
[ZEPPELIN-5958] Migrate shell to JUnit5 (#4653)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reamer authored Sep 13, 2023
1 parent e8aff24 commit fade856
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
import org.apache.zeppelin.interpreter.InterpreterOutput;
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventClient;
import org.apache.zeppelin.user.AuthenticationInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import java.util.concurrent.atomic.AtomicInteger;

import static org.mockito.Mockito.mock;

public abstract class BaseInterpreterTest {

@Before
@BeforeEach
public abstract void setUp() throws InterpreterException;

@After
@AfterEach
public abstract void tearDown() throws InterpreterException;

protected InterpreterContext getIntpContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@

package org.apache.zeppelin.shell;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.zeppelin.interpreter.InterpreterException;
import org.apache.zeppelin.interpreter.InterpreterOutput;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Properties;

import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ShellInterpreterTest {
class ShellInterpreterTest {

private ShellInterpreter shell;
private InterpreterContext context;
private InterpreterResult result;

@Before
@BeforeEach
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("shell.command.timeout.millisecs", "5000");
Expand All @@ -50,12 +49,12 @@ public void setUp() throws Exception {
shell.open();
}

@After
@AfterEach
public void tearDown() throws Exception {
}

@Test
public void test() throws InterpreterException {
void test() throws InterpreterException {
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("dir", context);
} else {
Expand All @@ -69,7 +68,7 @@ public void test() throws InterpreterException {
}

@Test
public void testInvalidCommand() throws InterpreterException {
void testInvalidCommand() throws InterpreterException {
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("invalid_command\ndir", context);
} else {
Expand All @@ -80,7 +79,7 @@ public void testInvalidCommand() throws InterpreterException {
}

@Test
public void testShellTimeout() throws InterpreterException {
void testShellTimeout() throws InterpreterException {
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("timeout 8", context);
} else {
Expand All @@ -92,7 +91,7 @@ public void testShellTimeout() throws InterpreterException {
}

@Test
public void testShellTimeout2() throws InterpreterException {
void testShellTimeout2() throws InterpreterException {
context = InterpreterContext.builder()
.setParagraphId("paragraphId")
.setInterpreterOut(new InterpreterOutput())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,34 @@
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.apache.zeppelin.shell.terminal.TerminalSocketTest;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.URI;
import java.util.Properties;
import java.util.regex.Pattern;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class TerminalInterpreterTest extends BaseInterpreterTest {
class TerminalInterpreterTest extends BaseInterpreterTest {
private static final Logger LOGGER = LoggerFactory.getLogger(TerminalInterpreterTest.class);

private TerminalInterpreter terminal;
private InterpreterContext intpContext;
private InterpreterResult result;

@Override
@BeforeEach
public void setUp() throws InterpreterException {
Properties p = new Properties();
intpContext = getIntpContext();
Expand All @@ -62,12 +66,13 @@ public void setUp() throws InterpreterException {
}

@Override
@AfterEach
public void tearDown() throws InterpreterException {
terminal.close();
}

@Test
public void testInvalidCommand() {
void testInvalidCommand() {
Session session = null;
WebSocketContainer webSocketContainer = null;

Expand Down Expand Up @@ -147,7 +152,7 @@ public void testInvalidCommand() {
}

@Test
public void testValidCommand() {
void testValidCommand() {
Session session = null;
WebSocketContainer webSocketContainer = null;

Expand Down

0 comments on commit fade856

Please sign in to comment.