From c6ebfb624e5424ca3e03c1e91a347d873027c116 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 20 Jul 2012 17:02:29 +0200 Subject: [PATCH] tests: SelfHoster: Test SqlUtils too. * src/test/java/org/glom/web/server/SelfHostExampleTest.java: Retrieve some data and check it too, as in the regular Glom test_selfhosting_new_from_example.cc test. * src/test/java/org/glom/web/server/SelfHoster.java: createConnection(): Make this public. --- ChangeLog | 10 ++++ .../org/glom/web/server/SelfHostExampleTest.java | 54 +++++++++++++++++++++- src/test/java/org/glom/web/server/SelfHoster.java | 4 +- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15a84be..4375618 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2012-07-20 Murray Cumming + tests: SelfHoster: Test SqlUtils too. + + * src/test/java/org/glom/web/server/SelfHostExampleTest.java: + Retrieve some data and check it too, as in the regular Glom + test_selfhosting_new_from_example.cc test. + * src/test/java/org/glom/web/server/SelfHoster.java: + createConnection(): Make this public. + +2012-07-20 Murray Cumming + tests: SelfHoster: createConnection(): Do not warn about expected failures. Let the caller say if the connection is expected to fail, to avoid diff --git a/src/test/java/org/glom/web/server/SelfHostExampleTest.java b/src/test/java/org/glom/web/server/SelfHostExampleTest.java index a10a541..6ec4800 100644 --- a/src/test/java/org/glom/web/server/SelfHostExampleTest.java +++ b/src/test/java/org/glom/web/server/SelfHostExampleTest.java @@ -22,9 +22,21 @@ package org.glom.web.server; import static org.junit.Assert.assertTrue; import java.net.URL; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; import org.glom.web.server.libglom.Document; import org.glom.web.server.libglom.Document.HostingMode; +import org.glom.web.shared.TypedDataItem; +import org.glom.web.shared.libglom.Field; +import org.glom.web.shared.libglom.layout.LayoutItemField; +import org.jooq.Condition; +import org.junit.Assert; import org.junit.Test; /** @@ -36,7 +48,7 @@ public class SelfHostExampleTest { private SelfHoster selfHoster = null; @Test - public void test() { + public void test() throws SQLException { final URL url = SelfHostExampleTest.class.getResource("example_music_collection.glom"); assertTrue(url != null); final String strUri = url.toString(); @@ -48,6 +60,46 @@ public class SelfHostExampleTest { selfHoster = new SelfHoster(document); final boolean hosted = selfHoster.createAndSelfHostFromExample(HostingMode.HOSTING_MODE_POSTGRES_SELF); assertTrue(hosted); + + testExampleMusiccollectionData(document); + } + + private void testExampleMusiccollectionData(final Document document) throws SQLException + { + assertTrue(document != null); + + //Check that some data is as expected: + final TypedDataItem quickFindValue = new TypedDataItem(); + quickFindValue.setText("Born To Run"); + final Condition whereClause = SqlUtils.getFindWhereClauseQuick(document, "albums", quickFindValue); + assertTrue(whereClause != null); + + final List fieldsToGet = new ArrayList(); + Field field = document.getField("albums", "album_id"); + LayoutItemField layoutItemField = new LayoutItemField(); + layoutItemField.setFullFieldDetails(field); + fieldsToGet.add(layoutItemField); + field = document.getField("albums", "name"); + layoutItemField = new LayoutItemField(); + layoutItemField.setFullFieldDetails(field); + fieldsToGet.add(layoutItemField); + + final String sqlQuery = SqlUtils.buildSqlSelectWithWhereClause("albums", fieldsToGet, whereClause, null); + + final Connection conn = selfHoster.createConnection(false); + assertTrue(conn != null); + + final Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + //st.setFetchSize(length); + final ResultSet rs = st.executeQuery(sqlQuery); + assertTrue(rs != null); + + final ResultSetMetaData rsMetaData = rs.getMetaData(); + Assert.assertEquals(2, rsMetaData.getColumnCount()); + + rs.last(); + final int rsRowsCount = rs.getRow(); + Assert.assertEquals(1, rsRowsCount); } public void tearDown() { diff --git a/src/test/java/org/glom/web/server/SelfHoster.java b/src/test/java/org/glom/web/server/SelfHoster.java index 988fd4f..a35179c 100644 --- a/src/test/java/org/glom/web/server/SelfHoster.java +++ b/src/test/java/org/glom/web/server/SelfHoster.java @@ -833,10 +833,8 @@ public class SelfHoster { } /** - * @return - * @throws SQLException */ - private Connection createConnection(boolean failureExpected) { + public Connection createConnection(boolean failureExpected) { final Properties connectionProps = new Properties(); connectionProps.put("user", this.username); connectionProps.put("password", this.password); -- 2.1.4