tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [20/24] tomee git commit: TOMEE-2295 check the correct database schema is in place
Date Thu, 06 Dec 2018 17:33:42 GMT
TOMEE-2295 check the correct database schema is in place


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/46a731e7
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/46a731e7
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/46a731e7

Branch: refs/heads/master
Commit: 46a731e7f11206f2bec39f21435fc2525ac67b1a
Parents: 1ba0375
Author: Jonathan Gallimore <jgallimore@tomitribe.com>
Authored: Wed Dec 5 14:55:40 2018 +0000
Committer: Jonathan Gallimore <jgallimore@tomitribe.com>
Committed: Wed Dec 5 14:55:40 2018 +0000

----------------------------------------------------------------------
 .../tests/cmp/sample/CustomOrmXmlTest.java      | 15 +++++--
 .../tests/cmp/sample/MoviesServlet.java         | 43 ++++++++++++++++++++
 .../openejb/arquillian/tests/cmp/sample/web.xml |  5 +++
 3 files changed, 60 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/46a731e7/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
index f261015..e8141b6 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlTest.java
@@ -24,6 +24,7 @@ import org.jboss.arquillian.test.api.ArquillianResource;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
 import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
 import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -60,8 +61,16 @@ public class CustomOrmXmlTest {
     public void checkCmpJpaEntityORMMappings() throws Exception {
         final String output = IO.slurp(new URL(url.toExternalForm()));
         System.out.println(output);
-        //Assert.assertTrue(output.contains("Movie added successfully"));
-        //Assert.assertTrue(output.contains("Movie removed successfully"));
-        //Assert.assertTrue(output.contains("title='Bad Boys', director='Michael Bay', year=1995"));
+
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR, COLUMN_NAME: ACTORID, DATA_TYPE:
INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR, COLUMN_NAME: ACTOR_NAME, DATA_TYPE:
CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 250"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR_MOVIE, COLUMN_NAME: ACTORS_ACTORID,
DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR_MOVIE, COLUMN_NAME: MOVIES_MOVIEID,
DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: MOVIEID, DATA_TYPE:
INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: GENRE, DATA_TYPE:
CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 255"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: MOVIE_NAME, DATA_TYPE:
CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 250"));
+
+        final String[] split = output.split("\r\n");
+        Assert.assertEquals(7, split.length);
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/46a731e7/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet.java
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet.java
index 54f0893..63d868c 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet.java
@@ -18,6 +18,11 @@
 package org.apache.openejb.arquillian.tests.cmp.sample;
 
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.rmi.PortableRemoteObject;
@@ -25,6 +30,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
 
 
 public class MoviesServlet extends HttpServlet {
@@ -32,6 +38,9 @@ public class MoviesServlet extends HttpServlet {
     @Override
     protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws
ServletException, IOException {
         try {
+
+            final PrintWriter pw = resp.getWriter();
+
             final Context initial = new InitialContext();
 
             final MoviesBusinessHome home = (MoviesBusinessHome)
@@ -40,6 +49,40 @@ public class MoviesServlet extends HttpServlet {
             final MoviesBusiness moviesBusiness = home.create();
             moviesBusiness.doLogic();
 
+            final DataSource ds = (DataSource) initial.lookup("java:comp/env/db/DataSource");
+            try (final Connection connection = ds.getConnection();
+                 final PreparedStatement ps = connection.prepareStatement(
+                         "select TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH
" +
+                                 "from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'PUBLIC'");
+
+                 final ResultSet rs = ps.executeQuery()) {
+
+                final ResultSetMetaData metaData = rs.getMetaData();
+                final int columnCount = metaData.getColumnCount();
+
+                final String[] columnNames = new String[columnCount];
+
+                for (int c = 0; c < columnCount; c++) {
+                    columnNames[c] = metaData.getColumnName(c + 1);
+                }
+
+                while (rs.next()) {
+                    final StringBuilder sb = new StringBuilder();
+
+                    for (int c = 0; c < columnCount; c++) {
+                        if (c > 0) {
+                            sb.append(", ");
+                        }
+
+                        sb.append(columnNames[c]).append(": ").append(rs.getString(c + 1));
+                    }
+
+                    pw.println(sb.toString());
+                }
+            }
+
+            pw.flush();
+
         } catch (final Exception ex) {
             throw new ServletException(ex);
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/46a731e7/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml
index a536e17..cd3c591 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/web.xml
@@ -39,4 +39,9 @@
         <home>org.apache.openejb.arquillian.tests.cmp.sample.MoviesBusinessHome</home>
         <remote>org.apache.openejb.arquillian.tests.cmp.sample.MoviesBusiness</remote>
     </ejb-ref>
+
+    <resource-ref>
+        <res-ref-name>db/DataSource</res-ref-name>
+        <res-type>javax.sql.DataSource</res-type>
+    </resource-ref>
 </web-app>
\ No newline at end of file


Mime
View raw message