Переглянути джерело

Clean up SQL container tests. (#8091)

Only one UI smoke test for the SQL container (along with a Table).

Fixes vaadin/framework8-issues#582
tags/8.0.0.beta2
Denis 7 роки тому
джерело
коміт
b302de9c93
14 змінених файлів з 55 додано та 984 видалено
  1. 0
    126
      uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxSQLContainerFilteredValueChange.java
  2. 0
    44
      uitest/src/main/java/com/vaadin/tests/components/table/DisabledSortingTableSqlContainer.java
  3. 0
    99
      uitest/src/main/java/com/vaadin/tests/components/table/TableScrollingWithSQLContainer.java
  4. 0
    27
      uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java
  5. 0
    114
      uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java
  6. 0
    146
      uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/MassInsertMemoryLeakTestApp.java
  7. 0
    47
      uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/SqlcontainertableApplication.java
  8. 0
    130
      uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java
  9. 2
    1
      uitest/src/main/java/com/vaadin/tests/smoke/TableSqlContainer.java
  10. 0
    154
      uitest/src/main/java/com/vaadin/v7/data/util/sqlcontainer/SQLTestsConstants.java
  11. 0
    16
      uitest/src/test/java/com/vaadin/tests/components/table/DisabledSortingTableTest.java
  12. 0
    35
      uitest/src/test/java/com/vaadin/tests/components/table/TableScrollingWithSQLContainerTest.java
  13. 0
    45
      uitest/src/test/java/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKeyTest.java
  14. 53
    0
      uitest/src/test/java/com/vaadin/tests/smoke/TableSqlContainerTest.java

+ 0
- 126
uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxSQLContainerFilteredValueChange.java Переглянути файл

@@ -1,126 +0,0 @@
package com.vaadin.tests.components.combobox;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.util.sqlcontainer.SQLContainer;
import com.vaadin.v7.data.util.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.query.TableQuery;
import com.vaadin.v7.ui.AbstractSelect.Filtering;
import com.vaadin.v7.ui.ComboBox;

public class ComboBoxSQLContainerFilteredValueChange extends TestBase {

@Override
protected void setup() {
VerticalLayout layout = new VerticalLayout();
addComponent(layout);

final ComboBox myCombo = new ComboBox("MyCaption");
layout.addComponent(myCombo);

final Label selectedLabel = new Label("Selected: null");
layout.addComponent(selectedLabel);

try {
JDBCConnectionPool connectionPool = new SimpleJDBCConnectionPool(
"org.hsqldb.jdbc.JDBCDriver",
"jdbc:hsqldb:mem:sqlcontainer", "SA", "", 2, 20);

createTestTable(connectionPool);
insertTestData(connectionPool);

TableQuery q = new TableQuery("mytable", connectionPool);
q.setVersionColumn("version");
SQLContainer myContainer = new SQLContainer(q);

myCombo.setContainerDataSource(myContainer);

} catch (SQLException e) {
e.printStackTrace();
}

myCombo.setItemCaptionPropertyId("MYFIELD");
myCombo.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
myCombo.setImmediate(true);
myCombo.setWidth("100.0%");
myCombo.setHeight("-1px");
myCombo.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
selectedLabel.setValue(
"Selected: " + event.getProperty().getValue());
}
});
}

@Override
protected String getDescription() {
return "Selecting the first filtered item should change the value of the label under the ComboBox to 'Selected: 1'.";
}

@Override
protected Integer getTicketNumber() {
return 10471;
}

/**
* (Re)creates the test table
*
* @param connectionPool
*/
private void createTestTable(JDBCConnectionPool connectionPool) {
Connection conn = null;
try {
conn = connectionPool.reserveConnection();
Statement statement = conn.createStatement();
try {
statement.executeUpdate("DROP TABLE mytable");
} catch (SQLException e) {
}
statement.execute("CREATE TABLE mytable "
+ "(id INTEGER GENERATED BY DEFAULT AS IDENTITY, "
+ "MYFIELD VARCHAR(45), " + "PRIMARY KEY(ID))");
statement.close();
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
connectionPool.releaseConnection(conn);
}
}

/**
* Adds test data to the test table
*
* @param connectionPool
* @throws SQLException
*/
private void insertTestData(JDBCConnectionPool connectionPool)
throws SQLException {
Connection conn = null;
try {
conn = connectionPool.reserveConnection();
Statement statement = conn.createStatement();

statement.executeUpdate("INSERT INTO mytable VALUES(1, 'A0')");
statement.executeUpdate("INSERT INTO mytable VALUES(2, 'A1')");
statement.executeUpdate("INSERT INTO mytable VALUES(3, 'B0')");
statement.executeUpdate("INSERT INTO mytable VALUES(4, 'B1')");

statement.close();
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
connectionPool.releaseConnection(conn);
}
}
}

+ 0
- 44
uitest/src/main/java/com/vaadin/tests/components/table/DisabledSortingTableSqlContainer.java Переглянути файл

@@ -1,44 +0,0 @@
package com.vaadin.tests.components.table;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;

public class DisabledSortingTableSqlContainer extends TableSqlContainer {

@Override
protected void setup(VaadinRequest request) {
super.setup(request);

addButton("Enable sorting", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
table.setSortEnabled(true);
}
});

addButton("Disable sorting", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
table.setSortEnabled(false);
}
});

addButton("Sort by empty array", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
table.sort(new Object[] {}, new boolean[] {});
}
});
}

@Override
protected String getTestDescription() {
return "Sorting with empty arrays should reset sorting and hide sorting indicator in Table connected to a SQLContainer";
}

@Override
protected Integer getTicketNumber() {
return 16563;
}

}

+ 0
- 99
uitest/src/main/java/com/vaadin/tests/components/table/TableScrollingWithSQLContainer.java Переглянути файл

@@ -1,99 +0,0 @@
package com.vaadin.tests.components.table;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.util.sqlcontainer.SQLContainer;
import com.vaadin.v7.data.util.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.query.QueryDelegate;
import com.vaadin.v7.data.util.sqlcontainer.query.TableQuery;
import com.vaadin.v7.data.util.sqlcontainer.query.generator.DefaultSQLGenerator;
import com.vaadin.v7.ui.Table;

@SuppressWarnings("serial")
public class TableScrollingWithSQLContainer extends UI {

/** Table should never end up calling indexOfId in this case */
private class LimitedSQLContainer extends SQLContainer {

public LimitedSQLContainer(QueryDelegate delegate) throws SQLException {
super(delegate);
}

@Override
public int indexOfId(Object itemId) {
throw new RuntimeException("This function should not be called");
}
}

private void generateTestData(JDBCConnectionPool connectionPool)
throws SQLException {
Connection conn = connectionPool.reserveConnection();
Statement statement = conn.createStatement();
try {
statement.execute("drop table PEOPLE");
} catch (SQLException e) {
// Will fail if table doesn't exist, which is OK.
conn.rollback();
}
statement.execute(
"create table people (id integer generated always as identity,"
+ " name varchar(32), AGE INTEGER)");
statement.execute("alter table people add primary key (id)");
for (int i = 0; i < 5000; i++) {
statement
.executeUpdate("insert into people values(default, 'Person "
+ i + "', '" + i % 99 + "')");
}
statement.close();
conn.commit();
connectionPool.releaseConnection(conn);
}

static final String TABLE = "table";

@Override
public void init(VaadinRequest request) {
try {
SimpleJDBCConnectionPool connectionPool = new SimpleJDBCConnectionPool(
"org.hsqldb.jdbc.JDBCDriver",
"jdbc:hsqldb:mem:sqlcontainer", "SA", "", 2, 20);
generateTestData(connectionPool);

TableQuery query = new TableQuery("people", connectionPool,
new DefaultSQLGenerator());

SQLContainer container = new LimitedSQLContainer(query);

final VerticalLayout rootLayout = new VerticalLayout();

final Table table = new Table();
table.setContainerDataSource(container);
table.setCurrentPageFirstItemIndex(300);
rootLayout.addComponent(table);

table.setImmediate(true);

rootLayout.addComponent(new Button("GOTO 200", new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
table.setCurrentPageFirstItemIndex(200);
}
}));

setContent(rootLayout);

} catch (Exception e) {
e.printStackTrace();
}
}
}

+ 0
- 27
uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/ComboBoxUpdateProblem.java Переглянути файл

@@ -1,27 +0,0 @@
package com.vaadin.tests.containers.sqlcontainer;

import com.vaadin.server.LegacyApplication;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.v7.shared.ui.combobox.FilteringMode;
import com.vaadin.v7.ui.ComboBox;

/**
* See http://dev.vaadin.com/ticket/9155 .
*/
public class ComboBoxUpdateProblem extends LegacyApplication {
private final DatabaseHelper databaseHelper = new DatabaseHelper();

@Override
public void init() {
setMainWindow(new LegacyWindow("Test window"));

ComboBox combo = new ComboBox("Names",
databaseHelper.getTestContainer());
combo.setItemCaptionPropertyId("FIELD1");
combo.setFilteringMode(FilteringMode.CONTAINS);
combo.setImmediate(true);

getMainWindow().addComponent(combo);
}

}

+ 0
- 114
uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/DatabaseHelper.java Переглянути файл

@@ -1,114 +0,0 @@
package com.vaadin.tests.containers.sqlcontainer;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.vaadin.v7.data.util.sqlcontainer.SQLContainer;
import com.vaadin.v7.data.util.sqlcontainer.SQLTestsConstants;
import com.vaadin.v7.data.util.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.query.TableQuery;

class DatabaseHelper {

private JDBCConnectionPool connectionPool = null;
private SQLContainer testContainer = null;
private static final String TABLENAME = "testtable";
private SQLContainer largeContainer = null;
private static final String LARGE_TABLENAME = "largetable";

public DatabaseHelper() {
initConnectionPool();
initDatabase();
initContainers();
}

private void initDatabase() {
try {
Connection conn = connectionPool.reserveConnection();
Statement statement = conn.createStatement();
try {
statement.execute("drop table " + TABLENAME);
} catch (SQLException e) {
// Will fail if table doesn't exist, which is OK.
conn.rollback();
}
try {
statement.execute("drop table " + LARGE_TABLENAME);
} catch (SQLException e) {
// Will fail if table doesn't exist, which is OK.
conn.rollback();
}
switch (SQLTestsConstants.db) {
case HSQLDB:
statement.execute("create table " + TABLENAME
+ " (id integer GENERATED BY DEFAULT AS IDENTITY, field1 varchar(100), field2 boolean, primary key(id))");
statement.execute("create table " + LARGE_TABLENAME
+ " (id integer GENERATED BY DEFAULT AS IDENTITY, field1 varchar(100), primary key(id))");
break;
case MYSQL:
statement.execute("create table " + TABLENAME
+ " (id integer auto_increment not null, field1 varchar(100), field2 boolean, primary key(id))");
statement.execute("create table " + LARGE_TABLENAME
+ " (id integer auto_increment not null, field1 varchar(100), primary key(id))");
break;
case POSTGRESQL:
statement.execute("create table " + TABLENAME
+ " (\"id\" serial primary key, \"field1\" varchar(100), \"field2\" boolean)");
statement.execute("create table " + LARGE_TABLENAME
+ " (\"id\" serial primary key, \"field1\" varchar(100))");
break;
}
statement.executeUpdate("insert into " + TABLENAME
+ " values(default, 'Kalle', 'true')");
statement.executeUpdate("insert into " + TABLENAME
+ " values(default, 'Ville', 'true')");
statement.executeUpdate("insert into " + TABLENAME
+ " values(default, 'Jussi', 'true')");

for (int i = 0; i < 400; ++i) {
statement.executeUpdate("insert into " + LARGE_TABLENAME
+ " values(default, 'User " + i + "')");
}

statement.close();
conn.commit();
connectionPool.releaseConnection(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}

private void initContainers() {
try {
TableQuery q1 = new TableQuery(TABLENAME, connectionPool);
q1.setVersionColumn("id");
testContainer = new SQLContainer(q1);

TableQuery q2 = new TableQuery(LARGE_TABLENAME, connectionPool);
q2.setVersionColumn("id");
largeContainer = new SQLContainer(q2);
} catch (SQLException e) {
e.printStackTrace();
}
}

private void initConnectionPool() {
try {
connectionPool = new SimpleJDBCConnectionPool(
SQLTestsConstants.dbDriver, SQLTestsConstants.dbURL,
SQLTestsConstants.dbUser, SQLTestsConstants.dbPwd, 2, 5);
} catch (SQLException e) {
e.printStackTrace();
}
}

public SQLContainer getTestContainer() {
return testContainer;
}

public SQLContainer getLargeContainer() {
return largeContainer;
}
}

+ 0
- 146
uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/MassInsertMemoryLeakTestApp.java Переглянути файл

@@ -1,146 +0,0 @@
package com.vaadin.tests.containers.sqlcontainer;

import java.sql.SQLException;

import com.vaadin.server.LegacyApplication;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.util.sqlcontainer.SQLContainer;
import com.vaadin.v7.data.util.sqlcontainer.connection.JDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
import com.vaadin.v7.data.util.sqlcontainer.query.TableQuery;
import com.vaadin.v7.ui.ProgressIndicator;

// author table in testdb (MySQL) is set out as follows
// +-------------+-------------+------+-----+---------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +-------------+-------------+------+-----+---------+----------------+
// | id | int(11) | NO | PRI | NULL | auto_increment |
// | last_name | varchar(40) | NO | | NULL | |
// | first_names | varchar(80) | NO | | NULL | |
// +-------------+-------------+------+-----+---------+----------------+

@SuppressWarnings("serial")
public class MassInsertMemoryLeakTestApp extends LegacyApplication {

ProgressIndicator proggress = new ProgressIndicator();
Button process = new Button("Mass insert");

@Override
public void init() {
setMainWindow(new LegacyWindow("SQLContainer Test", buildLayout()));

process.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
MassInsert mi = new MassInsert();
mi.start();
}
});
}

private class MassInsert extends Thread {

@Override
public void start() {
getContext().lock();
try {
proggress.setVisible(true);
proggress.setValue(new Float(0));
proggress.setPollingInterval(100);
process.setEnabled(false);
proggress.setCaption("");
super.start();
} finally {
getContext().unlock();
}
}

@Override
public void run() {
JDBCConnectionPool pool = getConnectionPool();
if (pool != null) {
try {
int cents = 100;
for (int cent = 0; cent < cents; cent++) {
TableQuery q = new TableQuery("AUTHOR", pool);
q.setVersionColumn("ID");
SQLContainer c = new SQLContainer(q);
for (int i = 0; i < 100; i++) {
Object id = c.addItem();
c.getContainerProperty(id, "FIRST_NAMES")
.setValue(getRandonName());
c.getContainerProperty(id, "LAST_NAME")
.setValue(getRandonName());
}
c.commit();
getContext().lock();
try {
proggress
.setValue(new Float((1.0f * cent) / cents));
proggress.setCaption(
"" + 100 * cent + " rows inserted");
} finally {
getContext().unlock();
}
}
} catch (SQLException e) {
getMainWindow().showNotification(
"SQLException while processing",
e.getLocalizedMessage());
e.printStackTrace();
}
}
getContext().lock();
try {
proggress.setVisible(false);
proggress.setPollingInterval(0);
process.setEnabled(true);
} finally {
getContext().unlock();
}
}
}

private ComponentContainer buildLayout() {
VerticalLayout lo = new VerticalLayout();
lo.setSizeFull();
lo.addComponent(proggress);
lo.addComponent(process);
lo.setComponentAlignment(proggress, Alignment.BOTTOM_CENTER);
lo.setComponentAlignment(process, Alignment.TOP_CENTER);
lo.setSpacing(true);
proggress.setIndeterminate(false);
proggress.setVisible(false);
return lo;
}

private String getRandonName() {
final String[] tokens = new String[] { "sa", "len", "da", "vid", "ma",
"ry", "an", "na", "jo", "bri", "son", "mat", "e", "ric", "ge",
"eu", "han", "har", "ri", "ja", "lo" };
StringBuffer sb = new StringBuffer();
int len = (int) (Math.random() * 3 + 2);
while (len-- > 0) {
sb.append(tokens[(int) (Math.random() * tokens.length)]);
}
return Character.toUpperCase(sb.charAt(0)) + sb.toString().substring(1);
}

private JDBCConnectionPool getConnectionPool() {
SimpleJDBCConnectionPool pool = null;
try {
pool = new SimpleJDBCConnectionPool("com.mysql.jdbc.Driver",
"jdbc:mysql://localhost:3306/sqlcontainer", "sqlcontainer",
"sqlcontainer");
} catch (SQLException e) {
getMainWindow().showNotification("Error connecting to database");
}
return pool;
}

}

+ 0
- 47
uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/SqlcontainertableApplication.java Переглянути файл

@@ -1,47 +0,0 @@
package com.vaadin.tests.containers.sqlcontainer;

import com.vaadin.server.LegacyApplication;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.ui.Table;

public class SqlcontainertableApplication extends LegacyApplication {
private LegacyWindow mainWindow;
private Table table;
private HorizontalSplitPanel panel;
private Label label = new Label();

@Override
public void init() {
mainWindow = new LegacyWindow("SQLContainer Test");
setMainWindow(mainWindow);
mainWindow.getContent().setSizeFull();

panel = new HorizontalSplitPanel();
panel.setSecondComponent(label);

final DatabaseHelper helper = new DatabaseHelper();
table = new Table();
table.setSizeFull();
table.setContainerDataSource(helper.getLargeContainer());
table.setSelectable(true);
table.setImmediate(true);
table.setMultiSelect(true);
table.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
label.setValue(table.getValue().toString());
}
});

panel.setSizeFull();
panel.addComponent(table);

mainWindow.addComponent(panel);

}

}

+ 0
- 130
uitest/src/main/java/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKey.java
Різницю між файлами не показано, бо вона завелика
Переглянути файл


uitest/src/main/java/com/vaadin/tests/components/table/TableSqlContainer.java → uitest/src/main/java/com/vaadin/tests/smoke/TableSqlContainer.java Переглянути файл

@@ -1,4 +1,4 @@
package com.vaadin.tests.components.table;
package com.vaadin.tests.smoke;

import java.sql.Connection;
import java.sql.SQLException;
@@ -32,6 +32,7 @@ public class TableSqlContainer extends AbstractReindeerTestUI {
layout.addComponent(table);

final Label selectedLabel = new Label("Selected: null");
selectedLabel.setId("selection");
layout.addComponent(selectedLabel);

try {

+ 0
- 154
uitest/src/main/java/com/vaadin/v7/data/util/sqlcontainer/SQLTestsConstants.java Переглянути файл

@@ -1,154 +0,0 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* 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 com.vaadin.v7.data.util.sqlcontainer;

import com.vaadin.v7.data.util.sqlcontainer.query.generator.DefaultSQLGenerator;
import com.vaadin.v7.data.util.sqlcontainer.query.generator.MSSQLGenerator;
import com.vaadin.v7.data.util.sqlcontainer.query.generator.OracleGenerator;
import com.vaadin.v7.data.util.sqlcontainer.query.generator.SQLGenerator;

public class SQLTestsConstants {

/* Set the DB used for testing here! */
public enum DB {
HSQLDB, MYSQL, POSTGRESQL, MSSQL, ORACLE;
}

/* 0 = HSQLDB, 1 = MYSQL, 2 = POSTGRESQL, 3 = MSSQL, 4 = ORACLE */
public static final DB db = DB.HSQLDB;

/* Auto-increment column offset (HSQLDB = 0, MYSQL = 1, POSTGRES = 1) */
public static int offset;
/* Garbage table creation query (=three queries for oracle) */
public static String createGarbage;
public static String createGarbageSecond;
public static String createGarbageThird;
/* DB Drivers, urls, usernames and passwords */
public static String dbDriver;
public static String dbURL;
public static String dbUser;
public static String dbPwd;
/* People -test table creation statement(s) */
public static String peopleFirst;
public static String peopleSecond;
public static String peopleThird;
/* Schema test creation statement(s) */
public static String createSchema;
public static String createProductTable;
public static String dropSchema;
/* Versioned -test table createion statement(s) */
public static String[] versionStatements;
/* SQL Generator used during the testing */
public static SQLGenerator sqlGen;

/* Set DB-specific settings based on selected DB */
static {
sqlGen = new DefaultSQLGenerator();
switch (db) {
case HSQLDB:
offset = 0;
createGarbage = "create table garbage (id integer generated always as identity, type varchar(32), PRIMARY KEY(id))";
dbDriver = "org.hsqldb.jdbc.JDBCDriver";
dbURL = "jdbc:hsqldb:mem:sqlcontainer";
dbUser = "SA";
dbPwd = "";
peopleFirst = "create table people (id integer generated always as identity, name varchar(32), AGE INTEGER)";
peopleSecond = "alter table people add primary key (id)";
versionStatements = new String[] {
"create table versioned (id integer generated always as identity, text varchar(255), version tinyint default 0)",
"alter table versioned add primary key (id)" };
// TODO these should ideally exist for all databases
createSchema = "create schema oaas authorization DBA";
createProductTable = "create table oaas.product (\"ID\" integer generated always as identity primary key, \"NAME\" VARCHAR(32))";
dropSchema = "drop schema if exists oaas cascade";
break;
case MYSQL:
offset = 1;
createGarbage = "create table GARBAGE (ID integer auto_increment, type varchar(32), PRIMARY KEY(ID))";
dbDriver = "com.mysql.jdbc.Driver";
dbURL = "jdbc:mysql:///sqlcontainer";
dbUser = "sqlcontainer";
dbPwd = "sqlcontainer";
peopleFirst = "create table PEOPLE (ID integer auto_increment not null, NAME varchar(32), AGE INTEGER, primary key(ID))";
peopleSecond = null;
versionStatements = new String[] {
"create table VERSIONED (ID integer auto_increment not null, TEXT varchar(255), VERSION tinyint default 0, primary key(ID))",
"CREATE TRIGGER upd_version BEFORE UPDATE ON VERSIONED"
+ " FOR EACH ROW SET NEW.VERSION = OLD.VERSION+1" };
break;
case POSTGRESQL:
offset = 1;
createGarbage = "create table GARBAGE (\"ID\" serial PRIMARY KEY, \"TYPE\" varchar(32))";
dbDriver = "org.postgresql.Driver";
dbURL = "jdbc:postgresql://localhost:5432/test";
dbUser = "postgres";
dbPwd = "postgres";
peopleFirst = "create table PEOPLE (\"ID\" serial primary key, \"NAME\" VARCHAR(32), \"AGE\" INTEGER)";
peopleSecond = null;
versionStatements = new String[] {
"create table VERSIONED (\"ID\" serial primary key, \"TEXT\" VARCHAR(255), \"VERSION\" INTEGER DEFAULT 0)",
"CREATE OR REPLACE FUNCTION zz_row_version() RETURNS TRIGGER AS $$"
+ "BEGIN" + " IF TG_OP = 'UPDATE'"
+ " AND NEW.\"VERSION\" = old.\"VERSION\""
+ " AND ROW(NEW.*) IS DISTINCT FROM ROW (old.*)"
+ " THEN"
+ " NEW.\"VERSION\" := NEW.\"VERSION\" + 1;"
+ " END IF;" + " RETURN NEW;" + "END;"
+ "$$ LANGUAGE plpgsql;",
"CREATE TRIGGER \"mytable_modify_dt_tr\" BEFORE UPDATE"
+ " ON VERSIONED FOR EACH ROW"
+ " EXECUTE PROCEDURE \"public\".\"zz_row_version\"();" };
createSchema = "create schema oaas";
createProductTable = "create table oaas.product (\"ID\" serial primary key, \"NAME\" VARCHAR(32))";
dropSchema = "drop schema oaas cascade";
break;
case MSSQL:
offset = 1;
createGarbage = "create table GARBAGE (\"ID\" int identity(1,1) primary key, \"TYPE\" varchar(32))";
dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
dbURL = "jdbc:sqlserver://localhost:1433;databaseName=tempdb;";
dbUser = "sa";
dbPwd = "sa";
peopleFirst = "create table PEOPLE (\"ID\" int identity(1,1) primary key, \"NAME\" VARCHAR(32), \"AGE\" INTEGER)";
peopleSecond = null;
versionStatements = new String[] {
"create table VERSIONED (\"ID\" int identity(1,1) primary key, \"TEXT\" VARCHAR(255), \"VERSION\" rowversion not null)" };
sqlGen = new MSSQLGenerator();
break;
case ORACLE:
offset = 1;
createGarbage = "create table GARBAGE (\"ID\" integer primary key, \"TYPE\" varchar2(32))";
createGarbageSecond = "create sequence garbage_seq start with 1 increment by 1 nomaxvalue";
createGarbageThird = "create trigger garbage_trigger before insert on GARBAGE for each row begin select garbage_seq.nextval into :new.ID from dual; end;";
dbDriver = "oracle.jdbc.OracleDriver";
dbURL = "jdbc:oracle:thin:test/test@localhost:1521:XE";
dbUser = "test";
dbPwd = "test";
peopleFirst = "create table PEOPLE (\"ID\" integer primary key, \"NAME\" VARCHAR2(32), \"AGE\" INTEGER)";
peopleSecond = "create sequence people_seq start with 1 increment by 1 nomaxvalue";
peopleThird = "create trigger people_trigger before insert on PEOPLE for each row begin select people_seq.nextval into :new.ID from dual; end;";
versionStatements = new String[] {
"create table VERSIONED (\"ID\" integer primary key, \"TEXT\" VARCHAR(255), \"VERSION\" INTEGER DEFAULT 0)",
"create sequence versioned_seq start with 1 increment by 1 nomaxvalue",
"create trigger versioned_trigger before insert on VERSIONED for each row begin select versioned_seq.nextval into :new.ID from dual; end;",
"create sequence versioned_version start with 1 increment by 1 nomaxvalue",
"create trigger versioned_version_trigger before insert or update on VERSIONED for each row begin select versioned_version.nextval into :new.VERSION from dual; end;" };
sqlGen = new OracleGenerator();
break;
}
}

}

+ 0
- 16
uitest/src/test/java/com/vaadin/tests/components/table/DisabledSortingTableTest.java Переглянути файл

@@ -37,22 +37,6 @@ public class DisabledSortingTableTest extends MultiBrowserTest {
assertThatFirstCellHasText("4");
}

@Test
public void emptySortingClearsIndicatorAndResetsSortingWithSQLContainer() {
uiClass = DisabledSortingTableSqlContainer.class;
openTestURL();

assertThatFirstCellHasText("1");

sortFirstColumnAscending();
assertThatFirstCellHasText("2");

disableSorting();
sortByEmptyArray();

assertThatFirstCellHasText("1");
}

private void sortFirstColumnAscending() {
getFirstColumnHeader().click();
waitUntilHeaderHasExpectedClass("v-table-header-cell-asc");

+ 0
- 35
uitest/src/test/java/com/vaadin/tests/components/table/TableScrollingWithSQLContainerTest.java Переглянути файл

@@ -1,35 +0,0 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* 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 com.vaadin.tests.components.table;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.tests.tb3.MultiBrowserTest;

public class TableScrollingWithSQLContainerTest extends MultiBrowserTest {

@Test
public void verifySQLContainerIndexOfIDNotCalled() {
openTestURL();

vaadinElement("/VVerticalLayout[0]/VButton[0]").click();

Assert.assertTrue("SQLContainer indexOfId was called", driver
.findElements(By.className("v-errorindicator")).isEmpty());
}
}

+ 0
- 45
uitest/src/test/java/com/vaadin/tests/containers/sqlcontainer/TableQueryWithNonUniqueFirstPrimaryKeyTest.java Переглянути файл

@@ -1,45 +0,0 @@
package com.vaadin.tests.containers.sqlcontainer;

import java.util.ArrayList;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.By;
import com.vaadin.testbench.customelements.ComboBoxElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class TableQueryWithNonUniqueFirstPrimaryKeyTest
extends MultiBrowserTest {

private static final String[] DATA = { "TARUSCIO GIOVANNI",
"RUSSO GAETANO AUTORICAMBI", "AMORUSO LUIGI SRL", "CARUSO ROCCO",
"F.LLI RUSSO DI GAETANO RUSSO & C", "RUSSO GIUSEPPE",
"TRUSCELLI ANTONIO", "CARUSO CALOGERO" };

@Test
public void testComboBoxSuggestionsListedCorrectly() throws Exception {
openTestURL();
$(ComboBoxElement.class).first().findElement(By.vaadin("#textbox"))
.sendKeys("rus", Keys.ENTER);

List<String> result = new ArrayList<>();

// pick list items that are shown in suggestion popup
List<WebElement> elems = findElements(
By.cssSelector("td[role=\"listitem\"]"));
Assert.assertEquals("not enough suggestions shown", DATA.length,
elems.size());

for (WebElement elem : elems) {
result.add(elem.getText());
}

Assert.assertArrayEquals("popup items not what they should be", DATA,
result.toArray());

}
}

+ 53
- 0
uitest/src/test/java/com/vaadin/tests/smoke/TableSqlContainerTest.java Переглянути файл

@@ -0,0 +1,53 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* 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 com.vaadin.tests.smoke;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
* @author Vaadin Ltd
*
*/
public class TableSqlContainerTest extends MultiBrowserTest {

@Test
public void sqlContainerSmokeTest() {
openTestURL();

TableElement table = $(TableElement.class).first();
char ch = 'A';
for (int i = 0; i < 4; i++) {
Assert.assertEquals(String.valueOf(i + 1),
table.getCell(i, 0).getText());
Assert.assertEquals(String.valueOf(ch) + i % 2,
table.getCell(i, 2).getText());
if (i == 1) {
ch++;
}
}

table.getCell(1, 0).click();

Assert.assertEquals("Selected: 2",
findElement(By.id("selection")).getText());
}

}

Завантаження…
Відмінити
Зберегти