OPENJPA-2876 unit test to show wrong SQL
sqlAction=refresh right now also generates the full DB.
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/test/java/org/apache/openjpa/tools/maven/test/ModifyDatabaseTest.java b/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/test/java/org/apache/openjpa/tools/maven/test/ModifyDatabaseTest.java
deleted file mode 100644
index 4e8b408..0000000
--- a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/test/java/org/apache/openjpa/tools/maven/test/ModifyDatabaseTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.apache.openjpa.tools.maven.test;
-
-/*
- * 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.
- */
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Arrays;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-
-import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.tools.maven.testentity.TestEntity;
-
-import junit.framework.TestCase;
-
-public class ModifyDatabaseTest extends TestCase {
-
-
- /**
- * check if the generated classes have been enhanced.
- * @throws Exception
- */
- public void testDatabaseWrite() throws Exception
- {
- EntityManagerFactory emf = Persistence.createEntityManagerFactory( "TestUnit" );
- assertNotNull( emf );
-
- EntityManager em = emf.createEntityManager();
- assertNotNull( em );
-
- try
- {
- em.getTransaction().begin();
-
- TestEntity entity = new TestEntity();
- entity.setInt1( 4711 );
- entity.setString1( "myVal" );
-
- em.persist( entity );
- em.getTransaction().commit();
- }
- finally
- {
- em.close();
- }
- }
-
-}
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/pom.xml.disabled b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/pom.xml
similarity index 64%
rename from openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/pom.xml.disabled
rename to openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/pom.xml
index 26fe129..2ec2d61 100644
--- a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/pom.xml.disabled
+++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/pom.xml
@@ -24,14 +24,17 @@
<modelVersion>4.0.0</modelVersion>
+
<groupId>org.apache.openjpa.tools.openjpa-maven-plugin.testing</groupId>
<artifactId>modifyDatabase</artifactId>
<version>1.0-SNAPSHOT</version>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.13.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
@@ -41,16 +44,23 @@
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.11</version>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>@hsqldb.version@</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ <version>@dbcp2.version@</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@@ -60,10 +70,10 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
- <version>1.4</version>
+ <version>1.5</version>
<executions>
<execution>
- <id>dropdatabase</id>
+ <id>initialdb</id>
<phase>process-resources</phase>
<goals>
<goal>execute</goal>
@@ -71,17 +81,20 @@
</execution>
</executions>
<configuration>
- <driver>com.mysql.jdbc.Driver</driver>
- <url>jdbc:mysql://localhost/testdb</url>
- <username>root</username>
- <enableAnonymousPassword>true</enableAnonymousPassword>
- <sqlCommand>DROP TABLE TestEntity;</sqlCommand>
+ <driver>org.hsqldb.jdbcDriver</driver>
+ <url>jdbc:hsqldb:file:target/openjpa-hsqldb;hsqldb.lock_file=false</url>
+ <username>SA</username>
+ <password></password>
+ <srcFiles>
+ <srcFile>src/main/sql/database.sql</srcFile>
+ </srcFiles>
+ <escapeProcessing>false</escapeProcessing>
</configuration>
<dependencies>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.11</version>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>@hsqldb.version@</version>
</dependency>
</dependencies>
</plugin>
@@ -96,14 +109,16 @@
org/apache/openjpa/tools/maven/testentity/TestEntity.class
</include>
<sqlAction>refresh</sqlAction>
- <modifyDatabase>true</modifyDatabase>
+ <connectionDriverName>org.apache.commons.dbcp2.BasicDataSource</connectionDriverName>
<connectionProperties>
- driverClass=com.mysql.jdbc.Driver,
- jdbcUrl=jdbc:mysql://localhost/testdb,
- user=root,
+ driverClassName=org.hsqldb.jdbcDriver,
+ url=jdbc:hsqldb:file:target/openjpa-hsqldb;hsqldb.lock_file=false,
+ username=SA,
password=
</connectionProperties>
-
+ <toolProperties>
+ <DBDictionary>org.apache.openjpa.jdbc.sql.HSQLDictionary</DBDictionary>
+ </toolProperties>
</configuration>
<executions>
<execution>
@@ -117,9 +132,14 @@
</executions>
<dependencies>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.11</version>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>@hsqldb.version@</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ <version>@dbcp2.version@</version>
</dependency>
</dependencies>
</plugin>
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java
similarity index 87%
rename from openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java
rename to openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java
index f008ad9..285324b 100644
--- a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java
+++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/java/org/apache/openjpa/tools/maven/testentity/TestEntity.java
@@ -19,18 +19,25 @@
* under the License.
*/
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
+import javax.persistence.Table;
@Entity
+@Table(name="TEST_ENTITY")
public class TestEntity {
@Id
private int xint1;
+ @Column(name="SOME_VALUE")
private String string1;
+ @Column(name="VAL2", length=100)
+ private String val2;
+
public int getInt1() {
return xint1;
}
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/resources/META-INF/persistence.xml b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/resources/META-INF/persistence.xml
similarity index 83%
rename from openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/resources/META-INF/persistence.xml
rename to openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/resources/META-INF/persistence.xml
index e4bfd7e..6bdeabb 100644
--- a/openjpa-tools/openjpa-maven-plugin/src/it/modifyDatabase/src/main/resources/META-INF/persistence.xml
+++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/resources/META-INF/persistence.xml
@@ -19,15 +19,15 @@
<!-- simply all annotated persistent entities will be part of this unit-->
<persistence-unit name="TestUnit">
-
+ <class>org.apache.openjpa.tools.maven.testentity.TestEntity</class>
+<!-- TODO REMOVE
<properties>
- <property name="openjpa.jdbc.DBDictionary" value="mysql" />
- <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
- <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost/testdb" />
- <property name="openjpa.ConnectionUserName" value="root" />
+ <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
+ <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:file:openjpa-hsqldb" />
+ <property name="openjpa.ConnectionUserName" value="SA" />
<property name="openjpa.ConnectionPassword" value="" />
-
</properties>
+-->
</persistence-unit>
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/sql/database.sql b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/sql/database.sql
new file mode 100644
index 0000000..3aa8daa
--- /dev/null
+++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/main/sql/database.sql
@@ -0,0 +1,2 @@
+CREATE TABLE TEST_ENTITY -- TestEntity
+(xint1 INTEGER NOT NULL, SOME_VALUE VARCHAR(255), PRIMARY KEY (xint1));
diff --git a/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/test/java/org/apache/openjpa/tools/maven/test/ItRefreshSchemaTest.java b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/test/java/org/apache/openjpa/tools/maven/test/ItRefreshSchemaTest.java
new file mode 100644
index 0000000..d89037b
--- /dev/null
+++ b/openjpa-tools/openjpa-maven-plugin/src/it/sqlActionRefresh/src/test/java/org/apache/openjpa/tools/maven/test/ItRefreshSchemaTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.openjpa.tools.maven.test;
+
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ItRefreshSchemaTest {
+
+ /** contains the directory where all generated results are placed */
+ private final static String TARGET_DIR = "target";
+
+ /** the file containing the generated SQL syntax */
+ private final static String SQL_FILE = "database.sql";
+
+ /** if the SQL generation has been successful, the following result should be in the SQL file */
+ private final static String VALID_SQL = "ALTER TABLE TEST_ENTITY ADD COLUMN VAL2 VARCHAR(100);";
+
+ /**
+ * check if the generated SQL script is correct.
+ * @throws Exception
+ */
+ @Test
+ public void testSqlGeneration() throws Exception
+ {
+ File sqlFile = new File( TARGET_DIR, SQL_FILE );
+ BufferedReader in = new BufferedReader( new FileReader( sqlFile ) );
+ String sqlIn = in.readLine();
+ assertEquals( VALID_SQL, sqlIn );
+ sqlIn = in.readLine();
+ assertTrue(sqlIn == null || sqlIn.trim().length() == 0);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 3591c5e..90f61ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@
<mssql.connector.version>9.2.1.jre8</mssql.connector.version>
<!-- other common versions -->
- <kubernetes-client.version>4.7.0</kubernetes-client.version>
+ <kubernetes-client.version>5.4.1</kubernetes-client.version>
<slf4j.version>1.7.23</slf4j.version>
<!-- Compile Java source/target class level -->
<compile.class.source>${java.class.version}</compile.class.source>
@@ -105,6 +105,7 @@
<jmock.version>2.9.0</jmock.version>
<automatic-module-name>-SUBMODULES-NEED-TO-OVERRIDE-THIS-</automatic-module-name>
+ <dbcp2.version>2.8.0</dbcp2.version>
</properties>
<licenses>
@@ -1786,7 +1787,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
- <version>2.8.0</version>
+ <version>${dbcp2.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>