Skip to content

Commit

Permalink
simplify ds and jdbc driver setup
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Sep 16, 2024
1 parent 46310e9 commit 65f4d8a
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 505 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jakartified.maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
sudo -u postgres psql postgres -c "CREATE USER test WITH ENCRYPTED PASSWORD 'test';"
sudo -u postgres psql postgres -c "GRANT ALL PRIVILEGES ON DATABASE test TO test;"
- name: Test with Maven
run: mvn verify -Dmaven.javadoc.skip=true -P ${{matrix.server}}
run: mvn -B verify -Dmaven.javadoc.skip=true -P ${{matrix.server}}
247 changes: 6 additions & 241 deletions pom.xml

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions src/test/java/org/omnifaces/optimusfaces/test/OptimusFacesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import static org.omnifaces.optimusfaces.model.PagedDataModel.QUERY_PARAMETER_SELECTION;
import static org.omnifaces.optimusfaces.test.service.StartupService.ROWS_PER_PAGE;
import static org.omnifaces.optimusfaces.test.service.StartupService.TOTAL_RECORDS;
import static org.omnifaces.persistence.Database.H2;
import static org.omnifaces.persistence.Database.MYSQL;
import static org.omnifaces.persistence.Database.POSTGRESQL;
import static org.openqa.selenium.Keys.BACK_SPACE;
import static org.openqa.selenium.Keys.SPACE;
Expand Down Expand Up @@ -121,19 +123,21 @@ protected static <T extends OptimusFacesIT> WebArchive createArchive(Class<T> te
.addAsLibraries(maven.loadPomFromFile("pom.xml").importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile())
.addAsLibraries(maven.resolve("org.omnifaces:omnifaces:" + getProperty("test.omnifaces.version"), "org.primefaces:primefaces:jar:jakarta:" + getProperty("test.primefaces.version")).withTransitivity().asFile());

addDataSourceConfig(database, archive);
addDataSourceConfig(maven, archive, database);
addPersistenceConfig(maven, archive);
addResources(new File(testClass.getClassLoader().getResource(packageName).getFile()), "", archive::addAsWebResource);

return archive;
}

private static void addDataSourceConfig(Database database, WebArchive archive) {
var dataSourceConfigXml = isWildFly() ? "wildfly-ds.xml" : isGlassFish() ? "glassfish-resources.xml" : isTomEE() ? "resources.xml" : null;

if (dataSourceConfigXml != null) {
archive.addAsWebInfResource("WEB-INF/" + dataSourceConfigXml + "/" + database.name().toLowerCase() + ".xml", dataSourceConfigXml);
}
private static void addDataSourceConfig(MavenResolverSystem maven, WebArchive archive, Database database) {
var jdbcDriverDependency = database == H2 ? "com.h2database:h2:" + getProperty("test.h2-driver.version")
: database == MYSQL ? "mysql:mysql-connector-java:" + getProperty("test.mysql-driver.version")
: database == POSTGRESQL ? "org.postgresql:postgresql:" + getProperty("test.postgresql-driver.version")
: null;
archive
.addAsWebInfResource("WEB-INF/web.xml/" + database.name().toLowerCase() + ".xml", "web.xml")
.addAsLibraries(maven.resolve(jdbcDriverDependency).withTransitivity().asFile());
}

private static void addPersistenceConfig(MavenResolverSystem maven, WebArchive archive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
version="3.0"
>
<persistence-unit name="OptimusFacesIT">
<jta-data-source>java:openejb/Resource/OptimusFacesIT</jta-data-source>
<jta-data-source>java:app/OptimusFacesIT</jta-data-source>

<class>org.omnifaces.persistence.model.BaseEntity</class>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
>
<persistence-unit name="OptimusFacesIT">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>OptimusFacesIT</jta-data-source>
<jta-data-source>java:app/OptimusFacesIT</jta-data-source>

<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
version="3.0"
>
<persistence-unit name="OptimusFacesIT">
<jta-data-source>OptimusFacesIT</jta-data-source>
<jta-data-source>java:app/OptimusFacesIT</jta-data-source>

<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
Expand Down
29 changes: 0 additions & 29 deletions src/test/resources/WEB-INF/glassfish-resources.xml/h2.xml

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/resources/WEB-INF/glassfish-resources.xml/mysql.xml

This file was deleted.

29 changes: 0 additions & 29 deletions src/test/resources/WEB-INF/glassfish-resources.xml/postgresql.xml

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/resources/WEB-INF/resources.xml/h2.xml

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/resources/WEB-INF/resources.xml/mysql.xml

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/resources/WEB-INF/resources.xml/postgresql.xml

This file was deleted.

34 changes: 34 additions & 0 deletions src/test/resources/WEB-INF/web.xml/h2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright OmniFaces
Licensed 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
https://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.
-->
<!--
web.xml with H2 data source configuration.
-->
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<data-source>
<name>java:app/OptimusFacesIT</name>
<class-name>org.h2.jdbcx.JdbcDataSource</class-name>
<url>jdbc:h2:mem:playground;MODE=LEGACY</url>
<user>sa</user>
<password>sa</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
</data-source>
</web-app>
34 changes: 34 additions & 0 deletions src/test/resources/WEB-INF/web.xml/mysql.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright OmniFaces
Licensed 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
https://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.
-->
<!--
web.xml with MySQL data source configuration.
-->
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<data-source>
<name>java:app/OptimusFacesIT</name>
<class-name>com.mysql.cj.jdbc.MysqlXADataSource</class-name>
<url>jdbc:mysql://localhost:3306/test</url>
<user>root</user>
<password>root</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
</data-source>
</web-app>
34 changes: 34 additions & 0 deletions src/test/resources/WEB-INF/web.xml/postgresql.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright OmniFaces
Licensed 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
https://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.
-->
<!--
web.xml with PostgreSQL data source configuration.
-->
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<data-source>
<name>java:app/OptimusFacesIT</name>
<class-name>org.postgresql.xa.PGXADataSource</class-name>
<url>jdbc:postgresql:test</url>
<user>test</user>
<password>test</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
</data-source>
</web-app>
28 changes: 0 additions & 28 deletions src/test/resources/WEB-INF/wildfly-ds.xml/h2.xml

This file was deleted.

Loading

0 comments on commit 65f4d8a

Please sign in to comment.