-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0ccbea
commit d2c2720
Showing
6 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
sadu-queries/src/test/java/de/chojo/sadu/queries/examples/BindTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* Copyright (C) RainbowDashLabs and Contributor | ||
*/ | ||
|
||
package de.chojo.sadu.queries.examples; | ||
|
||
import de.chojo.sadu.PostgresDatabase; | ||
import de.chojo.sadu.mapper.RowMapperRegistry; | ||
import de.chojo.sadu.mapper.rowmapper.RowMapper; | ||
import de.chojo.sadu.postgresql.mapper.PostgresqlMapper; | ||
import de.chojo.sadu.queries.api.configuration.QueryConfiguration; | ||
import de.chojo.sadu.queries.configuration.QueryConfigurationBuilder; | ||
import de.chojo.sadu.queries.examples.dao.User; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import static de.chojo.sadu.PostgresDatabase.createContainer; | ||
import static de.chojo.sadu.queries.api.call.Call.call; | ||
|
||
@SuppressWarnings({"unused", "ResultOfMethodCallIgnored", "OptionalGetWithoutIsPresent", "RedundantExplicitVariableType"}) | ||
public class BindTest { | ||
|
||
private QueryConfiguration query; | ||
private PostgresDatabase.Database db; | ||
|
||
|
||
@BeforeEach | ||
void before() throws IOException, SQLException { | ||
db = createContainer("postgres", "postgres"); | ||
query = new QueryConfigurationBuilder(db.dataSource()).setRowMapperRegistry(new RowMapperRegistry().register(PostgresqlMapper.getDefaultMapper()) | ||
.register(RowMapper.forClass(User.class).mapper(User.map()).build())).build(); | ||
} | ||
|
||
@AfterEach | ||
void after() { | ||
db.close(); | ||
} | ||
|
||
// Retrieve all matching users directly | ||
@Test | ||
public void failOnInvalidToken() { | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
List<User> users = query.query("SELECT * FROM users WHERE id = ? AND name ILIKE :name1") | ||
.single(call().bind(1).bind("name1", "lilly")) | ||
.map(User.map()) | ||
.all(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters