Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame^] | 1 | import de.ids_mannheim.korap.config.Attributes; |
| 2 | import de.ids_mannheim.korap.utils.SqlBuilder; |
| 3 | import org.junit.Assert; |
| 4 | import org.junit.Test; |
| 5 | |
| 6 | /** |
| 7 | * @author hanl |
| 8 | * @date 26/11/2015 |
| 9 | */ |
| 10 | public class TestUtil { |
| 11 | |
| 12 | @Test |
| 13 | public void testSqlBuilderSELECT () { |
| 14 | SqlBuilder b = new SqlBuilder("users"); |
| 15 | b.select(Attributes.USERNAME, Attributes.PASSWORD).where( |
| 16 | Attributes.USERNAME + "=?"); |
| 17 | Assert.assertEquals("query does not match", |
| 18 | "SELECT username, password FROM users WHERE username=?;", |
| 19 | b.toString()); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | @Test |
| 24 | public void testSqlBuilderINSERT () { |
| 25 | SqlBuilder b = new SqlBuilder("users"); |
| 26 | b.insert(Attributes.USERNAME, Attributes.PASSWORD).params("user", |
| 27 | "pass"); |
| 28 | Assert.assertEquals("query does not match", |
| 29 | "INSERT INTO users (username, password) VALUES (user, pass);", |
| 30 | b.toString()); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | @Test |
| 35 | public void testSqlBuilderINSERTExcludeWhere () { |
| 36 | SqlBuilder b = new SqlBuilder("users"); |
| 37 | b.insert(Attributes.USERNAME, Attributes.PASSWORD) |
| 38 | .params("user", "pass").where("some=?"); |
| 39 | Assert.assertEquals("query does not match", |
| 40 | "INSERT INTO users (username, password) VALUES (user, pass);", |
| 41 | b.toString()); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | @Test |
| 46 | public void testSqlBuilderDELETE () { |
| 47 | SqlBuilder b = new SqlBuilder("users"); |
| 48 | b.delete().where(Attributes.PERSISTENT_ID + "=?"); |
| 49 | Assert.assertEquals("query does not match", |
| 50 | "DELETE FROM users WHERE persistent_id=?;", b.toString()); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | @Test |
| 55 | public void testSqlBuilderUPDATE () { |
| 56 | SqlBuilder b = new SqlBuilder("users"); |
| 57 | b.update(Attributes.USERNAME, Attributes.PASSWORD).params("user", |
| 58 | "pass"); |
| 59 | Assert.assertEquals("query does not match", |
| 60 | "UPDATE users SET username=user, password=pass;", b.toString()); |
| 61 | } |
| 62 | } |