Skip to content

Commit

Permalink
[ZEPPELIN-5951] migrate bigquery to Junit5 (#4645)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reamer authored Sep 11, 2023
1 parent 5eb9824 commit b1fbb8a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,21 @@

package org.apache.zeppelin.bigquery;

import static org.junit.Assert.assertEquals;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.zeppelin.interpreter.InterpreterContext;
import org.apache.zeppelin.interpreter.InterpreterGroup;
import org.apache.zeppelin.interpreter.InterpreterResult;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class BigQueryInterpreterTest {
class BigQueryInterpreterTest {
protected static class Constants {
private String projectId;
private String oneQuery;
Expand All @@ -55,20 +51,18 @@ public String getWrong() {

protected static Constants constants = null;

public BigQueryInterpreterTest()
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
if (constants == null) {
InputStream is = this.getClass().getResourceAsStream("/constants.json");
constants = (new Gson()).<Constants>fromJson(new InputStreamReader(is), Constants.class);
}
@BeforeAll
public static void initConstants() {
InputStream is = ClassLoader.class.getResourceAsStream("/constants.json");
constants = (new Gson()).<Constants> fromJson(new InputStreamReader(is), Constants.class);
}

private InterpreterGroup intpGroup;
private BigQueryInterpreter bqInterpreter;

private InterpreterContext context;

@Before
@BeforeEach
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("zeppelin.bigquery.project_id", constants.getProjectId());
Expand All @@ -84,27 +78,27 @@ public void setUp() throws Exception {
}

@Test
public void sqlSuccess() {
void sqlSuccess() {
InterpreterResult ret = bqInterpreter.interpret(constants.getOne(), context);
assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
assertEquals(ret.message().get(0).getType(), InterpreterResult.Type.TABLE);
assertEquals(InterpreterResult.Type.TABLE, ret.message().get(0).getType());
}

@Test
public void badSqlSyntaxFails() {
void badSqlSyntaxFails() {
InterpreterResult ret = bqInterpreter.interpret(constants.getWrong(), context);
assertEquals(InterpreterResult.Code.ERROR, ret.code());
}

@Test
public void testWithQueryPrefix() {
void testWithQueryPrefix() {
InterpreterResult ret = bqInterpreter.interpret(
"#standardSQL\n WITH t AS (select 1) SELECT * FROM t", context);
assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
}

@Test
public void testInterpreterOutputData() {
void testInterpreterOutputData() {
InterpreterResult ret = bqInterpreter.interpret("SELECT 1 AS col1, 2 AS col2", context);
String[] lines = ret.message().get(0).getData().split("\\n");
assertEquals(2, lines.length);
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions bigquery/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c:%L - %m%n
#log4j.appender.stdout.layout.ConversionPattern=
#%5p [%t] (%F:%L) - %m%n
#%-4r [%t] %-5p %c %x - %m%n
#

# Root logger option
log4j.rootLogger=INFO, stdout
#log4j.logger.org.apache.zeppelin.interpreter=DEBUG

0 comments on commit b1fbb8a

Please sign in to comment.