Issue #23507 jdbc-admin now uses junit5 instead of junit4 + enabled some tests
diff --git a/appserver/jdbc/admin/pom.xml b/appserver/jdbc/admin/pom.xml
index 87a2163..6fdc1bf 100644
--- a/appserver/jdbc/admin/pom.xml
+++ b/appserver/jdbc/admin/pom.xml
@@ -75,14 +75,28 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.glassfish.main.core</groupId>
- <artifactId>kernel</artifactId>
+ <groupId>org.glassfish.main.admin</groupId>
+ <artifactId>admin-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.main.tests</groupId>
+ <artifactId>utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.glassfish.main.tests</groupId>
- <artifactId>utils</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>kernel</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
@@ -96,15 +110,7 @@
<artifactId>jakarta.el</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.glassfish.main.admin</groupId>
- <artifactId>admin-util</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest</artifactId>
- </dependency>
+
</dependencies>
<build>
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/CreateJdbcResourceTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/CreateJdbcResourceTest.java
index 7af0802..b02b042 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/CreateJdbcResourceTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/CreateJdbcResourceTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 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
@@ -16,69 +17,69 @@
package org.glassfish.jdbc.admin.cli;
-import com.sun.enterprise.config.serverbeans.*;
-import com.sun.enterprise.v3.common.PropsFileActionReporter;
+import com.sun.enterprise.config.serverbeans.Domain;
+import com.sun.enterprise.config.serverbeans.Resource;
+import com.sun.enterprise.config.serverbeans.ResourceRef;
+import com.sun.enterprise.config.serverbeans.Resources;
+import com.sun.enterprise.config.serverbeans.Server;
+import com.sun.enterprise.config.serverbeans.Servers;
import com.sun.enterprise.util.SystemPropertyConstants;
+import com.sun.enterprise.v3.common.PropsFileActionReporter;
import com.sun.logging.LogDomains;
-import java.beans.PropertyVetoException;
+import java.util.logging.Logger;
+import javax.security.auth.Subject;
+
+import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.AdminCommandContextImpl;
import org.glassfish.api.admin.CommandRunner;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
import org.glassfish.jdbc.config.JdbcResource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.glassfish.api.ActionReport;
import org.glassfish.tests.utils.Utils;
-import org.glassfish.tests.utils.ConfigApiTest;
-import org.jvnet.hk2.config.DomDocument;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
+import jakarta.inject.Inject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
- *
* @author Jennifer
*/
-//@Ignore // temporarily disabled
-public class CreateJdbcResourceTest extends ConfigApiTest {
- // Get Resources config bean
- ServiceLocator habitat = Utils.instance.getHabitat(this);
- private Resources resources = habitat.<Domain>getService(Domain.class).getResources();
- private CreateJdbcResource command = null;
+@ExtendWith(JdbcAdminJunit5Extension.class)
+public class CreateJdbcResourceTest {
+ private final Subject adminSubject = Utils.createInternalAsadminSubject();
+ @Inject
+ private ServiceLocator habitat;
+ @Inject
+ private Logger logger;
+ private Resources resources;
+ private CreateJdbcResource command;
private ParameterMap parameters = new ParameterMap();
- private AdminCommandContext context = null;
- private CommandRunner cr = null;
+ private AdminCommandContext context;
+ private CommandRunner cr;
- @Override
- public DomDocument getDocument(ServiceLocator habitat) {
-
- return new TestDocument(habitat);
- }
-
- /**
- * Returns the DomainTest file name without the .xml extension to load the test configuration
- * from.
- *
- * @return the configuration file name
- */
- public String getFileName() {
- return "DomainTest";
- }
-
- @Before
+ @BeforeEach
public void setUp() {
- assertTrue(resources!=null);
+ resources = habitat.<Domain>getService(Domain.class).getResources();
+ assertNotNull(resources);
// Get an instance of the CreateJdbcResource command
command = habitat.getService(CreateJdbcResource.class);
- assertTrue(command!=null);
+ assertNotNull(command);
// Set the options and operand to pass to the command
parameters.set("connectionpoolid", "DerbyPool");
@@ -93,34 +94,31 @@
cr = habitat.getService(CommandRunner.class);
}
- @After
+ @AfterEach
public void tearDown() throws TransactionFailure {
- // Delete the created resource
- ConfigSupport.apply(new SingleConfigCode<Resources>() {
- public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
- Resource target = null;
- // TODO: this causes NoSuchElementException but really
- // it should have caused ConcurrentModificationException, because the iteration
- // and removal runs at the same time.
- for (Resource resource : param.getResources()) {
- if (resource instanceof JdbcResource) {
- JdbcResource jr = (JdbcResource)resource;
- if (jr.getJndiName().equals("jdbc/foo")||
- jr.getJndiName().equals("dupRes")||
- jr.getJndiName().equals("jdbc/sun")||
- jr.getJndiName().equals("jdbc/alldefaults")||
- jr.getJndiName().equals("jdbc/junk")) {
- target = resource;
- break;
- }
+ // Delete the created resource
+ SingleConfigCode<Resources> configCode = resourcesBean -> {
+ Resource target = null;
+ // TODO: this causes NoSuchElementException but really
+ // it should have caused ConcurrentModificationException, because the iteration
+ // and removal runs at the same time.
+ for (Resource resource : resourcesBean.getResources()) {
+ if (resource instanceof JdbcResource) {
+ JdbcResource jr = (JdbcResource) resource;
+ if (jr.getJndiName().equals("jdbc/foo") || jr.getJndiName().equals("dupRes")
+ || jr.getJndiName().equals("jdbc/sun") || jr.getJndiName().equals("jdbc/alldefaults")
+ || jr.getJndiName().equals("jdbc/junk")) {
+ target = resource;
+ break;
}
}
- if (target!=null) {
- param.getResources().remove(target);
- }
- return null;
}
- }, resources);
+ if (target != null) {
+ resourcesBean.getResources().remove(target);
+ }
+ return null;
+ };
+ ConfigSupport.apply(configCode, resources);
parameters = new ParameterMap();
}
@@ -136,7 +134,7 @@
parameters.set("DEFAULT", "jdbc/foo");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -190,7 +188,7 @@
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -228,7 +226,7 @@
parameters.set("DEFAULT", "dupRes");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -249,7 +247,7 @@
//Try to create a duplicate resource dupRes. Get a new instance of the command.
CreateJdbcResource command2 = habitat.getService(CreateJdbcResource.class);
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command2);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -285,7 +283,7 @@
parameters.set("DEFAULT", "jdbc/nopool");
// Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is Failure
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -313,7 +311,6 @@
* asadmin create-jdbc-resource --connectionpoolid DerbyPool --enabled=junk
* --description "my resource" jdbc/junk
*/
- @Ignore
@Test
public void testExecuteFailInvalidOptionEnabled() {
// Set invalid enabled option value: --enabled junk
@@ -321,11 +318,10 @@
parameters.set("DEFAULT", "jdbc/junk");
// Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is Failure
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
-
// Don't check error message. Error message being set by CommandRunnerImpl.
}
@@ -341,7 +337,7 @@
parameters.set("DEFAULT", "jdbc/sun");
// Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -361,7 +357,6 @@
}
}
assertTrue(isCreated);
-
logger.fine("msg: " + context.getActionReport().getMessage());
}
}
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/DeleteJdbcResourceTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/DeleteJdbcResourceTest.java
index 779124b..4ee0ae6 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/DeleteJdbcResourceTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/DeleteJdbcResourceTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 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
@@ -16,64 +17,68 @@
package org.glassfish.jdbc.admin.cli;
-import com.sun.enterprise.config.serverbeans.*;
-import com.sun.enterprise.v3.common.PropsFileActionReporter;
+import com.sun.enterprise.config.serverbeans.Domain;
+import com.sun.enterprise.config.serverbeans.Resource;
+import com.sun.enterprise.config.serverbeans.ResourceRef;
+import com.sun.enterprise.config.serverbeans.Resources;
+import com.sun.enterprise.config.serverbeans.Server;
+import com.sun.enterprise.config.serverbeans.Servers;
import com.sun.enterprise.util.SystemPropertyConstants;
+import com.sun.enterprise.v3.common.PropsFileActionReporter;
import com.sun.logging.LogDomains;
+import java.util.logging.Logger;
+import javax.security.auth.Subject;
+
+import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.AdminCommandContextImpl;
import org.glassfish.api.admin.CommandRunner;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
import org.glassfish.jdbc.config.JdbcResource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.glassfish.api.ActionReport;
import org.glassfish.tests.utils.Utils;
-import org.glassfish.tests.utils.ConfigApiTest;
-import org.jvnet.hk2.config.DomDocument;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import jakarta.inject.Inject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
* @author Jennifer
*/
-//@Ignore // temporarily disabled
-public class DeleteJdbcResourceTest extends ConfigApiTest {
- ServiceLocator habitat = Utils.instance.getHabitat(this);
- private Resources resources = habitat.<Domain>getService(Domain.class).getResources();
- private DeleteJdbcResource deleteCommand = null;
+@ExtendWith(JdbcAdminJunit5Extension.class)
+public class DeleteJdbcResourceTest {
+ private final Subject adminSubject = Utils.createInternalAsadminSubject();
+ @Inject
+ private ServiceLocator habitat;
+ @Inject
+ private Logger logger;
+ private Resources resources;
+ private DeleteJdbcResource deleteCommand;
private ParameterMap parameters = new ParameterMap();
- private AdminCommandContext context = null;
- private CommandRunner cr = habitat.getService(CommandRunner.class);
+ private AdminCommandContext context;
+ private CommandRunner cr;
- @Override
- public DomDocument getDocument(ServiceLocator habitat) {
-
- return new TestDocument(habitat);
- }
-
- /**
- * Returns the DomainTest file name without the .xml extension to load the test configuration
- * from.
- *
- * @return the configuration file name
- */
- public String getFileName() {
- return "DomainTest";
- }
-
- @Before
+ @BeforeEach
public void setUp() {
- assertTrue(resources!=null);
+ resources = habitat.<Domain>getService(Domain.class).getResources();
+ assertNotNull(resources);
+ cr = habitat.getService(CommandRunner.class);
// Create a JDBC Resource jdbc/foo for each test
CreateJdbcResource createCommand = habitat.getService(CreateJdbcResource.class);
- assertTrue(createCommand!=null);
+ assertNotNull(createCommand);
parameters.add("connectionpoolid", "DerbyPool");
parameters.add("DEFAULT", "jdbc/foo");
@@ -82,7 +87,7 @@
LogDomains.getLogger(DeleteJdbcResourceTest.class, LogDomains.ADMIN_LOGGER),
new PropsFileActionReporter());
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Setup for delete-jdbc-resource
@@ -91,12 +96,12 @@
assertTrue(deleteCommand!=null);
}
- @After
+ @AfterEach
public void tearDown() {
// Cleanup any leftover jdbc/foo resource - could be success or failure depending on the test
parameters = new ParameterMap();
parameters.add("DEFAULT", "jdbc/foo");
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
}
/**
@@ -109,7 +114,7 @@
parameters.add("DEFAULT", "jdbc/foo");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -159,7 +164,7 @@
parameters.add("DEFAULT", "jdbc/foo");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -208,7 +213,7 @@
parameters.add("DEFAULT", "doesnotexist");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -222,11 +227,11 @@
* Test of execute method, of class DeleteJdbcResource.
* delete-jdbc-resource
*/
- @Ignore
@Test
+ @Disabled("Results in 'Cannot find jndiName in delete-jdbc-resource command model, file a bug'")
public void testExecuteFailNoOperand() {
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -239,15 +244,15 @@
* Test of execute method, of class DeleteJdbcResource.
* delete-jdbc-resource --invalid jdbc/foo
*/
- @Ignore
@Test
+ @Disabled("The action report error message contains weird characters (EOL, percents)")
public void testExecuteFailInvalidOption() {
// Set operand
parameters.add("invalid", "");
parameters.add("DEFAULT", "jdbc/foo");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
@@ -261,19 +266,13 @@
* delete-jdbc-resource --target invalid jdbc/foo
*/
@Test
- @Ignore
- //disabling the test.
- //in v3, this test was expecting the Command to return failure code.
- //in 3.1 --target validation is done by CLI framework (as part of command replication)
- //as of now command replication is not enabled by default and as a result,
- //the modified command does not fail when an invalid target is specified
public void testExecuteFailInvalidTarget() {
// Set operand
parameters.add("target", "invalid");
parameters.add("DEFAULT", "jdbc/foo");
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
//Check that the resource was NOT deleted
boolean isDeleted = true;
@@ -288,7 +287,7 @@
}
}
// Need bug fix in DeleteJdbcResource before uncommenting assertion
- //assertFalse(isDeleted);
+ assertFalse(isDeleted);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
index b83ef09..289d4f2 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/ListJdbcResourcesTest.java
@@ -23,59 +23,56 @@
import com.sun.logging.LogDomains;
import java.util.List;
+import java.util.logging.Logger;
+import javax.security.auth.Subject;
+
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.ActionReport.MessagePart;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.AdminCommandContextImpl;
import org.glassfish.api.admin.CommandRunner;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
import org.glassfish.jdbc.config.JdbcResource;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.glassfish.api.ActionReport;
-import org.glassfish.api.ActionReport.MessagePart;
import org.glassfish.tests.utils.Utils;
-import org.glassfish.tests.utils.ConfigApiTest;
-import org.jvnet.hk2.config.DomDocument;
-import org.jvnet.hk2.config.TransactionFailure;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import jakarta.inject.Inject;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
* @author Jennifer
*/
-//@Ignore // temporarily disabled
-public class ListJdbcResourcesTest extends ConfigApiTest {
- private ServiceLocator habitat = Utils.instance.getHabitat(this);
- private Resources resources = habitat.<Domain>getService(Domain.class).getResources();
+@ExtendWith(JdbcAdminJunit5Extension.class)
+public class ListJdbcResourcesTest {
+ private final Subject adminSubject = Utils.createInternalAsadminSubject();
+ @Inject
+ private ServiceLocator habitat;
+ @Inject
+ private Logger logger;
+
+ private Resources resources;
private int origNum = 0;
- private ParameterMap parameters = new ParameterMap();
- CreateJdbcResource createCommand = null;
- DeleteJdbcResource deleteCommand = null;
- ListJdbcResources listCommand = null;
- AdminCommandContext context = null;
- CommandRunner cr = habitat.getService(CommandRunner.class);
+ private ParameterMap parameters;
+ private CreateJdbcResource createCommand;
+ private DeleteJdbcResource deleteCommand;
+ private ListJdbcResources listCommand;
+ private AdminCommandContext context;
+ private CommandRunner cr;
- @Override
- public DomDocument getDocument(ServiceLocator habitat) {
- return new TestDocument(habitat);
- }
-
- /**
- * Returns the file name without the .xml extension to load the test configuration
- * from. By default, it's the name of the TestClass.
- *
- * @return the configuration file name
- */
- public String getFileName() {
- return "DomainTest";
- }
-
- @Before
+ @BeforeEach
public void setUp() {
+ parameters = new ParameterMap();
+ resources = habitat.<Domain>getService(Domain.class).getResources();
+ cr = habitat.getService(CommandRunner.class);
for (Resource resource : resources.getResources()) {
if (resource instanceof JdbcResource) {
origNum = origNum + 1;
@@ -83,27 +80,19 @@
}
}
- @After
- public void tearDown() throws TransactionFailure {
- parameters = new ParameterMap();
- }
-
/**
* Test of execute method, of class ListJdbcResources.
* list-jdbc-resources
*/
@Test
public void testExecuteSuccessListOriginal() {
- // List the original set of JDBC Resources
- //Get an instance of the ListJdbcResources command
- ListJdbcResources listCommand = habitat.getService(ListJdbcResources.class);
-
- AdminCommandContext context = new AdminCommandContextImpl(
+ listCommand = habitat.getService(ListJdbcResources.class);
+ context = new AdminCommandContextImpl(
LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER),
new PropsFileActionReporter());
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum, list.size());
@@ -129,7 +118,7 @@
new PropsFileActionReporter());
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum, list.size());
@@ -159,7 +148,7 @@
LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER),
new PropsFileActionReporter());
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -172,7 +161,7 @@
new PropsFileActionReporter());
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
@@ -209,7 +198,7 @@
LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER),
new PropsFileActionReporter());
- cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
+ cr.getCommandInvocation("create-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -223,7 +212,7 @@
parameters = new ParameterMap();
parameters.add("DEFAULT", "bob2");
- cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ cr.getCommandInvocation("delete-jdbc-resource", context.getActionReport(), adminSubject).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
@@ -236,7 +225,7 @@
new PropsFileActionReporter());
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
@@ -263,7 +252,6 @@
* Test of execute method, of class ListJdbcResource.
* list-jdbc-resources invalid
*/
- @Ignore
@Test
public void testExecuteFailInvalidTargetOperand() {
// List the original set of JDBC Resources
@@ -277,23 +265,19 @@
new PropsFileActionReporter());
//Call CommandRunnerImpl.doCommand(..) to execute the command
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
- // Need bug fix before uncommenting assertion
- //List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
- //assertEquals(0, list.size());
+ List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
+ assertEquals(0, list.size());
// Check the exit code is FAILURE
- // Need bug fix before uncommenting assertion
- //assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
- // Check error msg 'Invalid target: invalid'
+ assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
}
/**
* Test of execute method, of class ListJdbcResource.
* list-jdbc-resources --invalid invalid
*/
- @Ignore
@Test
public void testExecuteFailInvalidOption() {
listCommand = habitat.getService(ListJdbcResources.class);
@@ -302,13 +286,13 @@
LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER),
new PropsFileActionReporter());
- cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(1, list.size());
for (MessagePart mp : list) {
- assertEquals("Usage: list-jdbc-resources ", mp.getMessage());
+ assertEquals("Usage: list-jdbc-resources [target] ", mp.getMessage());
}
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/TestDocument.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/TestDocument.java
deleted file mode 100644
index 1b3d7e4..0000000
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/TestDocument.java
+++ /dev/null
@@ -1,47 +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.jdbc.admin.cli;
-
-import org.jvnet.hk2.config.DomDocument;
-import org.jvnet.hk2.config.Dom;
-import org.jvnet.hk2.config.ConfigModel;
-import org.glassfish.config.support.GlassFishConfigBean;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.junit.Ignore;
-
-import javax.xml.stream.XMLStreamReader;
-
-/**
- *
- * This document will create the appropriate ConfigBean implementation but will
- * not save the modified config tree.
- *
- * User: Jerome Dochez
- */
-@Ignore
-public class TestDocument extends DomDocument<GlassFishConfigBean> {
-
- public TestDocument(ServiceLocator habitat) {
- super(habitat);
- }
-
- @Override
- public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
- // by default, people get the translated view.
- return new GlassFishConfigBean(habitat, this, dom, configModel, xmlStreamReader);
- }
-}
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/test/JdbcAdminJunit5Extension.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/test/JdbcAdminJunit5Extension.java
new file mode 100644
index 0000000..8f1be52
--- /dev/null
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/admin/cli/test/JdbcAdminJunit5Extension.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021 Eclipse Foundation 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.jdbc.admin.cli.test;
+
+import com.sun.enterprise.admin.util.InstanceStateService;
+
+import org.glassfish.tests.utils.DomainXml;
+import org.glassfish.tests.utils.HK2JUnit5Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import static org.glassfish.hk2.utilities.ServiceLocatorUtilities.addOneDescriptor;
+import static org.glassfish.tests.utils.Utils.createMockDescriptor;
+
+
+/**
+ * @author David Matejcek
+ */
+public class JdbcAdminJunit5Extension extends HK2JUnit5Extension {
+
+ @Override
+ protected String getDomainXml(Class<?> testClass) {
+ if (testClass.getAnnotation(DomainXml.class) == null) {
+ return "DomainTest.xml";
+ }
+ return super.getDomainXml(testClass);
+ }
+
+
+ @Override
+ public void beforeEach(ExtensionContext context) throws Exception {
+ super.beforeEach(context);
+ addOneDescriptor(getLocator(), createMockDescriptor(InstanceStateService.class));
+ }
+}
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConcurrentModificationsTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConcurrentModificationsTest.java
index 2c33c9a..665e2eb 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConcurrentModificationsTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConcurrentModificationsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008, 2018 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
@@ -20,75 +21,69 @@
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.Resources;
+import java.util.List;
+
import org.glassfish.hk2.api.ServiceLocator;
-import org.junit.Test;
-import static org.junit.Assert.*;
-import org.jvnet.hk2.config.TransactionFailure;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
+import org.glassfish.tests.utils.DomainXml;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
-import java.beans.PropertyVetoException;
+import jakarta.inject.Inject;
-public class ConcurrentModificationsTest extends ConfigApiTest{
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- /**
- * Returns the file name without the .xml extension to load the test configuration
- * from. By default, it's the name of the TestClass.
- *
- * @return the configuration file name
- */
- public String getFileName() {
- return "DomainTest";
- }
+@ExtendWith(JdbcAdminJunit5Extension.class)
+@DomainXml("DomainTest.xml")
+public class ConcurrentModificationsTest {
- @Test(expected= TransactionFailure.class)
+ @Inject
+ private ServiceLocator locator;
+
+ @Test
public void collectionTest() throws TransactionFailure {
- ServiceLocator habitat = super.getHabitat();
- final Resources resources = habitat.<Domain>getService(Domain.class).getResources();
- assertTrue(resources!=null);
+ final Resources resources = locator.<Domain>getService(Domain.class).getResources();
+ assertNotNull(resources);
- ConfigSupport.apply(new SingleConfigCode<Resources>() {
+ SingleConfigCode<Resources> configCode = writeableResources -> {
- public Object run(Resources writeableResources) throws PropertyVetoException, TransactionFailure {
+ assertNotNull(writeableResources);
+ JdbcResource newResource = writeableResources.createChild(JdbcResource.class);
+ newResource.setJndiName("foo");
+ newResource.setDescription("Random ");
+ newResource.setPoolName("bar");
+ newResource.setEnabled("true");
+ writeableResources.getResources().add(newResource);
- assertTrue(writeableResources!=null);
- JdbcResource newResource = writeableResources.createChild(JdbcResource.class);
- newResource.setJndiName("foo");
- newResource.setDescription("Random ");
- newResource.setPoolName("bar");
- newResource.setEnabled("true");
- writeableResources.getResources().add(newResource);
+ // now let's check I have my copy...
+ assertTrue(containsFoo(writeableResources.getResources()), "writeableResources should NOT contain foo");
- // now let's check I have my copy...
- boolean found=false;
- for (Resource resource : writeableResources.getResources()) {
- if (resource instanceof JdbcResource) {
- JdbcResource jdbc = (JdbcResource) resource;
- if (jdbc.getJndiName().equals("foo")) {
- found = true;
- break;
- }
- }
+ // now let's check that my readonly copy does not see it...
+ assertFalse(containsFoo(resources.getResources()), "resources should contain foo");
+
+ // now I am throwing a transaction failure since I don't care about saving it
+ throw new TransactionFailure("Test passed", null);
+ };
+ assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, resources));
+ }
+
+
+ private boolean containsFoo(List<Resource> resources) {
+ for (Resource resource : resources) {
+ if (resource instanceof JdbcResource) {
+ JdbcResource jdbc2 = (JdbcResource) resource;
+ if (jdbc2.getJndiName().equals("foo")) {
+ return true;
}
- assertTrue(found);
-
- // now let's check that my readonly copy does not see it...
- boolean shouldNot = false;
- for (Resource resource : resources.getResources()) {
- if (resource instanceof JdbcResource) {
- JdbcResource jdbc = (JdbcResource) resource;
- if (jdbc.getJndiName().equals("foo")) {
- shouldNot = true;
- break;
- }
- }
- }
- assertFalse(shouldNot);
-
- // now I am throwing a transaction failure since I don't care about saving it
- throw new TransactionFailure("Test passed", null);
}
- },resources);
+ }
+ return false;
}
}
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConfigApiTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/ConfigApiTest.java
deleted file mode 100644
index 0973acf..0000000
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/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.jdbc.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/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolDefaultsTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolDefaultsTest.java
index 848c888..24c0d4e 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolDefaultsTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolDefaultsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1997, 2018 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
@@ -16,45 +17,28 @@
package org.glassfish.jdbc.config;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
+import org.glassfish.tests.utils.DomainXml;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.junit.Assert.*;
+import jakarta.inject.Inject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests the JdbcConnectionPool config bean's defaults.
* @author Kedar Mhaswade (km@dev.java.net)
*/
+@ExtendWith(JdbcAdminJunit5Extension.class)
+@DomainXml("JdbcConnectionPoolDefaults.xml")
+public class JdbcConnectionPoolDefaultsTest {
-public class JdbcConnectionPoolDefaultsTest extends ConfigApiTest{
+ @Inject
+ private JdbcConnectionPool onlyOnePool;
- JdbcConnectionPool onlyOnePool = null;
-
- public JdbcConnectionPoolDefaultsTest() {
- }
-
- @Override
- public String getFileName() {
- return ("JdbcConnectionPoolDefaults"); //this is the xml to load
- }
-
- @Before
- public void setUp() {
- onlyOnePool = super.getHabitat().getService(JdbcConnectionPool.class);
- }
-
- @After
- public void tearDown() {
- onlyOnePool = null;
- }
-
- // TODO add test methods here.
- // The methods must be annotated with annotation @Test. For example:
- //
@Test
public void testFewDefaults() {
-
assertEquals("8", onlyOnePool.getSteadyPoolSize());
assertEquals("32", onlyOnePool.getMaxPoolSize());
assertEquals("false", onlyOnePool.getMatchConnections());
diff --git a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolValidationTest.java b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolValidationTest.java
index 10c3b73..fb523ad 100644
--- a/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolValidationTest.java
+++ b/appserver/jdbc/admin/src/test/java/org/glassfish/jdbc/config/JdbcConnectionPoolValidationTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009, 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,73 +18,60 @@
package org.glassfish.jdbc.config;
import java.beans.PropertyVetoException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jdbc.admin.cli.test.JdbcAdminJunit5Extension;
+import org.glassfish.tests.utils.DomainXml;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
-
+import jakarta.inject.Inject;
import jakarta.validation.ConstraintViolationException;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
/**
- *
* @author केदार (km@dev.java.net)
*/
-public class JdbcConnectionPoolValidationTest extends ConfigApiTest {
+@ExtendWith(JdbcAdminJunit5Extension.class)
+@DomainXml("JdbcConnectionPoolValidation.xml")
+public class JdbcConnectionPoolValidationTest {
- private JdbcConnectionPool pool = null;
- private static final String NAME = "test"; //same as the one in JdbcConnectionPoolValidation.xml
+ // same as the one in JdbcConnectionPoolValidation.xml
+ private static final String NAME = "test";
+ @Inject
+ private ServiceLocator locator;
+ private JdbcConnectionPool pool;
- public JdbcConnectionPoolValidationTest() {
- }
-
- @Override
- public String getFileName() {
- return ("JdbcConnectionPoolValidation");
- }
-
- @Before
+ @BeforeEach
public void setUp() {
- pool = super.getHabitat().getService(JdbcConnectionPool.class, NAME);
+ pool = locator.getService(JdbcConnectionPool.class, NAME);
}
- @After
- public void tearDown() {
- pool = null;
- }
-
- // TODO add test methods here.
- // The methods must be annotated with annotation @Test. For example:
- //
- @Test (expected= ConstraintViolationException.class)
- public void testBooleanDoesNotTakeInteger1() throws Throwable {
- try {
- ConfigSupport.apply(new SingleConfigCode<JdbcConnectionPool>() {
- public Object run(JdbcConnectionPool jdbcConnectionPool) throws PropertyVetoException, TransactionFailure {
- jdbcConnectionPool.setConnectionLeakReclaim("123"); //this method should only take boolean;
- return null;
- }
- }, pool);
-
- } catch(TransactionFailure e) {
- throw e.getCause().getCause();
- }
+ @Test
+ public void testBooleanDoesNotTakeInteger1() throws Exception {
+ SingleConfigCode<JdbcConnectionPool> configCode = jdbcConnectionPool -> {
+ jdbcConnectionPool.setConnectionLeakReclaim("123");
+ return null;
+ };
+ TransactionFailure e = assertThrows(TransactionFailure.class, () -> ConfigSupport.apply(configCode, pool));
+ assertThat(e.getCause(), instanceOf(RuntimeException.class));
+ assertThat(e.getCause().getCause(), instanceOf(ConstraintViolationException.class));
}
@Test
public void testBooleanTakesTrueFalse() {
- try {
- pool.setSteadyPoolSize("true"); //this only takes a boolean
- pool.setSteadyPoolSize("false"); //this only takes a boolean
- pool.setSteadyPoolSize("TRUE"); //this only takes a boolean
- pool.setSteadyPoolSize("FALSE"); //this only takes a boolean
- pool.setSteadyPoolSize("FALSE"); //this only takes a boolean
- } catch(PropertyVetoException pv) {
- //ignore?
- }
+ assertThrows(PropertyVetoException.class, () -> pool.setSteadyPoolSize("true"));
+ assertThrows(PropertyVetoException.class, () -> pool.setSteadyPoolSize("false"));
+ assertThrows(PropertyVetoException.class, () -> pool.setSteadyPoolSize("TRUE"));
+ assertThrows(PropertyVetoException.class, () -> pool.setSteadyPoolSize("FALSE"));
+ assertThrows(PropertyVetoException.class, () -> pool.setSteadyPoolSize("FALSE"));
}
}