Skip to content

Commit

Permalink
Integration Tests for SQL Interface (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Harshit authored Sep 1, 2021
1 parent f924c71 commit 9ef2d02
Show file tree
Hide file tree
Showing 15 changed files with 3,522 additions and 0 deletions.
121 changes: 121 additions & 0 deletions config/src/main/java/org/polypheny/db/webui/UiTestingConfigPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2019-2021 The Polypheny Project
*
* Licensed 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.
*/

package org.polypheny.db.webui;

import com.google.common.collect.ImmutableList;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.polypheny.db.config.Config;
import org.polypheny.db.config.ConfigBoolean;
import org.polypheny.db.config.ConfigClazz;
import org.polypheny.db.config.ConfigClazzList;
import org.polypheny.db.config.ConfigDecimal;
import org.polypheny.db.config.ConfigDouble;
import org.polypheny.db.config.ConfigEnum;
import org.polypheny.db.config.ConfigEnumList;
import org.polypheny.db.config.ConfigInteger;
import org.polypheny.db.config.ConfigLong;
import org.polypheny.db.config.ConfigManager;
import org.polypheny.db.config.WebUiGroup;
import org.polypheny.db.config.WebUiPage;


public class UiTestingConfigPage {


private static class TestClass {

int a;

}


private enum testEnum {FOO, BAR, FOO_BAR}


private static class FooImplementation extends TestClass {

int b;

}


private static class BarImplementation extends TestClass {

int c;

}


private static class FooBarImplementation extends TestClass {

int d;

}


static {
ConfigManager cm = ConfigManager.getInstance();

WebUiPage p1 = new WebUiPage( "uiconfigtest", "UiConfigTestPage", "Configuration Description" );

WebUiGroup g1 = new WebUiGroup( "g1", p1.getId(), 1 ).withTitle( "Config" ).withDescription( "Select Config Options" );
WebUiGroup g2 = new WebUiGroup( "g2", p1.getId() ).withTitle( "Config Too" ).withDescription( "Select Config Options" );

cm.registerWebUiPage( p1 );
cm.registerWebUiGroup( g1 );
cm.registerWebUiGroup( g2 );

Config c1 = new ConfigBoolean( "Boolean True Test", true ).withUi( "g1" );
Config c2 = new ConfigBoolean( "Boolean False Test", false ).withUi( "g1" );
Config c3 = new ConfigInteger( "Integer Test", 11 ).withUi( "g1" );
Config c4 = new ConfigInteger( "Negative Integer Test", -1 ).withUi( "g1" );
Config c5 = new ConfigClazz( "clazz Test", TestClass.class, FooImplementation.class ).withUi( "g1" );

List<Class> l = new ArrayList<>();
l.add( FooImplementation.class );
l.add( BarImplementation.class );

Config c6 = new ConfigEnumList( "enumList", "Test description", testEnum.class, ImmutableList.of( testEnum.BAR ) ).withUi( "g1" );
Config c7 = new ConfigClazzList( "clazzList Test", TestClass.class, l ).withUi( "g2" );
Config c8 = new ConfigDecimal( "Decimal Test", BigDecimal.valueOf( 43.43431 ) ).withUi( "g2" );
Config c9 = new ConfigDouble( "Double Test", Double.valueOf( 2.2 ) ).withUi( "g2" );
Config c10 = new ConfigEnum( "Enum Test", "Test description", testEnum.class, testEnum.FOO_BAR ).withUi( "g2" );
List<Integer> list = new ArrayList<Integer>();
list.add( 1 );
list.add( 2 );
list.add( 3 );

Config c11 = new ConfigLong( "Long", 12312L ).withUi( "g2" );

// Config c45 = new ConfigList("List",list,TestClass.class);

// int[] array = { 1, 2, 3, 4, 5 };
// Config c40 = new ConfigArray( "array", array ).withUi("g1");

// int[][] table = new int[][]{
// { 1, 2, 3 },
// { 4, 5, 6 }
// };
// Config c41 = new ConfigTable( "table", table ).withUi("g1");
cm.registerConfigs( c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11 );

}


}
8 changes: 8 additions & 0 deletions dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.polypheny.db.webui.ConfigServer;
import org.polypheny.db.webui.HttpServer;
import org.polypheny.db.webui.InformationServer;
import org.polypheny.db.webui.UiTestingConfigPage;
import org.polypheny.db.webui.UiTestingMonitoringPage;


@Command(name = "polypheny-db", description = "Polypheny-DB command line hook.")
Expand Down Expand Up @@ -267,6 +269,12 @@ public void join( final long millis ) throws InterruptedException {
ExploreManager explore = ExploreManager.getInstance();
explore.setExploreQueryProcessor( exploreQueryProcessor );

// Add config and monitoring test page for UI testing
if ( testMode ) {
new UiTestingConfigPage();
new UiTestingMonitoringPage();
}

log.info( "****************************************************************************************************" );
log.info( " Polypheny-DB successfully started and ready to process your queries!" );
log.info( " The UI is waiting for you on port {}:", RuntimeConfig.WEBUI_SERVER_PORT.getInteger() );
Expand Down
145 changes: 145 additions & 0 deletions dbms/src/test/java/org/polypheny/db/sql/clause/GroupByTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright 2019-2021 The Polypheny Project
*
* Licensed 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.
*/

package org.polypheny.db.sql.clause;

import com.google.common.collect.ImmutableList;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.polypheny.db.AdapterTestSuite;
import org.polypheny.db.TestHelper;
import org.polypheny.db.TestHelper.JdbcConnection;
import org.polypheny.db.excluded.CassandraExcluded;
import org.polypheny.db.excluded.FileExcluded;


@SuppressWarnings({ "SqlDialectInspection", "SqlNoDataSourceInspection" })
@Slf4j
@Category({ AdapterTestSuite.class, CassandraExcluded.class })
public class GroupByTest {


@BeforeClass
public static void start() throws SQLException {
// Ensures that Polypheny-DB is running
//noinspection ResultOfMethodCallIgnored
TestHelper.getInstance();
addTestData();
}


private static void addTestData() throws SQLException {
try ( JdbcConnection jdbcConnection = new JdbcConnection( false ) ) {
Connection connection = jdbcConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "CREATE TABLE TestTableA(Id INTEGER NOT NULL,Name VARCHAR(255), Primary key(Id))" );
statement.executeUpdate( "INSERT INTO TestTableA VALUES(1,'Name1')" );
statement.executeUpdate( "INSERT INTO TestTableA VALUES(2,'Name2')" );
statement.executeUpdate( "INSERT INTO TestTableA VALUES(3,'Name3')" );
statement.executeUpdate( "INSERT INTO TestTableA VALUES(4,'Name4')" );
statement.executeUpdate( "INSERT INTO TestTableA VALUES(5,'Name5')" );

statement.executeUpdate( "CREATE TABLE TestTableB(Id INTEGER NOT NULL,Row_Code VARCHAR(255) NOT NULL,Frequency INTEGER, Primary key(Id,Row_Code))" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(1,'A',86)" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(1,'B',86)" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(1,'C',90)" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(2,'A',89)" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(2,'C',92)" );
statement.executeUpdate( "INSERT INTO TestTableB VALUES(3,'C',80)" );

statement.executeUpdate( "CREATE TABLE TestTableC(Id INTEGER NOT NULL,Name VARCHAR(255),location VARCHAR(255), Primary key(Id))" );
statement.executeUpdate( "INSERT INTO TestTableC VALUES(1,'Name1','loc1')" );
statement.executeUpdate( "INSERT INTO TestTableC VALUES(2,'Name2','loc2')" );
statement.executeUpdate( "INSERT INTO TestTableC VALUES(3,'Name3','loc3')" );

statement.executeUpdate( "CREATE TABLE TestTableD(Row_Code VARCHAR(255) NOT NULL,differentname VARCHAR(255),spec VARCHAR(255), Primary key(Row_Code))" );
statement.executeUpdate( "INSERT INTO TestTableD VALUES('A','names1','spec1')" );
statement.executeUpdate( "INSERT INTO TestTableD VALUES('B','names2','spec2')" );
statement.executeUpdate( "INSERT INTO TestTableD VALUES('C','names3','spec3')" );

connection.commit();
}
}
}


@AfterClass
public static void stop() throws SQLException {
try ( JdbcConnection jdbcConnection = new JdbcConnection( true ) ) {
Connection connection = jdbcConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "DROP TABLE TestTableA" );
statement.executeUpdate( "DROP TABLE TestTableB" );
statement.executeUpdate( "DROP TABLE TestTableC" );
statement.executeUpdate( "DROP TABLE TestTableD" );
}
connection.commit();
}
}

// --------------- Tests ---------------


@Test
public void groupByTest() throws SQLException {
try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) {
Connection connection = polyphenyDbConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
List<Object[]> expectedResult = ImmutableList.of(
new Object[]{ "Name1", 443 },
new Object[]{ "Name2", 443 },
new Object[]{ "Name3", 443 },
new Object[]{ "Name4", 443 },
new Object[]{ "Name5", 443 }
);
TestHelper.checkResultSet(
statement.executeQuery( "SELECT S.Name, sum (P.Frequency) FROM TestTableA S, TestTableB P WHERE P.Frequency > 84 GROUP BY S.Name ORDER BY S.Name" ),
expectedResult,
true
);
}
}
}


@Test
@Category(FileExcluded.class)
public void groupByWithInnerSelect() throws SQLException {
try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) {
Connection connection = polyphenyDbConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
List<Object[]> expectedResult = ImmutableList.of(
new Object[]{ 1, "Name1" },
new Object[]{ 2, "Name2" },
new Object[]{ 2, "Name2" }
);
TestHelper.checkResultSet(
statement.executeQuery( "SELECT s.id, s.name FROM TestTableC s, TestTableB t WHERE s.id = t.id AND Frequency > (SELECT AVG (Frequency) FROM TestTableB WHERE row_code = 'C' GROUP BY row_code='C')\n" ),
expectedResult,
true
);
}
}
}

}
Loading

0 comments on commit 9ef2d02

Please sign in to comment.