Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javrasya/ac4158b2ab00ec1d0c803ab1e2da6790 to your computer and use it in GitHub Desktop.
Save javrasya/ac4158b2ab00ec1d0c803ab1e2da6790 to your computer and use it in GitHub Desktop.
package dal.ahmet.hive.unittest;
import com.klarna.hiverunner.HiveShell;
import com.klarna.hiverunner.StandaloneHiveRunner;
import com.klarna.hiverunner.annotations.HiveSQL;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
import java.util.List;
* Created by ahmetdal on 02/09/16.
public class StudentCountReportTest {
private String database = "mydatabase";
@HiveSQL(files = {})
private HiveShell hiveShell;
public void setUp() throws FileNotFoundException {
// Create the database
hiveShell.execute("CREATE DATABASE IF NOT EXISTS " + database + ";");
// Create Tables
private void insertInto(String table, String resourcePath) {
String delimiter = ",";
String nullValue = "\\N";
hiveShell.insertInto(database, table)
new File(
private File getResourceFile(String resourcePath) throws FileNotFoundException {
URL url = getClass().getClassLoader().getResource(resourcePath);
if (null == url) {
throw new FileNotFoundException(resourcePath);
return new File(url.getPath());
public void testSuccessCase1() throws FileNotFoundException {
// Insert test data
insertInto("school", "StudentCountReportTest/successCase1/school.csv");
insertInto("student", "StudentCountReportTest/successCase1/student.csv");
// Execute the report
// Check and assert the result
List<Object[]> actualResultSet = hiveShell.executeStatement("select * from student_count_report order by school_name");
List<Object[]> expectedResultSet = Arrays.asList(
new Object[]{"Atatürk Lisesi", 2L},
new Object[]{"Cumhuriyet İlköğretim Okulu", 5L},
new Object[]{"Samsun Anadolu Lisesi", 3L}
Assert.assertArrayEquals(expectedResultSet.toArray(), actualResultSet.toArray());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment