use of com.github.fabriciofx.cactoos.jdbc.Server in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysH2.
@Test
public // @checkstyle MethodNameCheck (1 line)
void insertWithKeysH2() throws Exception {
try (Server server = new ServerH2()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed("INSERT INTO t02 (name) VALUES (:name)", new ParamText("name", "Jeff Malony")))), new HasValue<>(1));
}
}
use of com.github.fabriciofx.cactoos.jdbc.Server in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysPsql.
@Test
public void insertWithKeysPsql() throws Exception {
try (Server server = new ServerPgsql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id SERIAL,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed("INSERT INTO t02 (name) VALUES (:name)", new ParamText("name", "Jeff Malony")))), new HasValue<>(1));
}
}
use of com.github.fabriciofx.cactoos.jdbc.Server in project cactoos-jdbc by fabriciofx.
the class ResultAsValueTest method insertWithKeys.
@Test
public void insertWithKeys() throws Exception {
try (Server server = new ServerMysql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE contact (", "id INT AUTO_INCREMENT,", "name VARCHAR(50) NOT NULL,", "CONSTRAINT pk_contact PRIMARY KEY(id))"))).result();
MatcherAssert.assertThat("Can't get a generated key value", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed(() -> "INSERT INTO contact (name) VALUES (:name)", "id", new ParamText("name", "Leonardo da Vinci")))), new HasValue<>(BigInteger.ONE));
}
}
use of com.github.fabriciofx.cactoos.jdbc.Server in project cactoos-jdbc by fabriciofx.
the class ScriptSqlTest method h2Server.
@Test
public void h2Server() throws Exception {
final Server server = new ServerH2(new ScriptSql(new ResourceOf(new Joined("/", "com/github/fabriciofx/cactoos/jdbc/phonebook", "phonebook-h2.sql"))));
server.start();
server.stop();
}
use of com.github.fabriciofx.cactoos.jdbc.Server in project cactoos-jdbc by fabriciofx.
the class StatementInsertTest method insertWithKeysMysql.
@Test
public void insertWithKeysMysql() throws Exception {
try (Server server = new ServerMysql()) {
server.start();
final Session session = server.session();
new StatementUpdate(session, new QuerySimple(new Joined(" ", "CREATE TABLE t02 (id INT AUTO_INCREMENT,", "name VARCHAR(50), PRIMARY KEY (id))"))).result();
MatcherAssert.assertThat("Can't insert with an integer keys", new ResultAsValue<>(new StatementInsertKeyed<>(session, new QueryKeyed(() -> "INSERT INTO t02 (name) VALUES (:name)", "id", new ParamText("name", "Jeff Malony")))), new HasValue<>(BigInteger.ONE));
}
}
Aggregations