Issue #23507 jdbc-runtime now uses junit5 instead of junit4
- the test probably belongs to another module, not here
diff --git a/appserver/jdbc/jdbc-runtime/pom.xml b/appserver/jdbc/jdbc-runtime/pom.xml
index d865950..f04c773 100644
--- a/appserver/jdbc/jdbc-runtime/pom.xml
+++ b/appserver/jdbc/jdbc-runtime/pom.xml
@@ -59,6 +59,10 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
diff --git a/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/ConfigApiTest.java b/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/ConfigApiTest.java
deleted file mode 100644
index 57af462..0000000
--- a/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/ConfigApiTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package org.glassfish.jdbcruntime.config;
-
-import org.glassfish.config.support.GlassFishDocument;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.jvnet.hk2.config.DomDocument;
-import org.junit.Ignore;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-/**
- * User: Jerome Dochez
- * Date: Mar 25, 2008
- * Time: 12:38:30 PM
- */
-public abstract class ConfigApiTest extends org.glassfish.tests.utils.ConfigApiTest {
-
- @Override
- public DomDocument getDocument(ServiceLocator habitat) {
- DomDocument doc = habitat.getService(GlassFishDocument.class);
- if (doc==null) {
- return new GlassFishDocument(habitat, Executors.newCachedThreadPool(new ThreadFactory() {
-
- public Thread newThread(Runnable r) {
- Thread t = Executors.defaultThreadFactory().newThread(r);
- t.setDaemon(true);
- return t;
- }
-
- }));
- }
- return doc;
- }
-}
diff --git a/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/validation/ReferenceConstrainTest.java b/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/validation/ReferenceConstrainTest.java
index 70c988f..d9a0bbe 100644
--- a/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/validation/ReferenceConstrainTest.java
+++ b/appserver/jdbc/jdbc-runtime/src/test/java/org/glassfish/jdbcruntime/config/validation/ReferenceConstrainTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,43 +18,39 @@
package org.glassfish.jdbcruntime.config.validation;
import com.sun.enterprise.config.serverbeans.Domain;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import jakarta.validation.ConstraintViolationException;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.jdbc.config.JdbcResource;
-import org.junit.Test;
-import org.junit.Ignore;
-import org.junit.Before;
-import org.glassfish.tests.utils.Utils;
+import org.glassfish.tests.utils.DomainXml;
+import org.glassfish.tests.utils.HK2JUnit5Extension;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hk2.config.ConfigBean;
import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.TransactionFailure;
-import org.glassfish.jdbcruntime.config.ConfigApiTest;
-import static org.junit.Assert.*;
+import jakarta.inject.Inject;
+import jakarta.validation.ConstraintViolationException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
- *
* @author mmares
*/
-public class ReferenceConstrainTest extends ConfigApiTest {
+@ExtendWith(HK2JUnit5Extension.class)
+@DomainXml(value = "DomainTest.xml")
+// FIXME: This test probably belongs to another module: code coverage here: 0.0%
+public class ReferenceConstrainTest {
-// private Logger logger = Logger.getLogger(ReferenceConstrainTest.class.getName());
+ @Inject
private ServiceLocator habitat;
- @Override
- public String getFileName() {
- return "DomainTest";
- }
-
- @Override
- public ServiceLocator getHabitat() {
- return habitat;
- }
-
private ConstraintViolationException findConstrViolation(Throwable thr) {
if (thr == null) {
return null;
@@ -64,12 +61,8 @@
return findConstrViolation(thr.getCause());
}
- @Before
- public void createNewHabitat() {
- this.habitat = Utils.instance.getHabitat(this);
- }
- @Test // @Ignore
+ @Test
public void doChangeToValidPool() throws TransactionFailure {
Domain domain = habitat.getService(Domain.class);
//Find JdbcResource to chenge its values
@@ -83,23 +76,19 @@
}
}
assertNotNull(jdbc);
- ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean poolConfig = (ConfigBean) Dom.unwrap(jdbc);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("pool-name", "DerbyPool");
changes.put(poolConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- } catch (TransactionFailure tf) {
- fail();
- }
+ ConfigSupport cs = this.habitat.getService(ConfigSupport.class);
+ cs.apply(changes);
}
@Test
public void doChangeToInValidPool() throws TransactionFailure {
Domain domain = habitat.getService(Domain.class);
- //Find JdbcResource to chenge its values
+ // Find JdbcResource to chenge its values
Iterator<JdbcResource> iterator = domain.getResources().getResources(JdbcResource.class).iterator();
JdbcResource jdbc = null;
while (iterator.hasNext()) {
@@ -110,20 +99,14 @@
}
}
assertNotNull(jdbc);
- ConfigBean poolConfig = (ConfigBean) ConfigBean.unwrap(jdbc);
- Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
- Map<String, String> configChanges = new HashMap<String, String>();
+ ConfigBean poolConfig = (ConfigBean) Dom.unwrap(jdbc);
+ Map<ConfigBean, Map<String, String>> changes = new HashMap<>();
+ Map<String, String> configChanges = new HashMap<>();
configChanges.put("pool-name", "WrongPointer");
changes.put(poolConfig, configChanges);
- try {
- ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
- cs.apply(changes);
- fail("Can not reach this point");
- } catch (TransactionFailure tf) {
- ConstraintViolationException cv = findConstrViolation(tf);
-// cv.printStackTrace(System.out);
- assertNotNull(cv);
- }
+ ConfigSupport cs = this.habitat.getService(ConfigSupport.class);
+ TransactionFailure tf = assertThrows(TransactionFailure.class, () -> cs.apply(changes));
+ ConstraintViolationException cv = findConstrViolation(tf);
+ assertNotNull(cv);
}
-
}