Skip to content

Commit

Permalink
Merge pull request #29132 from KyleAure/28366-recreate-jakarta-data-e…
Browse files Browse the repository at this point in the history
…clipselink-issues
  • Loading branch information
KyleAure authored Jul 29, 2024
2 parents df1d9b4 + 3b02d05 commit ef64085
Show file tree
Hide file tree
Showing 32 changed files with 2,650 additions and 14 deletions.
1 change: 1 addition & 0 deletions dev/com.ibm.ws.jpa.tests.jpa_32_fat/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<classpathentry kind="src" path="fat/src"/>
<classpathentry kind="src" path="test-applications/jpabootstrap/src"/>
<classpathentry kind="src" path="test-applications/helpers/DatabaseManagement/src"/>
<classpathentry kind="src" path="test-applications/jakartadata/src"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
Expand Down
3 changes: 2 additions & 1 deletion dev/com.ibm.ws.jpa.tests.jpa_32_fat/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bVersion=1.0
src: \
fat/src,\
test-applications/helpers/DatabaseManagement/src,\
test-applications/jpabootstrap/src
test-applications/jpabootstrap/src,\
test-applications/jakartadata/src

fat.project: true
tested.features: databaseRotation, persistence-3.2, persistencecontainer-3.2, servlet-6.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.testcontainers.containers.JdbcDatabaseContainer;

import com.ibm.ws.jpa.jpa32.JPABootstrapTest;
import com.ibm.ws.jpa.jpa32.JakartaDataRecreateTest;

import componenttest.containers.TestContainerSuite;
import componenttest.rules.repeater.RepeatTests;
Expand All @@ -28,6 +29,7 @@
@RunWith(Suite.class)
@SuiteClasses({
JPABootstrapTest.class,
JakartaDataRecreateTest.class,
componenttest.custom.junit.runner.AlwaysPassesTest.class
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.testcontainers.containers.JdbcDatabaseContainer;

Expand Down Expand Up @@ -91,14 +90,4 @@ public static void tearDown() throws Exception {
server1.stopServer("CWWJP9991W",
"Missing PostgreSQL10JsonPlatform"); // Generated with postgres db, since we don't include the postgres plugin);
}

@Test
public void testJPA32Bootstrap() throws Exception {
runTest(SPECLEVEL);
}

private void runTest(String spec) throws Exception {
FATServletClient.runTest(server1, APP_NAME + "_" + spec + "/TestJPABootstrap", "testPersistenceUnitBootstrap");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.jpa.jpa32;

import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.testcontainers.containers.JdbcDatabaseContainer;

import com.ibm.websphere.simplicity.ShrinkHelper;
import com.ibm.ws.jpa.FATSuite;

import componenttest.annotation.MinimumJavaLevel;
import componenttest.annotation.Server;
import componenttest.annotation.TestServlet;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.database.container.DatabaseContainerType;
import componenttest.topology.database.container.DatabaseContainerUtil;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.utils.PrivHelper;
import io.openliberty.jpa.data.tests.web.JakartaDataRecreateServlet;

/**
* Recreate issues found during development of Jakarta Data with EclipseLink
* using pure Jakarta Persistence.
*
* These tests should be contributed back to EclipseLink as these issues are resovled.
*/
@RunWith(FATRunner.class)
@MinimumJavaLevel(javaLevel = 17)
public class JakartaDataRecreateTest {
public static final String APP_NAME = "jakartadata";
public static final String SERVLET = "JakartaDataRecreate";
public static final String SPECLEVEL = "3.2";

@Server("JakartaDataRecreateServer")
@TestServlet(servlet = JakartaDataRecreateServlet.class, path = APP_NAME + "_" + SPECLEVEL + "/" + SERVLET)
public static LibertyServer server;

public static final JdbcDatabaseContainer<?> testContainer = FATSuite.testContainer;

@BeforeClass
public static void setUp() throws Exception {
PrivHelper.generateCustomPolicy(server, PrivHelper.JAXB_PERMISSION);

//Get driver name
server.addEnvVar("DB_DRIVER", DatabaseContainerType.valueOf(testContainer).getDriverName());

//Setup server DataSource properties
DatabaseContainerUtil.setupDataSourceProperties(server, testContainer);

createApplication(SPECLEVEL);
server.startServer();
}

private static void createApplication(String specLevel) throws Exception {
final String resPath = "test-applications/" + APP_NAME + "/resources/jpa-" + specLevel + "/web/";

WebArchive app = ShrinkWrap.create(WebArchive.class, APP_NAME + "_" + specLevel + ".war");
app.addPackage("io.openliberty.jpa.data.tests.models");
app.addPackage("io.openliberty.jpa.data.tests.web");
app.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class).importDirectory(resPath).as(GenericArchive.class),
"/",
Filters.includeAll());
ShrinkHelper.exportDropinAppToServer(server, app);
}

@AfterClass
public static void tearDown() throws Exception {
server.stopServer("CWWJP9991W",
"WTRN0074E: Exception caught from before_completion synchronization operation", // RuntimeException test, expected
"Missing PostgreSQL10JsonPlatform"); // Generated with postgres db, since we don't include the postgres plugin);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
###############################################################################
bootstrap.include=../testports.properties
# Test requires JPA trace to be enabled, do not disable!
traceSpecification=JPA=all
com.ibm.ws.logging.trace.specification==JPA=all
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###############################################################################
# Copyright (c) 2024 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
bootstrap.include=../testports.properties
# Test requires JPA trace to be enabled, do not disable!
com.ibm.ws.logging.trace.specification=*=info:JPA=all:eclipselink=all
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
Copyright (c) 2024 IBM Corporation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
-->
<server description="new server">

<featureManager>
<feature>persistence-3.2</feature>
<feature>servlet-6.1</feature>
<!-- DO NOT ADD data-1.0 feature -->
<feature>componenttest-2.0</feature>
</featureManager>

<include location="../fatTestPorts.xml"/>
<dataSource id="DefaultDataSource" fat.modify="true">
<jdbcDriver libraryRef="JDBCLib"/>
<properties.derby.embedded databaseName="memory:ds1" createDatabase="create" user="dbuser1" password="{xor}Oz0vKDtu" />
</dataSource>

<library id="JDBCLib">
<fileset dir="${shared.resource.dir}/jdbc" includes="${env.DB_DRIVER}"/>
</library>

<!-- JDBC driver -->
<javaPermission codebase="${shared.resource.dir}/jdbc/${env.DB_DRIVER}" className="java.security.AllPermission"/>

<!-- Permission needed for Postgres driver -->
<javaPermission className="java.util.PropertyPermission" name="org.postgresql.forceBinary" actions="read"/>

<!-- Permission needed for SQLServer driver -->
<javaPermission className="java.net.SocketPermission" name="*" actions="connect,resolve"/>

<!-- Permission needed for Oracle driver -->
<javaPermission className="java.lang.RuntimePermission" name="accessDeclaredMembers" />

<!-- File read write permissions -->
<javaPermission className="java.util.PropertyPermission" name="user.dir" actions="read"/>
<javaPermission className="java.io.FilePermission" name="files/timertestoutput.txt" actions="read,write"/>
<javaPermission className="java.io.FilePermission" name="files" actions="write"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-->
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_2.xsd"
version="3.2">

<persistence-unit name="RecreatePersistenceUnit">
<properties>
<!-- EclipseLink should create the database schema automatically -->
<property name="jakarta.persistence.schema-generation.database.action" value="create" />
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.jpa.data.tests.models;

import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;

/**
* Recreate from io.openliberty.data.internal_fat_jpa
*/
@Entity
public class Account {

@EmbeddedId
public AccountId accountId;

public double balance;

public String bankName;

public boolean checking;

public String owner;

public static Account of(long accountNum, long routingNum, String bankName, boolean checking, double balance, String owner) {
Account inst = new Account();
inst.accountId = AccountId.of(accountNum, routingNum);
inst.bankName = bankName;
inst.checking = checking;
inst.balance = balance;
inst.owner = owner;
return inst;
}

@Override
public String toString() {
return bankName + ' ' + accountId + " $" + balance + " owned by " + owner + (checking ? " with checking" : "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.jpa.data.tests.models;

import jakarta.persistence.Embeddable;

@Embeddable
public class AccountId {

public long accountNum;
public long routingNum;

public AccountId() {
}

public AccountId(long accountNum, long routingNum) {
this.accountNum = accountNum;
this.routingNum = routingNum;
}

public static AccountId of(long accountNum, long routingNum) {
return new AccountId(accountNum, routingNum);
}

@Override
public String toString() {
return "AccountId:" + accountNum + ":" + routingNum;
}
}
Loading

0 comments on commit ef64085

Please sign in to comment.