Skip to content

Commit 1d33e65

Browse files
Merge pull request #32966 from anjumfatima90/SB3-jpa
Test Spring Boot 3 with JPA
2 parents 0b20bb9 + 0188e2d commit 1d33e65

File tree

6 files changed

+480
-3
lines changed

6 files changed

+480
-3
lines changed

dev/io.openliberty.springboot.fat30_fat/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

dev/io.openliberty.springboot.fat30_fat/fat/src/com/ibm/ws/springboot/support/fat/FATSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
JPALibertyAppTests30War.class,
6969
JPAEclipseLinkAppTests30War.class,
7070
JPAEclipseLinkWeavingAppTests30War.class,
71+
JPAEclipseLinkAppTests30.class,
72+
JPAEclipseLinkWeavingAppTests30.class,
73+
JPAHibernateAppTests30.class,
74+
// JPALibertyAppTests30.class,
7175
JmsWebAppTests30.class,
7276
JmsSpringBootAppTests30.class,
7377
ConcurrencyAppTests30.class,
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
*******************************************************************************/
11+
package com.ibm.ws.springboot.support.fat;
12+
13+
import static org.junit.Assert.assertNotNull;
14+
15+
import java.io.File;
16+
import java.io.FileOutputStream;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.Enumeration;
22+
import java.util.HashSet;
23+
import java.util.Map;
24+
import java.util.Set;
25+
import java.util.jar.JarEntry;
26+
import java.util.jar.JarFile;
27+
import java.util.jar.JarOutputStream;
28+
29+
import org.junit.AfterClass;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.runner.RunWith;
33+
34+
import com.ibm.websphere.simplicity.RemoteFile;
35+
import com.ibm.websphere.simplicity.config.ClassloaderElement;
36+
import com.ibm.websphere.simplicity.config.SpringBootApplication;
37+
38+
import componenttest.annotation.MinimumJavaLevel;
39+
import componenttest.custom.junit.runner.FATRunner;
40+
import componenttest.topology.utils.HttpUtils;
41+
42+
@RunWith(FATRunner.class)
43+
@MinimumJavaLevel(javaLevel = 17)
44+
public class JPAEclipseLinkAppTests30 extends JPAAppAbstractTests {
45+
46+
@BeforeClass
47+
public static void modifyTestApp() {
48+
// modify the app to include hibernate in the WEB-INF/lib folder from the WEB-INF/lib-provided folder
49+
try {
50+
RemoteFile rFile = server.getFileFromLibertyServerRoot("apps/" + SPRING_BOOT_30_APP_DATA);
51+
File f = new File(rFile.getAbsolutePath());
52+
removePersistenceXML(f);
53+
} catch (Exception e) {
54+
throw new RuntimeException(e);
55+
}
56+
}
57+
58+
private static String eclipseLinkAppName() {
59+
return "eclipseLink." + SPRING_BOOT_30_APP_DATA;
60+
}
61+
62+
private static void removePersistenceXML(File f) throws IOException {
63+
try (JarFile jarFile = new JarFile(f);
64+
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(new File(f.getParentFile(), eclipseLinkAppName())))) {
65+
Enumeration<JarEntry> entries = jarFile.entries();
66+
while (entries.hasMoreElements()) {
67+
JarEntry originalEntry = entries.nextElement();
68+
JarEntry newEntry = originalEntry;
69+
String entryName = originalEntry.getName();
70+
if (entryName.equals("WEB-INF/classes/META-INF/persistence.xml")) {
71+
// Remove the default persistence.xml processed by Liberty
72+
continue;
73+
}
74+
if (entryName.equals("WEB-INF/web.xml")) {
75+
// Remove the web.xml
76+
continue;
77+
}
78+
jarOutputStream.putNextEntry(newEntry);
79+
byte[] buffer = new byte[1024];
80+
int bytesRead;
81+
try (InputStream entryIn = jarFile.getInputStream(originalEntry)) {
82+
while ((bytesRead = entryIn.read(buffer)) != -1) {
83+
jarOutputStream.write(buffer, 0, bytesRead);
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
@Override
91+
public void modifyAppConfiguration(SpringBootApplication appConfig) {
92+
// Using Spring class EclipseLinkJpaVendorAdapter directly requires thrid-party API access
93+
ClassloaderElement classloader = new ClassloaderElement();
94+
classloader.setApiTypeVisibility("+third-party");
95+
appConfig.getClassloaders().add(classloader);
96+
}
97+
98+
@Test
99+
public void testEclipseLinkJPAAppRunner() throws Exception {
100+
assertNotNull("Did not find TESTS PASSED messages", server.waitForStringInLog("COMMAND_LINE_RUNNER: SPRING DATA TEST: PASSED"));
101+
}
102+
103+
@Test
104+
public void testEclipseLinkJPAWebContext() throws Exception {
105+
HttpUtils.findStringInUrl(server, "/testPersistence", "TESTED PERSISTENCE");
106+
assertNotNull("Did not find TESTS PASSED messages", server.waitForStringInLog("WEB_CONTEXT: SPRING DATA TEST: PASSED"));
107+
}
108+
109+
@Override
110+
public Set<String> getFeatures() {
111+
return new HashSet<>(Arrays.asList("springBoot-3.0", "servlet-6.0", "jdbc-4.2", "jndi-1.0", "componenttest-2.0", "persistence-3.1"));
112+
}
113+
114+
@Override
115+
public AppConfigType getApplicationConfigType() {
116+
return AppConfigType.SPRING_BOOT_APP_TAG;
117+
}
118+
119+
@AfterClass
120+
public static void stopServerWithErrors() throws Exception {
121+
server.stopServer("CWWJP9991W", "WTRN0074E");
122+
}
123+
124+
@Override
125+
public Map<String, String> getBootStrapProperties() {
126+
return Collections.singletonMap("test.persistence", "eclipselink");
127+
}
128+
129+
@Override
130+
public String getApplication() {
131+
return eclipseLinkAppName();
132+
}
133+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
*******************************************************************************/
11+
package com.ibm.ws.springboot.support.fat;
12+
13+
import static org.junit.Assert.assertNotNull;
14+
15+
import java.io.File;
16+
import java.io.FileOutputStream;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.Enumeration;
22+
import java.util.HashSet;
23+
import java.util.Map;
24+
import java.util.Set;
25+
import java.util.jar.JarEntry;
26+
import java.util.jar.JarFile;
27+
import java.util.jar.JarOutputStream;
28+
29+
import org.junit.AfterClass;
30+
import org.junit.BeforeClass;
31+
import org.junit.Test;
32+
import org.junit.runner.RunWith;
33+
34+
import com.ibm.websphere.simplicity.RemoteFile;
35+
import com.ibm.websphere.simplicity.config.ClassloaderElement;
36+
import com.ibm.websphere.simplicity.config.SpringBootApplication;
37+
38+
import componenttest.annotation.MinimumJavaLevel;
39+
import componenttest.custom.junit.runner.FATRunner;
40+
import componenttest.topology.utils.HttpUtils;
41+
42+
@RunWith(FATRunner.class)
43+
@MinimumJavaLevel(javaLevel = 17)
44+
public class JPAEclipseLinkWeavingAppTests30 extends JPAAppAbstractTests {
45+
46+
@BeforeClass
47+
public static void modifyTestApp() {
48+
// modify the app to include hibernate in the WEB-INF/lib folder from the WEB-INF/lib-provided folder
49+
try {
50+
RemoteFile rFile = server.getFileFromLibertyServerRoot("apps/" + SPRING_BOOT_30_APP_DATA);
51+
File f = new File(rFile.getAbsolutePath());
52+
removePersistenceXML(f);
53+
} catch (Exception e) {
54+
throw new RuntimeException(e);
55+
}
56+
}
57+
58+
private static String eclipseLinkAppName() {
59+
return "eclipseLink.weaving." + SPRING_BOOT_30_APP_DATA;
60+
}
61+
62+
private static void removePersistenceXML(File f) throws IOException {
63+
try (JarFile jarFile = new JarFile(f);
64+
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(new File(f.getParentFile(), eclipseLinkAppName())))) {
65+
Enumeration<JarEntry> entries = jarFile.entries();
66+
while (entries.hasMoreElements()) {
67+
JarEntry originalEntry = entries.nextElement();
68+
JarEntry newEntry = originalEntry;
69+
String entryName = originalEntry.getName();
70+
if (entryName.equals("WEB-INF/classes/META-INF/persistence.xml")) {
71+
// Remove the default persistence.xml processed by Liberty
72+
continue;
73+
}
74+
if (entryName.equals("WEB-INF/web.xml")) {
75+
// Remove the web.xml
76+
continue;
77+
}
78+
jarOutputStream.putNextEntry(newEntry);
79+
byte[] buffer = new byte[1024];
80+
int bytesRead;
81+
try (InputStream entryIn = jarFile.getInputStream(originalEntry)) {
82+
while ((bytesRead = entryIn.read(buffer)) != -1) {
83+
jarOutputStream.write(buffer, 0, bytesRead);
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
@Override
91+
public void modifyAppConfiguration(SpringBootApplication appConfig) {
92+
// Using Spring class EclipseLinkJpaVendorAdapter directly requires thrid-party API access
93+
ClassloaderElement classloader = new ClassloaderElement();
94+
classloader.setApiTypeVisibility("+third-party");
95+
appConfig.getClassloaders().add(classloader);
96+
}
97+
98+
@Test
99+
public void testEclipseLinkWeavingJPAAppRunner() throws Exception {
100+
assertNotNull("Did not find TESTS PASSED messages", server.waitForStringInLog("COMMAND_LINE_RUNNER: SPRING DATA TEST: PASSED"));
101+
}
102+
103+
@Test
104+
public void testEclipseLinkWeavingJPAWebContext() throws Exception {
105+
HttpUtils.findStringInUrl(server, "/testPersistence", "TESTED PERSISTENCE");
106+
assertNotNull("Did not find TESTS PASSED messages", server.waitForStringInLog("WEB_CONTEXT: SPRING DATA TEST: PASSED"));
107+
}
108+
109+
@Override
110+
public Set<String> getFeatures() {
111+
return new HashSet<>(Arrays.asList("springBoot-3.0", "servlet-6.0", "jdbc-4.2", "jndi-1.0", "componenttest-2.0", "persistence-3.1"));
112+
}
113+
114+
@Override
115+
public AppConfigType getApplicationConfigType() {
116+
return AppConfigType.SPRING_BOOT_APP_TAG;
117+
}
118+
119+
@AfterClass
120+
public static void stopServerWithErrors() throws Exception {
121+
server.stopServer("CWWJP9991W", "WTRN0074E");
122+
}
123+
124+
@Override
125+
public Map<String, String> getBootStrapProperties() {
126+
return Collections.singletonMap("test.persistence", "eclipselink.weaving");
127+
}
128+
129+
@Override
130+
public String getApplication() {
131+
return eclipseLinkAppName();
132+
}
133+
}

0 commit comments

Comments
 (0)