This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d0c794  Creates CMP test scenario that uses cast instead of 
PortableRemoteObject.narrow
     new 75d84b5  Merge pull request #394 from otaviojava/improve_test
0d0c794 is described below

commit 0d0c794c546657a18539a0725a774d44568eff11
Author: Otavio Santana <otaviopolianasant...@gmail.com>
AuthorDate: Tue Feb 12 11:38:51 2019 -0200

    Creates CMP test scenario that uses cast instead of 
PortableRemoteObject.narrow
---
 .../tests/cmp/sample/CustomOrmXmlCastTest.java     | 76 ++++++++++++++++++
 .../tests/cmp/sample/MoviesServlet2.java           | 89 ++++++++++++++++++++++
 2 files changed, 165 insertions(+)

diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlCastTest.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlCastTest.java
new file mode 100644
index 0000000..3e852ea
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlCastTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.cmp.sample;
+
+import org.apache.ziplock.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+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;
+
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+public class CustomOrmXmlCastTest {
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment(testable = false)
+    public static WebArchive createDeployment() {
+        final WebArchive archive = ShrinkWrap.create(WebArchive.class, 
CustomOrmXmlCastTest.class.getSimpleName() + ".war")
+                .addClasses(ActorBean.class, ActorDetails.class, 
LocalActor.class, LocalActorHome.class,
+                        LocalMovie.class, LocalMovieHome.class, 
MovieBean.class, MovieDetails.class,
+                        MoviesBusiness.class, MoviesBusinessBean.class, 
MoviesBusinessHome.class,
+                        MoviesServlet2.class)
+                .addAsResource(new 
ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"),
 "META-INF/custom-orm.xml")
+                .addAsResource(new 
ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"),
 "META-INF/persistence.xml")
+                .addAsWebInfResource(new 
ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"),
 "openejb-jar.xml")
+                .addAsWebInfResource(new 
ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), 
"ejb-jar.xml")
+                .addAsWebInfResource(new 
ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/web.xml"), 
"web.xml");
+
+        System.out.println(archive.toString(true));
+        return archive;
+    }
+
+    @Test
+    @RunAsClient
+    public void checkCmpJpaEntityORMMappings() throws Exception {
+        final String output = IO.slurp(new URL(url.toExternalForm()));
+        System.out.println(output);
+
+        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);
+    }
+}
diff --git 
a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet2.java
 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet2.java
new file mode 100644
index 0000000..007ba0e
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/MoviesServlet2.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.openejb.arquillian.tests.cmp.sample;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+
+
+public class MoviesServlet2 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) 
initial.lookup("java:comp/env/ejb/MoviesBusiness");
+
+            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' and TABLE_NAME in ('ACTOR', 'MOVIE', 'ACTOR_MOVIE')");
+
+                 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);
+        }
+    }
+
+}

Reply via email to