Refactoring in admin-tests
- separation - jersey/asadmin/url
- shutdownHook
- set of rest clients targeting usage, less confusion
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java
index 1a8f196..03912a6 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java
@@ -17,24 +17,30 @@
package org.glassfish.nucleus.admin;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.getURL;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadmin;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Tom Mueller
*/
@TestMethodOrder(OrderAnnotation.class)
-@ExtendWith(DomainLifecycleExtension.class)
public class ClusterITest {
private static final String PORT1 = "55123";
@@ -44,48 +50,54 @@
private static final String INSTANCE_NAME_2 = "eein2";
private static final String URL1 = "http://localhost:" + PORT1;
private static final String URL2 = "http://localhost:" + PORT2;
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
@Test
@Order(1)
public void createClusterTest() {
- assertTrue(nadmin("create-cluster", CLUSTER_NAME), "create cluster");
+ assertThat(ASADMIN.exec("create-cluster", CLUSTER_NAME), asadminOK());
}
@Test
@Order(2)
public void createInstancesTest() {
- assertTrue(
- nadmin("create-local-instance", "--cluster", CLUSTER_NAME, "--systemproperties",
- "HTTP_LISTENER_PORT=" + PORT1 + ":" +
- "HTTP_SSL_LISTENER_PORT=18181:" +
- "IIOP_SSL_LISTENER_PORT=13800:" +
- "IIOP_LISTENER_PORT=13700:" +
- "JMX_SYSTEM_CONNECTOR_PORT=17676:" +
- "IIOP_SSL_MUTUALAUTH_PORT=13801:" +
- "JMS_PROVIDER_PORT=18686:" +
- "ASADMIN_LISTENER_PORT=14848",
- INSTANCE_NAME_1), "create instance1");
+ assertThat(
+ ASADMIN.exec("create-local-instance", "--cluster", CLUSTER_NAME, "--systemproperties",
+ "HTTP_LISTENER_PORT=" + PORT1
+ + ":HTTP_SSL_LISTENER_PORT=18181"
+ + ":IIOP_SSL_LISTENER_PORT=13800"
+ + ":IIOP_LISTENER_PORT=13700"
+ + ":JMX_SYSTEM_CONNECTOR_PORT=17676"
+ + ":IIOP_SSL_MUTUALAUTH_PORT=13801"
+ + ":JMS_PROVIDER_PORT=18686"
+ + ":ASADMIN_LISTENER_PORT=14848",
+ INSTANCE_NAME_1), asadminOK());
- assertTrue(
- nadmin("create-local-instance", "--cluster", CLUSTER_NAME, "--systemproperties",
- "HTTP_LISTENER_PORT=" + PORT2 +
- ":HTTP_SSL_LISTENER_PORT=28181:IIOP_SSL_LISTENER_PORT=23800:" +
- "IIOP_LISTENER_PORT=23700:JMX_SYSTEM_CONNECTOR_PORT=27676:IIOP_SSL_MUTUALAUTH_PORT=23801:" +
- "JMS_PROVIDER_PORT=28686:ASADMIN_LISTENER_PORT=24848",
- INSTANCE_NAME_2), "create instance2");
+ assertThat(
+ ASADMIN.exec("create-local-instance", "--cluster", CLUSTER_NAME, "--systemproperties",
+ "HTTP_LISTENER_PORT=" + PORT2
+ + ":HTTP_SSL_LISTENER_PORT=28181"
+ + ":IIOP_SSL_LISTENER_PORT=23800"
+ + ":IIOP_LISTENER_PORT=23700"
+ + ":JMX_SYSTEM_CONNECTOR_PORT=27676"
+ + ":IIOP_SSL_MUTUALAUTH_PORT=23801"
+ + ":JMS_PROVIDER_PORT=28686"
+ + ":ASADMIN_LISTENER_PORT=24848",
+ INSTANCE_NAME_2), asadminOK());
}
+
@Test
@Order(3)
public void startInstancesTest() {
- assertTrue(nadmin("start-local-instance", INSTANCE_NAME_1), "start instance1");
- assertTrue(nadmin("start-local-instance", INSTANCE_NAME_2), "start instance2");
+ assertThat(ASADMIN.exec(30_000, false, "start-local-instance", INSTANCE_NAME_1), asadminOK());
+ assertThat(ASADMIN.exec(30_000, false, "start-local-instance", INSTANCE_NAME_2), asadminOK());
}
@Test
@Order(4)
public void checkClusterTest() {
- assertTrue(nadmin("list-instances"), "list-instances");
+ assertThat(ASADMIN.exec("list-instances"), asadminOK());
assertThat(getURL(URL1), stringContainsInOrder("GlassFish Server"));
assertThat(getURL(URL2), stringContainsInOrder("GlassFish Server"));
}
@@ -93,20 +105,55 @@
@Test
@Order(5)
public void stopInstancesTest() {
- assertTrue(nadmin("stop-local-instance", "--kill", INSTANCE_NAME_1), "stop instance1");
- assertTrue(nadmin("stop-local-instance", "--kill", INSTANCE_NAME_2), "stop instance2");
+ assertThat(ASADMIN.exec("stop-local-instance", "--kill", INSTANCE_NAME_1), asadminOK());
+ assertThat(ASADMIN.exec("stop-local-instance", "--kill", INSTANCE_NAME_2), asadminOK());
}
@Test
@Order(6)
public void deleteInstancesTest() {
- assertTrue(nadmin("delete-local-instance", INSTANCE_NAME_1), "delete instance1");
- assertTrue(nadmin("delete-local-instance", INSTANCE_NAME_2), "delete instance2");
+ assertThat(ASADMIN.exec("delete-local-instance", INSTANCE_NAME_1), asadminOK());
+ assertThat(ASADMIN.exec("delete-local-instance", INSTANCE_NAME_2), asadminOK());
}
@Test
@Order(7)
public void deleteClusterTest() {
- assertTrue(nadmin("delete-cluster", CLUSTER_NAME), "delete cluster");
+ assertThat(ASADMIN.exec("delete-cluster", CLUSTER_NAME), asadminOK());
+ }
+
+
+ /**
+ * This methods opens a connection to the given URL and
+ * returns the string that is returned from that URL. This
+ * is useful for simple servlet retrieval
+ *
+ * @param urlstr The URL to connect to
+ * @return The string returned from that URL, or empty
+ * string if there was a problem contacting the URL
+ */
+ public static String getURL(String urlstr) {
+ URLConnection urlc = openConnection(urlstr);
+ try (
+ BufferedReader ir = new BufferedReader(new InputStreamReader(urlc.getInputStream(), ISO_8859_1));
+ StringWriter ow = new StringWriter();
+ ) {
+ String line;
+ while ((line = ir.readLine()) != null) {
+ ow.write(line);
+ ow.write("\n");
+ }
+ return ow.getBuffer().toString();
+ } catch (IOException ex) {
+ return fail(ex);
+ }
+ }
+
+ private static URLConnection openConnection(String url) {
+ try {
+ return new URL(url).openConnection();
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java
index 97d7e4b..66f27e7 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java
@@ -17,40 +17,47 @@
package org.glassfish.nucleus.admin;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadmin;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
+import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Tom Mueller
*/
-@ExtendWith(DomainLifecycleExtension.class)
@TestMethodOrder(OrderAnnotation.class)
public class MiscCommandsITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
+ @AfterAll
+ public static void startDomainAgain() {
+ assertThat(ASADMIN.exec("start-domain"), asadminOK());
+ }
+
@Test
@Order(1)
public void uptime() {
- assertTrue(nadmin("uptime"));
+ assertThat(ASADMIN.exec("uptime"), asadminOK());
}
@Test
@Order(1)
public void version1() {
- assertTrue(nadmin("version"));
+ assertThat(ASADMIN.exec("version"), asadminOK());
}
@Test
@Order(100)
public void version2() {
- assertTrue(nadmin("stop-domain"));
- assertTrue(nadmin("version", "--local"));
+ assertThat(ASADMIN.exec("stop-domain"), asadminOK());
+ assertThat(ASADMIN.exec("version", "--local"), asadminOK());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java
index fa20972..c7bf5b0 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java
@@ -26,15 +26,13 @@
import java.util.List;
import java.util.Set;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.hamcrest.collection.IsEmptyCollection;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadmin;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -44,12 +42,13 @@
/**
* @author sanjeeb.sahoo@oracle.com
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class OSGiCommandsITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
@Test
public void basicOsgiCmd() {
- assertTrue(nadmin("osgi", "lb"));
+ assertThat(ASADMIN.exec("osgi", "lb"), asadminOK());
}
@@ -103,28 +102,12 @@
try (PrintStream ps = new PrintStream(new FileOutputStream(cmdFile))) {
ps.println("help");
ps.println("lb");
- NucleusTestUtils.NadminReturn value = nadminWithOutput("osgi-shell", "--file", cmdFile.getAbsolutePath());
- assertTrue(value.out.contains("System Bundle"));
+ AsadminResult value = ASADMIN.exec("osgi-shell", "--file", cmdFile.getAbsolutePath());
+ assertTrue(value.getStdOut().contains("System Bundle"));
}
}
- private List<String> runCmd(String... cmd) throws Exception {
- NadminReturn value = nadminWithOutput(cmd);
- if (!value.returnValue) {
- throw new Exception("Cmd failed: \n" + value.outAndErr);
- }
- List<String> output = new ArrayList<>();
- for (String line : value.out.split("\\n")) {
- line = line.trim();
- if (line.isEmpty() || line.startsWith("nadmin") || line.startsWith("Command")) {
- continue;
- }
- output.add(line);
- }
- return output;
- }
-
private String newCmdSession() throws Exception {
List<String> value = runCmd("osgi", "--session", "new");
if (value.size() != 1) {
@@ -137,4 +120,19 @@
List<String> sessions = runCmd("osgi", "--session", "list");
return new HashSet<>(sessions);
}
+
+
+ private List<String> runCmd(String... cmd) throws Exception {
+ AsadminResult value = ASADMIN.exec(cmd);
+ assertThat(value, asadminOK());
+ List<String> output = new ArrayList<>();
+ for (String line : value.getStdOut().split("\\n")) {
+ line = line.trim();
+ if (line.isEmpty() || line.startsWith(ASADMIN.getCommandName()) || line.startsWith("Command")) {
+ continue;
+ }
+ output.add(line);
+ }
+ return output;
+ }
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java
index 9112ad4..700048b 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java
@@ -19,25 +19,20 @@
import java.io.DataOutputStream;
import java.io.IOException;
-import java.net.Authenticator;
import java.net.HttpURLConnection;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.Test;
+
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.openConnection;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
-@ExtendWith(DomainLifecycleExtension.class)
public class RestITest {
@Test
public void testManagementEndpoint() throws Exception {
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain.xml");
+ HttpURLConnection connection = openConnection("/management/domain.xml");
try {
assertEquals(200, connection.getResponseCode());
} finally {
@@ -47,7 +42,7 @@
@Test
public void testMonitoringEndpoint() throws Exception {
- HttpURLConnection connection = getConnection("http://localhost:4848/monitoring/domain.xml");
+ HttpURLConnection connection = openConnection("/monitoring/domain.xml");
try {
assertEquals(200, connection.getResponseCode());
} finally {
@@ -57,7 +52,7 @@
@Test
public void testAdminCommandEndpoint() throws Exception {
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain/version.xml");
+ HttpURLConnection connection = openConnection("/management/domain/version.xml");
try {
assertEquals(200, connection.getResponseCode());
} finally {
@@ -67,7 +62,7 @@
@Test
public void testChildConfigBeanEndpoint() throws Exception {
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain/applications.xml");
+ HttpURLConnection connection = openConnection("/management/domain/applications.xml");
try {
assertEquals(200, connection.getResponseCode());
} finally {
@@ -84,17 +79,9 @@
assertEquals(200, deleteNode());
}
- protected HttpURLConnection getConnection(String url) throws IOException {
- HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
- connection.setRequestProperty("X-GlassFish-3", "true");
- connection.setRequestProperty("X-Requested-By", "dummy");
- connection.setAuthenticator(new DasAuthenticator());
- return connection;
- }
-
private int createNode() throws IOException {
String parameters = "name=myConfigNode";
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain/nodes/create-node-config");
+ HttpURLConnection connection = openConnection("/management/domain/nodes/create-node-config");
try {
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@@ -113,7 +100,7 @@
}
private int getNode() throws IOException {
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain/nodes/node/myConfigNode");
+ HttpURLConnection connection = openConnection("/management/domain/nodes/node/myConfigNode");
try {
return connection.getResponseCode();
} finally {
@@ -122,7 +109,7 @@
}
private int deleteNode() throws IOException {
- HttpURLConnection connection = getConnection("http://localhost:4848/management/domain/nodes/delete-node-config?id=myConfigNode");
+ HttpURLConnection connection = openConnection("/management/domain/nodes/delete-node-config?id=myConfigNode");
try {
connection.setRequestMethod("DELETE");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@@ -132,11 +119,4 @@
connection.disconnect();
}
}
-
- private static class DasAuthenticator extends Authenticator {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(NucleusTestUtils.ADMIN_USER, NucleusTestUtils.ADMIN_PASSWORD.toCharArray());
- }
- }
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java
index c8a89d9..d76d7a8 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java
@@ -29,55 +29,49 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
+import java.util.logging.Level;
+import java.util.logging.Logger;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
-import org.junit.jupiter.api.AfterEach;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteJobsFile;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteOsgiDirectory;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadmin;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.stringContainsInOrder;
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 martinmares
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class DetachAttachITest {
-
- @AfterEach
- public void cleanUp() throws Exception {
- nadmin("stop-domain");
- deleteJobsFile();
- deleteOsgiDirectory();
- nadmin("start-domain");
- }
+ private static final Logger LOG = Logger.getLogger(DetachAttachITest.class.getName());
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
@Test
public void uptimePeriodically() throws Exception {
Set<String> ids = new HashSet<>();
for (int i = 0; i < 3; i++) {
- System.out.println("detachAndAttachUptimePeriodically(): round " + i);
+ LOG.log(Level.FINE, "detachAndAttachUptimePeriodically(): round " + i);
final String id;
{
- NadminReturn result = nadminWithOutput("--detach", "--terse", "uptime");
- assertTrue(result.returnValue);
- id = parseJobIdFromEchoTerse(result.out);
+ AsadminResult result = ASADMIN.execDetached("--terse", "uptime");
+ assertThat(result, asadminOK());
+ id = parseJobIdFromEchoTerse(result.getStdOut());
assertTrue(ids.add(id));
}
Thread.sleep(1000L);
{
- NadminReturn result = nadminWithOutput("--terse", "attach", id);
- assertTrue(result.returnValue);
- assertTrue(result.out.contains("uptime"));
+ AsadminResult result = ASADMIN.exec("--terse", "attach", id);
+ assertThat(result, asadminOK());
+ assertTrue(result.getStdOut().contains("uptime"));
}
}
}
@@ -85,21 +79,20 @@
@Test
public void commandWithProgressStatus() throws Exception {
- NadminReturn result = nadminWithOutput("--detach", "--terse", "progress-custom", "6x1");
- assertTrue(result.returnValue);
- String id = parseJobIdFromEchoTerse(result.out);
+ AsadminResult result = ASADMIN.execDetached("--terse", "progress-custom", "6x1");
+ assertThat(result, asadminOK());
+ String id = parseJobIdFromEchoTerse(result.getStdOut());
Thread.sleep(2000L);
// Now attach running
- result = nadminWithOutput("attach", id);
- assertTrue(result.returnValue);
- assertThat(result.out, stringContainsInOrder("progress-custom"));
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ result = ASADMIN.exec("attach", id);
+ assertThat(result, asadminOK());
+ assertThat(result.getStdOut(), stringContainsInOrder("progress-custom"));
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertFalse(prgs.isEmpty());
- assertTrue(prgs.get(0).getValue() > 0);
+ assertThat(prgs.get(0).getValue(), greaterThan(0));
assertEquals(100, prgs.get(prgs.size() - 1).getValue());
// Now attach finished - must NOT exist - seen progress job is removed
- result = nadminWithOutput("attach", id);
- assertFalse(result.returnValue);
+ assertThat(ASADMIN.exec("attach", id), not(asadminOK()));
}
@@ -113,28 +106,29 @@
return result;
}
});
- NadminReturn result = nadminWithOutput("--detach", "--terse", "progress-custom", "8x1");
- assertTrue(result.returnValue);
- final String id = parseJobIdFromEchoTerse(result.out);
+ AsadminResult result = ASADMIN.execDetached("--terse", "progress-custom", "8x1");
+ assertThat(result, asadminOK());
+ final String id = parseJobIdFromEchoTerse(result.getStdOut());
+ assertNotNull(id, "id");
Thread.sleep(1500L);
final int attachCount = 3;
- Collection<Callable<NadminReturn>> attaches = new ArrayList<>(attachCount);
+ Collection<Callable<AsadminResult>> attaches = new ArrayList<>(attachCount);
for (int i = 0; i < attachCount; i++) {
- attaches.add(new Callable<NadminReturn>() {
+ attaches.add(new Callable<AsadminResult>() {
@Override
- public NadminReturn call() throws Exception {
- return nadminWithOutput("attach", id);
+ public AsadminResult call() throws Exception {
+ return ASADMIN.exec("attach", id);
}
});
}
- List<Future<NadminReturn>> results = pool.invokeAll(attaches);
- for (Future<NadminReturn> fRes : results) {
- NadminReturn res = fRes.get();
- assertTrue(res.returnValue);
- assertTrue(res.out.contains("progress-custom"));
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(res.out);
+ List<Future<AsadminResult>> results = pool.invokeAll(attaches);
+ for (Future<AsadminResult> fRes : results) {
+ AsadminResult res = fRes.get();
+ assertThat(res, asadminOK());
+ assertTrue(res.getStdOut().contains("progress-custom"));
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(res.getStdOut());
assertFalse(prgs.isEmpty());
- assertTrue(prgs.get(0).getValue() > 0);
+ assertThat(prgs.get(0).getValue(), greaterThan(0));
assertEquals(100, prgs.get(prgs.size() - 1).getValue());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java
index 8c5ebfa..00f6088 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java
@@ -17,22 +17,20 @@
package org.glassfish.nucleus.admin.progress;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteJobsFile;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteOsgiDirectory;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadmin;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminDetachWithOutput;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.deleteJobsFile;
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.deleteOsgiDirectory;
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.getAsadmin;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* This tests the functionality of JobManager, list-jobs
@@ -41,67 +39,71 @@
* @author David Matejcek
*/
@TestMethodOrder(OrderAnnotation.class)
-@ExtendWith(DomainLifecycleExtension.class)
public class JobManagerITest {
private static final String COMMAND_PROGRESS_SIMPLE = "progress-simple";
+ private static final Asadmin ASADMIN = getAsadmin();
@BeforeEach
public void setUp() throws Exception {
- nadmin("stop-domain");
+ assertThat(ASADMIN.exec("stop-domain"), asadminOK());
deleteJobsFile();
deleteOsgiDirectory();
- assertTrue(nadmin("start-domain"), "start-domain failed");
+ assertThat(ASADMIN.exec("start-domain"), asadminOK());
}
@Test
@Order(1)
public void noJobsTest() {
- assertThat(nadminWithOutput("list-jobs").outAndErr, stringContainsInOrder("Nothing to list"));
+ AsadminResult result = ASADMIN.exec("list-jobs");
+ assertThat(result, asadminOK());
+ assertThat(result.getOutput(), stringContainsInOrder("Nothing to list"));
}
@Test
@Order(2)
public void jobSurvivesRestart() throws Exception {
- assertTrue(nadminWithOutput("--terse", "progress-simple").returnValue);
- assertThat(nadminWithOutput("list-jobs").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
- assertThat(nadminWithOutput("list-jobs", "1").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
+ assertThat(ASADMIN.exec("--terse", "progress-simple"), asadminOK());
+ assertThat(ASADMIN.exec("list-jobs").getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
+ assertThat(ASADMIN.exec("list-jobs", "1").getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
- assertTrue(nadmin("stop-domain"));
- assertTrue(nadmin("start-domain"));
- assertThat(nadminWithOutput("list-jobs", "1").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
+ assertThat(ASADMIN.exec("stop-domain"), asadminOK());
+ assertThat(ASADMIN.exec("start-domain"), asadminOK());
+ AsadminResult result = ASADMIN.exec("list-jobs", "1");
+ assertThat(result, asadminOK());
+ assertThat(result.getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE, "COMPLETED"));
}
@Test
@Order(3)
public void detachAndAttach() throws Exception {
- assertThat(nadminDetachWithOutput(COMMAND_PROGRESS_SIMPLE).out, stringContainsInOrder("Job ID: "));
- assertThat(nadminWithOutput("list-jobs", "1").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
- assertTrue(nadmin("attach", "1"));
+ assertThat(ASADMIN.execDetached(COMMAND_PROGRESS_SIMPLE).getStdOut(), stringContainsInOrder("Job ID: "));
+ assertThat(ASADMIN.exec("list-jobs", "1").getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
+ assertThat(ASADMIN.exec("attach", "1"), asadminOK());
// list-jobs and it should be purged since the user
// starting is the same as the user who attached to it
- assertThat(nadminWithOutput("list-jobs").outAndErr, stringContainsInOrder("Nothing to list"));
+ assertThat(ASADMIN.exec("list-jobs").getOutput(), stringContainsInOrder("Nothing to list"));
}
@Test
@Order(4)
public void runConfigureManagedJobsTest() throws Exception {
- assertTrue(nadmin("configure-managed-jobs", "--job-retention-period=60s", "--cleanup-initial-delay=1s", "--cleanup-poll-interval=1s"));
- assertTrue(nadmin(COMMAND_PROGRESS_SIMPLE), COMMAND_PROGRESS_SIMPLE + " failed to start");
- assertThat(nadminWithOutput("list-jobs", "1").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
+ assertThat(ASADMIN.exec("configure-managed-jobs", "--job-retention-period=60s", "--cleanup-initial-delay=1s", "--cleanup-poll-interval=1s"), asadminOK());
+ assertThat(ASADMIN.exec(COMMAND_PROGRESS_SIMPLE), asadminOK());
+ assertThat(ASADMIN.exec("list-jobs", "1").getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
// FIXME: Random race condition on Linux caused by some bug in restart-domain; 4848 port is then blocked for start-domain in setUp();
- assertTrue(nadmin("stop-domain"));
- assertTrue(nadmin("start-domain"));
- assertThat(nadminWithOutput("list-jobs", "1").out, stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
+ assertThat(ASADMIN.exec("stop-domain"), asadminOK());
+ assertThat(ASADMIN.exec("start-domain"), asadminOK());
+ assertThat(ASADMIN.exec("list-jobs", "1").getStdOut(), stringContainsInOrder(COMMAND_PROGRESS_SIMPLE));
- assertTrue(nadmin("configure-managed-jobs", "--job-retention-period=1s", "--cleanup-initial-delay=1s", "--cleanup-poll-interval=1s"));
+ assertThat(ASADMIN.exec("configure-managed-jobs", "--job-retention-period=1s", "--cleanup-initial-delay=1s", "--cleanup-poll-interval=1s"), asadminOK());
Thread.sleep(2100L);
- assertThat(nadminWithOutput("list-jobs").outAndErr, stringContainsInOrder("Nothing to list"));
- assertTrue(nadmin("configure-managed-jobs", "--job-retention-period=1h", "--cleanup-initial-delay=5m", "--cleanup-poll-interval=20m"));
+ assertThat(ASADMIN.exec("list-jobs").getOutput(), stringContainsInOrder("Nothing to list"));
+ assertThat(ASADMIN.exec("configure-managed-jobs", "--job-retention-period=1h", "--cleanup-initial-delay=5m", "--cleanup-poll-interval=20m"), asadminOK());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java
index 609c997..6074aa0 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java
@@ -19,13 +19,13 @@
import java.util.List;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.glassfish.nucleus.admin.progress.ProgressMessage.isIncreasing;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -35,14 +35,15 @@
/**
* @author martinmares
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class ProgressStatusBasicITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
@Test
public void simple() {
- NadminReturn result = nadminWithOutput("progress-simple");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-simple");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, isIncreasing());
assertEquals(12, prgs.size());
for (int i = 0; i < 11; i++) {
@@ -53,9 +54,9 @@
@Test
public void simpleNoTotal() {
- NadminReturn result = nadminWithOutput("progress-simple", "--nototalsteps");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-simple", "--nototalsteps");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, isIncreasing());
boolean nonPercentageExists = false;
for (ProgressMessage prg : prgs) {
@@ -69,9 +70,9 @@
@Test
public void simpleSpecInAnnotation() {
- NadminReturn result = nadminWithOutput("progress-full-annotated");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-full-annotated");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, hasSize(12));
assertThat(prgs, isIncreasing());
for (int i = 0; i < 11; i++) {
@@ -83,9 +84,9 @@
@Test
public void simpleTerse() {
- NadminReturn result = nadminWithOutput("--terse", "progress-simple");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("--terse", "progress-simple");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, hasSize(0));
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java
index 069081a..5c0e076 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java
@@ -19,16 +19,15 @@
import java.util.List;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.glassfish.nucleus.admin.progress.ProgressMessage.grepProgressMessages;
import static org.glassfish.nucleus.admin.progress.ProgressMessage.isIncreasing;
import static org.glassfish.nucleus.admin.progress.ProgressMessage.uniqueMessages;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -42,25 +41,26 @@
/**
* @author martinmares
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class ProgressStatusComplexITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
@Test
public void executeCommandFromCommand() {
- NadminReturn result = nadminWithOutput("progress-exec-other");
- assertTrue(result.returnValue);
+ AsadminResult result = ASADMIN.exec(30_000, false, "progress-exec-other");
+ assertThat(result, asadminOK());
assertArrayEquals(new String[] {
"Starting", "Preparing", "Parsing", "Working on main part",
"Cleaning", "Finished", "Finishing outer command", "Finished outer command" },
- uniqueMessages(grepProgressMessages(result.out)));
+ uniqueMessages(grepProgressMessages(result.getStdOut())));
}
@Test
public void executeCommandWithSupplements() {
- NadminReturn result = nadminWithOutput("progress-supplement");
- assertTrue(result.returnValue);
+ AsadminResult result = ASADMIN.exec("progress-supplement");
+ assertThat(result, asadminOK());
- List<ProgressMessage> prgs = grepProgressMessages(result.out);
+ List<ProgressMessage> prgs = grepProgressMessages(result.getStdOut());
assertArrayEquals(new String[] {
"Starting", "2 seconds supplemental command", "Parsing",
"Working on main part", "Finished", "3 seconds supplemental" },
@@ -74,10 +74,10 @@
@Test
public void executeVeryComplexCommand() {
- NucleusTestUtils.NadminReturn result = nadminWithOutput("progress-complex");
- assertTrue(result.returnValue);
+ AsadminResult result = ASADMIN.exec("progress-complex");
+ assertThat(result, asadminOK());
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, hasSize(greaterThanOrEqualTo(100)));
assertThat(prgs, isIncreasing());
assertEquals(5, scopeCount(prgs, "complex:"));
@@ -103,5 +103,4 @@
}
return result;
}
-
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java
index 7d9fe7b..dfd0b1b 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java
@@ -19,35 +19,38 @@
import java.util.List;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* @author martinmares
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class ProgressStatusFailITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
@Test
public void failDuringExecution() {
- NadminReturn result = nadminWithOutput("progress-fail-in-half");
- assertFalse(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-fail-in-half");
+ assertThat(result, not(asadminOK()));
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertFalse(prgs.isEmpty());
assertEquals(50, prgs.get(prgs.size() - 1).getValue());
}
@Test
public void timeout() {
- NadminReturn result = nadminWithOutput(6 * 1000, "progress-custom", "3x1", "1x8", "2x1");
- assertFalse(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec(6_000, false, "progress-custom", "3x1", "1x8", "2x1");
+ assertThat(result, not(asadminOK()));
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertFalse(prgs.isEmpty());
assertEquals(50, prgs.get(prgs.size() - 1).getValue());
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java
index 68573f0..58bd344 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java
@@ -20,13 +20,13 @@
import java.util.Iterator;
import java.util.List;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
import static org.glassfish.nucleus.admin.progress.ProgressMessage.isIncreasing;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
@@ -36,14 +36,15 @@
/**
* @author martinmares
*/
-@ExtendWith(DomainLifecycleExtension.class)
public class ProgressStatusSpecialITest {
+ private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin();
+
@Test
public void stepBackCommand() {
- NadminReturn result = nadminWithOutput("progress-step-back");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-step-back");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, not(isIncreasing()));
Iterator<ProgressMessage> itr = prgs.iterator();
while (itr.hasNext()) {
@@ -67,9 +68,9 @@
@Test
public void doubleTotalCommand() {
- NadminReturn result = nadminWithOutput("progress-double-totals");
- assertTrue(result.returnValue);
- List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.out);
+ AsadminResult result = ASADMIN.exec("progress-double-totals");
+ assertThat(result, asadminOK());
+ List<ProgressMessage> prgs = ProgressMessage.grepProgressMessages(result.getStdOut());
assertThat(prgs, not(isIncreasing()));
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java
index bb91938..19d9bb0 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java
@@ -19,17 +19,13 @@
import jakarta.ws.rs.core.Response;
-import java.io.File;
-import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
-import java.util.logging.Logger;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
import org.glassfish.nucleus.test.webapp.HelloServlet;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -42,46 +38,55 @@
*/
public class ApplicationITest extends RestTestBase {
+
+ private DomainAdminRestClient client;
+ private String appName;
+
+ @BeforeEach
+ public void initInstanceClient() {
+ appName = "testApp" + generateRandomString();
+ client = new DomainAdminRestClient(getBaseInstanceUrl() + "/" + appName);
+ }
+
+ @AfterEach
+ public void closeInstanceClient() {
+ if (client != null) {
+ client.close();
+ }
+ }
+
@Test
public void testApplicationDeployment() throws URISyntaxException {
- final String appName = "testApp" + generateRandomString();
-
try {
Map<String, String> deployedApp = deployApp(getWar("test"), appName, appName);
assertEquals(appName, deployedApp.get("name"));
assertEquals("/" + appName, deployedApp.get("contextRoot"));
- } catch (Exception e) {
- throw new RuntimeException(e);
} finally {
undeployApp(appName);
}
}
+
@Test
public void testApplicationDisableEnable() throws URISyntaxException {
- final String appName = "testApp" + generateRandomString();
-
Map<String, String> deployedApp = deployApp(getWar("test"), appName, appName);
assertEquals(appName, deployedApp.get("name"));
-
assertEquals("/" + appName, deployedApp.get("contextRoot"));
-
try {
- String appUrl = getBaseInstanceUrl() + appName;
- Response response = get(appUrl);
- assertEquals ("Hello!", response.readEntity(String.class));
+ Response response = client.get("");
+ assertEquals("Hello!", response.readEntity(String.class));
- response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/disable");
+ response = managementClient.post(URL_APPLICATION_DEPLOY + "/" + appName + "/disable");
assertThat(response.getStatus(), equalTo(200));
- response = get(appUrl);
+ response = client.get("");
assertEquals(404, response.getStatus());
- response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/enable");
+ response = managementClient.post(URL_APPLICATION_DEPLOY + "/" + appName + "/enable");
assertThat(response.getStatus(), equalTo(200));
- response = get(appUrl);
- assertEquals ("Hello!", response.readEntity(String.class).trim());
+ response = client.get("");
+ assertEquals("Hello!", response.readEntity(String.class).trim());
} finally {
undeployApp(appName);
}
@@ -89,16 +94,16 @@
@Test
public void listSubComponents() throws URISyntaxException {
- final String appName = "testApp" + generateRandomString();
-
try {
deployApp(getEar("simple"), appName, appName);
- Response response = get(URL_APPLICATION_DEPLOY +"/" + appName + "/list-sub-components?id=" + appName);
+ Response response = managementClient
+ .get(URL_APPLICATION_DEPLOY + "/" + appName + "/list-sub-components?id=" + appName);
assertThat(response.getStatus(), equalTo(200));
String subComponents = response.readEntity(String.class);
assertThat(subComponents, stringContainsInOrder("simple"));
- response = get(URL_APPLICATION_DEPLOY +"/" + appName + "/list-sub-components?id=simple.war&appname=" + appName);
+ response = managementClient
+ .get(URL_APPLICATION_DEPLOY + "/" + appName + "/list-sub-components?id=simple.war&appname=" + appName);
assertThat(response.getStatus(), equalTo(200));
subComponents = response.readEntity(String.class);
assertThat(subComponents, stringContainsInOrder(HelloServlet.class.getName()));
@@ -110,30 +115,28 @@
@Test
public void testCreatingAndDeletingApplicationRefs() throws URISyntaxException {
final String instanceName = "instance_" + generateRandomString();
- final String appName = "testApp" + generateRandomString();
- final String appRefUrl = "domain/servers/server/" + instanceName + "/application-ref";
+ final String appRefUrl = "/domain/servers/server/" + instanceName + "/application-ref";
Map<String, String> newInstance = Map.of("id", instanceName, "node", "localhost-domain1");
Map<String, String> applicationRef = Map.of("id", appName, "target", instanceName);
-
try {
- Response response = post(URL_CREATE_INSTANCE, newInstance);
+ Response response = managementClient.post(URL_CREATE_INSTANCE, newInstance);
assertThat(response.getStatus(), equalTo(200));
deployApp(getWar("test"), appName, appName);
- response = post (appRefUrl, applicationRef);
+ response = managementClient.post(appRefUrl, applicationRef);
assertThat(response.getStatus(), equalTo(200));
- response = get(appRefUrl + "/" + appName);
+ response = managementClient.get(appRefUrl + "/" + appName);
assertThat(response.getStatus(), equalTo(200));
- response = delete(appRefUrl + "/" + appName, Map.of("target", instanceName));
+ response = managementClient.delete(appRefUrl + "/" + appName, Map.of("target", instanceName));
assertThat(response.getStatus(), equalTo(200));
} finally {
- Response response = delete("domain/servers/server/" + instanceName + "/delete-instance");
+ Response response = managementClient.delete("/domain/servers/server/" + instanceName + "/delete-instance");
assertThat(response.getStatus(), equalTo(200));
- response = get("domain/servers/server/" + instanceName);
+ response = managementClient.get("/domain/servers/server/" + instanceName);
assertEquals(404, response.getStatus());
undeployApp(appName);
}
@@ -141,43 +144,45 @@
@Test
public void testGetContextRoot() throws URISyntaxException {
- final String appName = "testApp" + generateRandomString();
try {
Map<String, String> deployedApp = deployApp(getEar("simple"), appName, appName);
assertEquals(appName, deployedApp.get("name"));
Map<String, String> contextRootPayload = Map.of("appname", appName, "modulename", "simple");
- Response response = get("domain/applications/application/" + appName + "/get-context-root", contextRootPayload);
+ Response response = managementClient
+ .get("/domain/applications/application/" + appName + "/get-context-root", contextRootPayload);
assertThat(response.getStatus(), equalTo(200));
assertThat(response.readEntity(String.class),
- stringContainsInOrder("command", "_get-context-root AdminCommand", "exit_code", "SUCCESS",
- "--appname", appName, "--modulename", "simple", "method", "GET"));
+ stringContainsInOrder("command", "_get-context-root AdminCommand", "exit_code", "SUCCESS", "--appname",
+ appName, "--modulename", "simple", "method", "GET"));
} finally {
undeployApp(appName);
}
}
+
@Test
public void testUndeploySubActionWarnings() throws URISyntaxException {
- final String appName = "testApp" + generateRandomString();
final String serverName = "in" + generateRandomNumber();
try {
- Response response = post ("domain/create-instance", Map.of("id", serverName, "node", "localhost-domain1"));
+ Response response = managementClient.post("/domain/create-instance",
+ Map.of("id", serverName, "node", "localhost-domain1"));
assertThat(response.getStatus(), equalTo(200));
- response = post("domain/servers/server/" + serverName + "/start-instance");
+ response = managementClient.post("/domain/servers/server/" + serverName + "/start-instance");
assertThat(response.getStatus(), equalTo(200));
deployApp(getWar("test"), appName, appName);
addAppRef(appName, serverName);
- response = post("domain/servers/server/" + serverName + "/stop-instance");
+ response = managementClient.post("/domain/servers/server/" + serverName + "/stop-instance");
assertThat(response.getStatus(), equalTo(200));
- response = delete("domain/applications/application/" + appName, Map.of("target", "domain"));
+ response = managementClient.delete("/domain/applications/application/" + appName,
+ Map.of("target", "domain"));
assertThat(response.readEntity(String.class),
stringContainsInOrder("deleted successfully", "exit_code", "SUCCESS"));
} finally {
- delete("domain/applications/application/" + appName, Map.of("target", "domain"));
+ managementClient.delete("/domain/applications/application/" + appName, Map.of("target", "domain"));
}
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java
index 02033d7..7466a75 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java
@@ -44,17 +44,17 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
public class AuthRealmITest extends RestTestBase {
- private static final String URL_LIST_GROUP_NAMES = "domain/configs/config/server-config/security-service/auth-realm/admin-realm/list-group-names";
- private static final String URL_SUPPORTS_USER_MANAGEMENT = "domain/configs/config/server-config/security-service/auth-realm/admin-realm/supports-user-management";
- private static final String URL_LIST_ADMIN_REALM_USERS = "domain/configs/config/server-config/security-service/auth-realm/admin-realm/list-users";
- private static final String URL_LIST_FILE_USERS = "domain/configs/config/server-config/security-service/auth-realm/file/list-users";
- private static final String URL_CREATE_USER = "domain/configs/config/server-config/security-service/auth-realm/file/create-user";
- private static final String URL_DELETE_USER = "domain/configs/config/server-config/security-service/auth-realm/file/delete-user";
- private static final String URL_AUTH_REALM_CLASS_NAMES = "domain/list-predefined-authrealm-classnames";
+ private static final String URL_LIST_GROUP_NAMES = "/domain/configs/config/server-config/security-service/auth-realm/admin-realm/list-group-names";
+ private static final String URL_SUPPORTS_USER_MANAGEMENT = "/domain/configs/config/server-config/security-service/auth-realm/admin-realm/supports-user-management";
+ private static final String URL_LIST_ADMIN_REALM_USERS = "/domain/configs/config/server-config/security-service/auth-realm/admin-realm/list-users";
+ private static final String URL_LIST_FILE_USERS = "/domain/configs/config/server-config/security-service/auth-realm/file/list-users";
+ private static final String URL_CREATE_USER = "/domain/configs/config/server-config/security-service/auth-realm/file/create-user";
+ private static final String URL_DELETE_USER = "/domain/configs/config/server-config/security-service/auth-realm/file/delete-user";
+ private static final String URL_AUTH_REALM_CLASS_NAMES = "/domain/list-predefined-authrealm-classnames";
@Test
public void testListGroupNames() {
- Response response = get(URL_LIST_GROUP_NAMES, Map.of("userName", "admin", "realmName", "admin-realm"));
+ Response response = managementClient.get(URL_LIST_GROUP_NAMES, Map.of("userName", "admin", "realmName", "admin-realm"));
assertEquals(200, response.getStatus());
final String entity = response.readEntity(String.class);
Map responseMap = MarshallingUtils.buildMapFromDocument(entity);
@@ -65,7 +65,7 @@
@Test
public void testListAdminUsers() {
- Response response = get(URL_LIST_ADMIN_REALM_USERS);
+ Response response = managementClient.get(URL_LIST_ADMIN_REALM_USERS);
assertEquals(200, response.getStatus());
final String entity = response.readEntity(String.class);
Map<String, ?> responseMap = MarshallingUtils.buildMapFromDocument(entity);
@@ -82,7 +82,7 @@
@Test
public void testSupportsUserManagement() {
- List<String> groups = getCommandResults(get(URL_SUPPORTS_USER_MANAGEMENT));
+ List<String> groups = getCommandResults(managementClient.get(URL_SUPPORTS_USER_MANAGEMENT));
assertEquals("true", groups.get(0));
}
@@ -91,19 +91,19 @@
public void testUserManagement() {
final String userName = "user" + generateRandomString();
{
- Response response = post(URL_CREATE_USER, Map.of("id", userName, "AS_ADMIN_USERPASSWORD", "password"));
+ Response response = managementClient.post(URL_CREATE_USER, Map.of("id", userName, "AS_ADMIN_USERPASSWORD", "password"));
assertEquals(200, response.getStatus());
}
{
- List<String> values = getCommandResults(get(URL_LIST_FILE_USERS));
+ List<String> values = getCommandResults(managementClient.get(URL_LIST_FILE_USERS));
assertThat(values, hasItem(userName));
}
{
- Response response = delete(URL_DELETE_USER, Map.of("id", userName));
+ Response response = managementClient.delete(URL_DELETE_USER, Map.of("id", userName));
assertEquals(200, response.getStatus());
}
{
- List<String> values = getCommandResults(get(URL_LIST_FILE_USERS));
+ List<String> values = getCommandResults(managementClient.get(URL_LIST_FILE_USERS));
assertThat(values, not(hasItem(userName)));
}
}
@@ -111,7 +111,7 @@
@Test
public void testListAuthRealmClassNames() {
- List<String> classNameList = getCommandResults(get(URL_AUTH_REALM_CLASS_NAMES));
+ List<String> classNameList = getCommandResults(managementClient.get(URL_AUTH_REALM_CLASS_NAMES));
assertThat(classNameList.toString(), classNameList, hasSize(6));
String[] realms = Stream.of(JDBCRealm.class, PamRealm.class, CertificateRealm.class, FileRealm.class,
LDAPRealm.class, SolarisRealm.class).map(Class::getName).toArray(String[]::new);
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java
index 68a72f6..062970c 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java
@@ -37,7 +37,7 @@
final String clusterName = "cluster_" + generateRandomString();
createCluster(clusterName);
- Map<String, String> entity = getEntityValues(get(URL_CLUSTER + "/" + clusterName));
+ Map<String, String> entity = getEntityValues(managementClient.get(URL_CLUSTER + "/" + clusterName));
assertEquals(clusterName + "-config", entity.get("configRef"));
deleteCluster(clusterName);
@@ -46,16 +46,16 @@
@Test
public void testListLifecycleModules() {
final String clusterName = "cluster_" + generateRandomString();
- Response response = post(URL_CLUSTER, Map.of("id", clusterName));
+ Response response = managementClient.post(URL_CLUSTER, Map.of("id", clusterName));
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_CLUSTER + "/" + clusterName + "/list-lifecycle-modules");
+ response = managementClient.get(URL_CLUSTER + "/" + clusterName + "/list-lifecycle-modules");
assertThat(response.getStatus(), equalTo(200));
- response = delete(URL_CLUSTER + "/" + clusterName);
+ response = managementClient.delete(URL_CLUSTER + "/" + clusterName);
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_CLUSTER + "/" + clusterName);
+ response = managementClient.get(URL_CLUSTER + "/" + clusterName);
assertEquals(404, response.getStatus());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java
index 4f9cb1f..8d82383 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java
@@ -45,7 +45,7 @@
MultivaluedHashMap<String, String> formData = new MultivaluedHashMap<>();
formData.add("id", "default-config");
formData.add("id", "server-config");
- Response response = post(URL_CONFIGS + "/copy-config", formData);
+ Response response = managementClient.post(URL_CONFIGS + "/copy-config", formData);
// FIXME: causes HTTP 500 without any log, should be 422.
assertThat(response.getStatus(), equalTo(500));
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java
index 532094e..dcda4de 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java
@@ -33,9 +33,11 @@
public class DomainITest extends RestTestBase {
+ private static final String URL_DOMAIN = "/domain";
+
@Test
public void testDomainGet() throws Exception {
- Response response0 = get("domain");
+ Response response0 = managementClient.get(URL_DOMAIN);
assertThat(response0.getStatus(), equalTo(200));
Map<String, String> current = getEntityValues(response0);
@@ -47,11 +49,11 @@
Map<String, String> payload = new HashMap<>();
payload.put("locale", newLocale);
- Response response = post("domain", payload);
+ Response response = managementClient.post(URL_DOMAIN, payload);
assertEquals(200, response.getStatus());
// Reload the domain and make sure our new locale was saved
- Map<String, String> map = getEntityValues(this.get("domain"));
+ Map<String, String> map = getEntityValues(managementClient.get(URL_DOMAIN));
assertEquals(newLocale, map.get("locale"));
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java
index c10e9a1..6c83feb 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java
@@ -37,7 +37,7 @@
* @author jasonlee
*/
public class ElementStarITest extends RestTestBase {
- private static final String URL_CREATE_INSTANCE = "domain/create-instance";
+ private static final String URL_CREATE_INSTANCE = "/domain/create-instance";
private String instanceName1;
private String instanceName2;
@@ -47,20 +47,23 @@
instanceName1 = "instance_" + generateRandomString();
instanceName2 = "instance_" + generateRandomString();
- Response response = post(URL_CREATE_INSTANCE, Map.of("id", instanceName1, "node", "localhost-domain1"));
+ Response response = managementClient.post(URL_CREATE_INSTANCE,
+ Map.of("id", instanceName1, "node", "localhost-domain1"));
assertThat(response.getStatus(), equalTo(200));
- response = post(URL_CREATE_INSTANCE, Map.of("id", instanceName2, "node", "localhost-domain1"));
+ response = managementClient.post(URL_CREATE_INSTANCE, Map.of("id", instanceName2, "node", "localhost-domain1"));
assertEquals(200, response.getStatus());
}
+
@AfterEach
public void after() {
- Response response = delete("domain/servers/server/" + instanceName1 + "/delete-instance");
+ Response response = managementClient.delete("/domain/servers/server/" + instanceName1 + "/delete-instance");
assertEquals(200, response.getStatus());
- response = delete("domain/servers/server/" + instanceName2 + "/delete-instance");
+ response = managementClient.delete("/domain/servers/server/" + instanceName2 + "/delete-instance");
assertEquals(200, response.getStatus());
}
+
@Test
public void testApplications() throws URISyntaxException {
final String app1 = "app" + generateRandomString();
@@ -71,29 +74,33 @@
addAppRef(app1, instanceName1);
addAppRef(app2, instanceName1);
- Response response = get("domain/servers/server/" + instanceName1 + "/application-ref");
+ Response response = managementClient.get("/domain/servers/server/" + instanceName1 + "/application-ref");
Map<String, String> children = this.getChildResources(response);
assertThat(children, aMapWithSize(2));
}
+
@Test
public void testResources() {
// The DAS should already have two resource-refs (jdbc/__TimerPool and jdbc/__default)
- Response response = get ("domain/servers/server/server/resource-ref");
+ Response response = managementClient.get("/domain/servers/server/server/resource-ref");
Map<String, String> children = this.getChildResources(response);
assertThat(children, aMapWithSize(7));
}
+
@Test
public void testLoadBalancerConfigs() {
final String lbName = "lbconfig-" + generateRandomString();
- Response response = post("domain/lb-configs/lb-config/", Map.of("id", lbName, "target", instanceName1));
+ Response response = managementClient.post("/domain/lb-configs/lb-config/",
+ Map.of("id", lbName, "target", instanceName1));
assertEquals(200, response.getStatus());
- response = post("domain/lb-configs/lb-config/" + lbName + "/create-http-lb-ref", Map.of("id", instanceName2));
+ response = managementClient.post("/domain/lb-configs/lb-config/" + lbName + "/create-http-lb-ref",
+ Map.of("id", instanceName2));
assertEquals(200, response.getStatus());
- response = get ("domain/lb-configs/lb-config/" + lbName + "/server-ref");
+ response = managementClient.get("/domain/lb-configs/lb-config/" + lbName + "/server-ref");
Map<String, String> children = getChildResources(response);
assertThat(children, aMapWithSize(1));
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java
index be1425e..2128d65 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java
@@ -31,7 +31,7 @@
*/
public class ExternalResourceITest extends RestTestBase {
- private static final String URL_EXTERNAL_RESOURCE = "domain/resources/external-jndi-resource";
+ private static final String URL_EXTERNAL_RESOURCE = "/domain/resources/external-jndi-resource";
@Test
public void createAndDeleteExternalResource() {
@@ -43,13 +43,13 @@
"factoryClass", "org.glassfish.resources.custom.factory.PrimitivesAndStringFactory",
"restype", Double.class.getName()
);
- Response response = post(URL_EXTERNAL_RESOURCE, newResource);
+ Response response = managementClient.post(URL_EXTERNAL_RESOURCE, newResource);
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_EXTERNAL_RESOURCE + "/" + resourceName);
+ response = managementClient.get(URL_EXTERNAL_RESOURCE + "/" + resourceName);
assertThat(response.getStatus(), equalTo(200));
- response = delete(URL_EXTERNAL_RESOURCE + "/" + resourceName);
+ response = managementClient.delete(URL_EXTERNAL_RESOURCE + "/" + resourceName);
assertThat(response.getStatus(), equalTo(200));
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java
index 4cb903e..090f918 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java
@@ -38,7 +38,7 @@
@Test
public void testReadingPoolEntity() {
- Map<String, String> entity = getEntityValues(get(URL_JDBC_CONNECTION_POOL + "/__TimerPool"));
+ Map<String, String> entity = getEntityValues(managementClient.get(URL_JDBC_CONNECTION_POOL + "/__TimerPool"));
assertEquals("__TimerPool", entity.get("name"));
}
@@ -49,16 +49,16 @@
Map<String, String> params = new HashMap<>();
params.put("name", poolName);
params.put("datasourceClassname", "org.apache.derby.jdbc.ClientDataSource");
- Response response = post(URL_JDBC_CONNECTION_POOL, params);
+ Response response = managementClient.post(URL_JDBC_CONNECTION_POOL, params);
assertEquals(200, response.getStatus());
- Map<String, String> entity = getEntityValues(get(URL_JDBC_CONNECTION_POOL + "/" + poolName));
+ Map<String, String> entity = getEntityValues(managementClient.get(URL_JDBC_CONNECTION_POOL + "/" + poolName));
assertThat(entity, aMapWithSize(greaterThan(40)));
- response = delete(URL_JDBC_CONNECTION_POOL + "/" + poolName, Map.of());
+ response = managementClient.delete(URL_JDBC_CONNECTION_POOL + "/" + poolName, Map.of());
assertEquals(200, response.getStatus());
- response = get(URL_JDBC_CONNECTION_POOL + "/" + poolName);
+ response = managementClient.get(URL_JDBC_CONNECTION_POOL + "/" + poolName);
assertEquals(404, response.getStatus());
}
@@ -71,18 +71,18 @@
params.put("name", poolName);
params.put("poolName", "DerbyPool");
- Response response = post(URL_JDBC_RESOURCE, params);
+ Response response = managementClient.post(URL_JDBC_RESOURCE, params);
assertEquals(500, response.getStatus());
- Response responseGet = get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName);
+ Response responseGet = managementClient.get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName);
assertEquals(500, response.getStatus());
Map<String, String> entity = getEntityValues(responseGet);
assertNull(entity);
- response = delete("/" + encodedPoolName, Map.of());
+ response = managementClient.delete("/" + encodedPoolName, Map.of());
assertEquals(500, response.getStatus());
- response = get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName);
+ response = managementClient.get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName);
assertEquals(500, response.getStatus());
}
@@ -91,7 +91,7 @@
public void createDuplicateResource() {
final String resourceName = "jdbc/__default";
Map<String, String> params = Map.of("id", resourceName, "poolName", "DerbyPool");
- Response response = post(URL_JDBC_RESOURCE, params);
+ Response response = managementClient.post(URL_JDBC_RESOURCE, params);
assertEquals(500, response.getStatus());
}
@@ -101,7 +101,7 @@
final String poolName = "DerbyPool";
Map<String, String> params = Map.of("id", poolName, "datasourceClassname",
"org.apache.derby.jdbc.ClientDataSource");
- Response response = post(URL_JDBC_CONNECTION_POOL, params);
+ Response response = managementClient.post(URL_JDBC_CONNECTION_POOL, params);
assertEquals(500, response.getStatus());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java
index 748ac67..1757b0e 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java
@@ -33,18 +33,17 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author jasonlee
* @since May 26, 2010
*/
public class JmsITest extends RestTestBase {
- static final String URL_ADMIN_OBJECT_RESOURCE = "domain/resources/admin-object-resource";
- static final String URL_CONNECTOR_CONNECTION_POOL = "domain/resources/connector-connection-pool";
- static final String URL_CONNECTOR_RESOURCE = "domain/resources/connector-resource";
- static final String URL_JMS_HOST = "domain/configs/config/server-config/jms-service/jms-host";
- static final String URL_SEVER_JMS_DEST = "domain/servers/server/server";
+ static final String URL_ADMIN_OBJECT_RESOURCE = "/domain/resources/admin-object-resource";
+ static final String URL_CONNECTOR_CONNECTION_POOL = "/domain/resources/connector-connection-pool";
+ static final String URL_CONNECTOR_RESOURCE = "/domain/resources/connector-resource";
+ static final String URL_JMS_HOST = "/domain/configs/config/server-config/jms-service/jms-host";
+ static final String URL_SEVER_JMS_DEST = "/domain/servers/server/server";
static final String DEST_TYPE = "topic";
@Test
@@ -53,39 +52,39 @@
final String poolName = "JmsConnectionFactory" + generateRandomString();
Map<String, String> ccp_attrs = Map.of("name", poolName, "connectiondefinition",
"jakarta.jms.ConnectionFactory", "raname", "jmsra");
- Response response = post(URL_CONNECTOR_CONNECTION_POOL, ccp_attrs);
+ Response response = managementClient.post(URL_CONNECTOR_CONNECTION_POOL, ccp_attrs);
assertThat(response.getStatus(), equalTo(200));
// Check connection pool creation
- Map<String, String> pool = getEntityValues(get(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName));
+ Map<String, String> pool = getEntityValues(managementClient.get(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName));
assertThat(pool, aMapWithSize(greaterThanOrEqualTo(26)));
// Create connector resource
String resourceName = poolName + "Resource";
Map<String, String> cr_attrs = Map.of("name", resourceName, "poolname", poolName);
- response = post(URL_CONNECTOR_RESOURCE, cr_attrs);
+ response = managementClient.post(URL_CONNECTOR_RESOURCE, cr_attrs);
assertThat(response.getStatus(), equalTo(200));
// Check connector resource
- Map<String, String> resource = getEntityValues(get(URL_CONNECTOR_RESOURCE + "/" + resourceName));
+ Map<String, String> resource = getEntityValues(managementClient.get(URL_CONNECTOR_RESOURCE + "/" + resourceName));
assertThat(resource, aMapWithSize(6));
// Edit and check ccp
- response = post(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, Map.of("description", poolName));
+ response = managementClient.post(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, Map.of("description", poolName));
assertThat(response.getStatus(), equalTo(200));
- pool = getEntityValues(get(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName));
- assertTrue(pool.get("description").equals(poolName));
+ pool = getEntityValues(managementClient.get(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName));
+ assertThat(pool.get("description"), equalTo(poolName));
// Edit and check cr
- response = post(URL_CONNECTOR_RESOURCE + "/" + resourceName, Map.of("description", poolName));
+ response = managementClient.post(URL_CONNECTOR_RESOURCE + "/" + resourceName, Map.of("description", poolName));
assertThat(response.getStatus(), equalTo(200));
- resource = getEntityValues(get(URL_CONNECTOR_RESOURCE + "/" + resourceName));
- assertTrue(pool.get("description").equals(poolName));
+ resource = getEntityValues(managementClient.get(URL_CONNECTOR_RESOURCE + "/" + resourceName));
+ assertThat(pool.get("description"), equalTo(poolName));
// Delete objects
- response = delete(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, Map.of("cascade", "true"));
+ response = managementClient.delete(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, Map.of("cascade", "true"));
assertThat(response.getStatus(), equalTo(200));
}
@@ -96,13 +95,14 @@
Map<String, String> attrs = Map.of("id", jndiName, "raname", "jmsra", "restype", "jakarta.jms.Topic");
- Response response = post(URL_ADMIN_OBJECT_RESOURCE, attrs);
+ Response response = managementClient.post(URL_ADMIN_OBJECT_RESOURCE, attrs);
assertThat(response.getStatus(), equalTo(200));
- Map<String, String> entity = getEntityValues(get(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName));
+ Map<String, String> entity = getEntityValues(
+ managementClient.get(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName));
assertThat(entity, aMapWithSize(8));
- response = delete(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName);
+ response = managementClient.delete(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName);
assertThat(response.getStatus(), equalTo(200));
}
@@ -118,12 +118,12 @@
Map<String, String> destProps = new HashMap<>(newDest);
destProps.putAll(Map.of("property", "MaxNumMsgs=" + maxNumMsgs + ":ConsumerFlowLimit=" + consumerFlowLimit));
- Response response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
+ Response response = managementClient.get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
- response = post(URL_SEVER_JMS_DEST + "/__update-jmsdest", destProps);
+ response = managementClient.post(URL_SEVER_JMS_DEST + "/__update-jmsdest", destProps);
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
+ response = managementClient.get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
Map<String, String> entity = getEntityValues(response);
assertEquals(maxNumMsgs, entity.get("MaxNumMsgs"));
@@ -140,14 +140,14 @@
final String clusterName = createCluster();
createClusterInstance(clusterName, "in1_" + clusterName);
startCluster(clusterName);
- final String endpoint = "domain/clusters/cluster/" + clusterName;
+ final String endpoint = "/domain/clusters/cluster/" + clusterName;
try {
createJmsPhysicalDestination(destName, "topic", endpoint);
final Map<String, String> newDest = Map.of("id", destName, "desttype", DEST_TYPE);
- Response response = get(endpoint + "/__get-jmsdest", newDest);
+ Response response = managementClient.get(endpoint + "/__get-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
+ response = managementClient.get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
} finally {
deleteJmsPhysicalDestination(destName, endpoint);
@@ -158,14 +158,14 @@
@Test
public void testJmsPing() {
- String results = get(URL_SEVER_JMS_DEST + "/jms-ping").readEntity(String.class);
+ String results = managementClient.get(URL_SEVER_JMS_DEST + "/jms-ping").readEntity(String.class);
assertThat(results, stringContainsInOrder("JMS-ping command executed successfully"));
}
@Test
public void testJmsFlush() {
Map<String, String> payload = Map.of("id", "mq.sys.dmq", "destType", "queue");
- Response response = post(URL_SEVER_JMS_DEST + "/flush-jmsdest", payload);
+ Response response = managementClient.post(URL_SEVER_JMS_DEST + "/flush-jmsdest", payload);
assertThat(response.getStatus(), equalTo(200));
}
@@ -176,36 +176,36 @@
"adminUserName", "admin", "host", "localhost");
// Test create
- Response response = post(URL_JMS_HOST, newHost);
+ Response response = managementClient.post(URL_JMS_HOST, newHost);
assertThat(response.getStatus(), equalTo(200));
// Test edit
- Map<String, String> entity = getEntityValues(get(URL_JMS_HOST + "/" + jmsHostName));
+ Map<String, String> entity = getEntityValues(managementClient.get(URL_JMS_HOST + "/" + jmsHostName));
assertThat(entity, aMapWithSize(greaterThanOrEqualTo(6)));
assertEquals(jmsHostName, entity.get("name"));
entity.put("port", "8686");
- response = post(URL_JMS_HOST + "/" + jmsHostName, entity);
+ response = managementClient.post(URL_JMS_HOST + "/" + jmsHostName, entity);
assertThat(response.getStatus(), equalTo(200));
- entity = getEntityValues(get(URL_JMS_HOST + "/" + jmsHostName));
+ entity = getEntityValues(managementClient.get(URL_JMS_HOST + "/" + jmsHostName));
assertEquals("8686", entity.get("port"));
// Test delete
- response = delete(URL_JMS_HOST + "/" + jmsHostName);
+ response = managementClient.delete(URL_JMS_HOST + "/" + jmsHostName);
assertThat(response.getStatus(), equalTo(200));
}
public void createJmsPhysicalDestination(final String destName, final String type, final String endpoint) {
final Map<String, String> newDest = Map.of("id", destName, "desttype", type);
- Response response = post(endpoint + "/create-jmsdest", newDest);
+ Response response = managementClient.post(endpoint + "/create-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
}
public void deleteJmsPhysicalDestination(final String destName, final String endpoint) {
final Map<String, String> newDest = Map.of("id", destName, "desttype", DEST_TYPE);
- Response response = delete(endpoint + "/delete-jmsdest", newDest);
+ Response response = managementClient.delete(endpoint + "/delete-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(200));
- response = get(endpoint + "__get-jmsdest", newDest);
+ response = managementClient.get(endpoint + "__get-jmsdest", newDest);
assertThat(response.getStatus(), equalTo(404));
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java
index c56b008..246b3d5 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java
@@ -20,11 +20,15 @@
import jakarta.ws.rs.core.Response;
import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput;
+import static org.glassfish.nucleus.test.tool.AsadminResultMatcher.asadminOK;
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.getAsadmin;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -35,20 +39,41 @@
* @author jdlee
*/
public class JobsResourceITest extends RestTestBase {
- public static final String URL_JOBS = "jobs";
+
+ private static final String GF_JSON_TYPE = "application/vnd.oracle.glassfish+json";
+ private static final String URL_JOBS = "/jobs";
+
+ private DomainAdminRestClient client;
+ private String jobId;
+
+ @BeforeEach
+ public void initInstanceClient() {
+ client = new DomainAdminRestClient(getBaseAdminUrl() + "/management", GF_JSON_TYPE);
+ }
+
+
+ @AfterEach
+ public void closeInstanceClient() {
+ if (jobId != null) {
+ GlassFishTestEnvironment.getAsadmin().exec("attach", jobId);
+ }
+ if (client != null) {
+ client.close();
+ }
+ }
@Test
public void testJobsListing() {
- assertEquals(200, get(URL_JOBS).getStatus());
+ assertEquals(200, client.get(URL_JOBS).getStatus());
}
@Test
public void testGetJob() throws Exception {
// make sure we have at least one detached job
- nadminWithOutput("--detach", "uptime");
+ assertThat(getAsadmin().exec("--detach", "uptime"), asadminOK());
// verify getting the collection
- Response response = get(URL_JOBS);
+ Response response = client.get(URL_JOBS);
assertEquals(200, response.getStatus());
// verify the overall structure
@@ -56,6 +81,7 @@
JSONArray resources = json.getJSONArray("resources");
assertNotNull(resources);
assertThat(resources.length(), equalTo(1));
+
JSONArray items = json.getJSONArray("items");
assertNotNull(items);
assertThat(items.length(), equalTo(1));
@@ -67,21 +93,27 @@
String uri = resource.getString("uri");
assertNotNull(uri);
assertEquals("job", resource.getString("rel"));
- String jobId = resource.getString("title");
+
+ jobId = resource.getString("title");
assertNotNull(jobId);
assertThat(uri, endsWith(URL_JOBS + "/id/" + jobId));
// verify the job it refers to by following the link.
// it should only have a parent link
- response = get(uri);
- assertEquals(200, response.getStatus());
- json = response.readEntity(JSONObject.class);
+ try (GenericClient genericClient = new GenericClient()) {
+ response = genericClient.get(uri);
+ assertThat(response.getStatus(), equalTo(200));
+ json = response.readEntity(JSONObject.class);
+ }
JSONObject item = json.getJSONObject("item");
System.out.println(item.toString());
- verifyItem(jobId, item);
+ assertNotNull(item);
+ assertEquals(jobId, item.getString("jobId"));
+
resources = json.getJSONArray("resources");
assertNotNull(resources);
assertThat(resources.length(), equalTo(1));
+
resource = resources.getJSONObject(0);
assertEquals("parent", resource.getString("rel"));
assertThat(resource.getString("uri"), endsWith(URL_JOBS));
@@ -94,16 +126,14 @@
item = thisItem;
}
}
- verifyItem(jobId, item);
+ assertNotNull(item);
+ assertEquals(jobId, item.getString("jobId"));
}
- private void verifyItem(String expectedJobId, JSONObject jobJsonObject) throws JSONException {
- assertNotNull(jobJsonObject);
- assertEquals(expectedJobId, jobJsonObject.getString("jobId"));
- }
- @Override
- protected String getResponseType() {
- return "application/vnd.oracle.glassfish+json";
+ private static class GenericClient extends DomainAdminRestClient {
+ public GenericClient() {
+ super(GlassFishTestEnvironment.createClient(), "", GF_JSON_TYPE);
+ }
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java
index 24e0260..18beffe 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java
@@ -21,7 +21,6 @@
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -31,27 +30,29 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
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 jasonlee
*/
public class JvmOptionsITest extends RestTestBase {
- private static final String URL_SERVER_JVM_OPTIONS = "domain/configs/config/server-config/java-config/jvm-options";
- private static final String URL_DEFAULT_JVM_OPTIONS = "domain/configs/config/default-config/java-config/jvm-options";
+ private static final String URL_SERVER_JVM_OPTIONS = "/domain/configs/config/server-config/java-config/jvm-options";
+ private static final String URL_DEFAULT_JVM_OPTIONS = "/domain/configs/config/default-config/java-config/jvm-options";
- private static final String URL_SERVER_CONFIG_CREATE_PROFILER = "domain/configs/config/server-config/java-config/create-profiler";
- private static final String URL_SERVER_CONFIG_DELETE_PROFILER = "domain/configs/config/server-config/java-config/profiler/delete-profiler";
+ private static final String URL_SERVER_CONFIG_CREATE_PROFILER = "/domain/configs/config/server-config/java-config/create-profiler";
+ private static final String URL_SERVER_CONFIG_DELETE_PROFILER = "/domain/configs/config/server-config/java-config/profiler/delete-profiler";
private static final String URL_SERVER_CONFIG_PROFILER_JVM_OPTIONS = "/domain/configs/config/server-config/java-config/profiler/jvm-options";
- private static final String URL_DEFAULT_CONFIG_CREATE_PROFILER = "domain/configs/config/default-config/java-config/create-profiler";
- private static final String URL_DEFAULT_CONFIG_DELETE_PROFILER = "domain/configs/config/default-config/java-config/profiler/delete-profiler";
- private static final String URL_DEFAULT_CONFIG_PROFILER_JVM_OPTIONS = "domain/configs/config/default-config/java-config/profiler/jvm-options";
+ private static final String URL_DEFAULT_CONFIG_CREATE_PROFILER = "/domain/configs/config/default-config/java-config/create-profiler";
+ private static final String URL_DEFAULT_CONFIG_DELETE_PROFILER = "/domain/configs/config/default-config/java-config/profiler/delete-profiler";
+ private static final String URL_DEFAULT_CONFIG_PROFILER_JVM_OPTIONS = "/domain/configs/config/default-config/java-config/profiler/jvm-options";
private static RestTestBase configManagement;
private String testConfigName;
@@ -71,7 +72,7 @@
add("id", testConfigName);
}};
configManagement.createAndVerifyConfig(testConfigName, formData);
- testConfigUrl = "domain/configs/config/" + testConfigName;
+ testConfigUrl = "/domain/configs/config/" + testConfigName;
testConfigJvmOptionsUrl = testConfigUrl + "/java-config/jvm-options";
}
@@ -83,7 +84,7 @@
@Test
public void getJvmOptions() {
- Response response = get(URL_SERVER_JVM_OPTIONS);
+ Response response = managementClient.get(URL_SERVER_JVM_OPTIONS);
assertEquals(200, response.getStatus());
Map<String, ?> responseMap = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
List<String> jvmOptions = (List<String>)((Map)responseMap.get("extraProperties")).get("leafList");
@@ -93,90 +94,75 @@
@Test
public void createAndDeleteOptions() {
final String option1Name = "-Doption" + generateRandomString();
- Map<String, String> newOptions = new HashMap<>() {{
- put(option1Name, "someValue");
- }};
+ Map<String, String> newOptions = Map.of(option1Name, "someValue");
- Response response = post(testConfigJvmOptionsUrl, newOptions);
+ Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(option1Name+"=someValue"));
+ assertThat(jvmOptions, hasItem(option1Name + "=someValue"));
- response = delete(testConfigJvmOptionsUrl, newOptions);
+ response = managementClient.delete(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
jvmOptions = getJvmOptions(response);
- assertFalse(jvmOptions.contains(option1Name+"=someValue"));
+ assertThat(jvmOptions, not(hasItem(option1Name + "=someValue")));
}
@Test
public void createAndDeleteOptionsWithBackslashes() {
final String optionName = "-Dfile" + generateRandomString();
final String optionValue = "C:\\ABC\\DEF\\";
- Map<String, String> newOptions = new HashMap<>() {{
- put(optionName, escape(optionValue));
- }};
+ Map<String, String> newOptions = Map.of(optionName, escape(optionValue));
- Response response = post(testConfigJvmOptionsUrl, newOptions);
+ Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(optionName+"="+optionValue));
+ assertThat(jvmOptions, hasItem(optionName + "=" + optionValue));
- response = delete(testConfigJvmOptionsUrl, newOptions);
+ response = managementClient.delete(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
jvmOptions = getJvmOptions(response);
- assertFalse(jvmOptions.contains(optionName+"="+optionValue));
+ assertThat(jvmOptions, not(hasItem(optionName + "=" + optionValue)));
}
@Test
public void createAndDeleteOptionsWithoutValues() {
final String option1Name = "-Doption" + generateRandomString();
final String option2Name = "-Doption" + generateRandomString();
- Map<String, String> newOptions = new HashMap<>() {{
- put(option1Name, "");
- put(option2Name, "");
- }};
-
- Response response = post(testConfigJvmOptionsUrl, newOptions);
+ Map<String, String> newOptions = Map.of(option1Name, "", option2Name, "");
+ Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(option1Name));
- assertFalse(jvmOptions.contains(option1Name+"="));
- assertTrue(jvmOptions.contains(option2Name));
- assertFalse(jvmOptions.contains(option2Name+"="));
+ assertThat(jvmOptions, hasItems(option2Name, option2Name));
+ assertThat(jvmOptions, not(hasItems(option1Name + '=', option2Name + '=')));
- response = delete(testConfigJvmOptionsUrl, newOptions);
+ response = managementClient.delete(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
jvmOptions = getJvmOptions(response);
- assertFalse(jvmOptions.contains(option1Name));
- assertFalse(jvmOptions.contains(option2Name));
+ assertThat(jvmOptions, allOf(not(hasItem(option1Name)), not(hasItem(option2Name))));
}
@Test
public void testIsolatedOptionsCreationOnNewConfig() {
final String optionName = "-Doption" + generateRandomString();
-
- Map<String, String> newOptions = new HashMap<>() {{
- put(optionName, "");
- put("target", testConfigName);
- }};
+ Map<String, String> newOptions = Map.of(optionName, "", "target", testConfigName);
// Test new config to make sure option is there
- Response response = post(testConfigJvmOptionsUrl, newOptions);
+ Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(optionName));
+ assertThat(jvmOptions, hasItem(optionName));
// Test server-config to make sure the options are NOT there
- response = get(URL_SERVER_JVM_OPTIONS);
+ response = managementClient.get(URL_SERVER_JVM_OPTIONS);
jvmOptions = getJvmOptions(response);
- assertFalse(jvmOptions.contains(optionName));
+ assertThat(jvmOptions, not(hasItem(optionName)));
}
@Test
@@ -187,15 +173,15 @@
Map<String, String> newOptions = Map.of(optionName, "");
deleteProfiler(testConfigUrl + "/java-config/profiler/delete-profiler", testConfigName, false);
- Response response = post(testConfigUrl + "/java-config/create-profiler", attrs);
+ Response response = managementClient.post(testConfigUrl + "/java-config/create-profiler", attrs);
assertEquals(200, response.getStatus());
- response = post(testConfigUrl + "/java-config/profiler/jvm-options", newOptions);
+ response = managementClient.post(testConfigUrl + "/java-config/profiler/jvm-options", newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigUrl + "/java-config/profiler/jvm-options");
+ response = managementClient.get(testConfigUrl + "/java-config/profiler/jvm-options");
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(optionName));
+ assertThat(jvmOptions, hasItem(optionName));
deleteProfiler(testConfigUrl + "/java-config/profiler/delete-profiler", testConfigName, true);
}
@@ -204,26 +190,24 @@
public void testJvmOptionWithColon() {
final String optionName = "-XX:MaxPermSize";
final String optionValue = "152m";
- Map<String, String> newOptions = new HashMap<>() {{
- put(escape(optionName), optionValue);
- }};
+ Map<String, String> newOptions = Map.of(escape(optionName), optionValue);
- Response response = post(testConfigJvmOptionsUrl, newOptions);
+ Response response = managementClient.post(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
assertEquals(200, response.getStatus());
List<String> jvmOptions = getJvmOptions(response);
- assertTrue(jvmOptions.contains(optionName+"="+optionValue));
+ assertThat(jvmOptions, hasItem(optionName + '=' + optionValue));
- response = delete(testConfigJvmOptionsUrl, newOptions);
+ response = managementClient.delete(testConfigJvmOptionsUrl, newOptions);
assertEquals(200, response.getStatus());
- response = get(testConfigJvmOptionsUrl);
+ response = managementClient.get(testConfigJvmOptionsUrl);
jvmOptions = getJvmOptions(response);
- assertFalse(jvmOptions.contains(optionName+"="+optionValue));
+ assertThat(jvmOptions, not(hasItem(optionName + '=' + optionValue)));
}
private void deleteProfiler(final String url, final String target, final boolean failOnError) {
- Response response = delete(url, Map.of("target", target));
+ Response response = managementClient.delete(url, Map.of("target", target));
if (failOnError) {
assertEquals(200, response.getStatus());
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java
index 27dcde0..fb15ba7 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java
@@ -33,12 +33,12 @@
* @author jasonlee
*/
public class MetadataITest extends RestTestBase {
- private static final String URL_CONFIG = "domain/configs/config.json";
- private static final String URL_UPTIMECOMMAND = "domain/uptime.json";
+ private static final String URL_CONFIG = "/domain/configs/config.json";
+ private static final String URL_UPTIMECOMMAND = "/domain/uptime.json";
@Test
public void configParameterTest() {
- Response response = options(URL_CONFIG);
+ Response response = managementClient.options(URL_CONFIG);
assertEquals(200, response.getStatus());
// Really dumb test. Should be good enough for now
@@ -46,21 +46,21 @@
assertNotNull(extraProperties);
// Another dumb test to make sure that "name" shows up on the HTML page
- response = getClient().target(getAddress(URL_CONFIG)).request().get(Response.class);
+ response = managementClient.get(URL_CONFIG);
String data = response.readEntity(String.class);
assertThat(data, stringContainsInOrder("extraProperties"));
}
@Test
public void upTimeMetadaDataTest() {
- Response response = options(URL_UPTIMECOMMAND);
+ Response response = managementClient.options(URL_UPTIMECOMMAND);
assertEquals(200, response.getStatus());
- Map extraProperties = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
+ Map<String, ?> extraProperties = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
assertNotNull(extraProperties);
// Another dumb test to make sure that "extraProperties" shows up on the HTML page
- response = getClient().target(getAddress(URL_UPTIMECOMMAND)).request().get(Response.class);
+ response = managementClient.get(URL_UPTIMECOMMAND);
String resp = response.readEntity(String.class);
assertThat(resp, stringContainsInOrder("extraProperties"));
// test to see if we get the milliseconds parameter description which is an
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java
index 0ad5cdf..fbf87af 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java
@@ -19,31 +19,60 @@
import jakarta.ws.rs.core.Response;
+
import java.util.HashMap;
import java.util.Map;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
+ * Note regards HTTP 200/202 - not sure why it is happening, but the server probably needs some time
+ * to propagate changes, while we request another.
+ *
* @author Mitesh Meswani
*/
@TestMethodOrder(OrderAnnotation.class)
public class MonitoringITest extends RestTestBase {
- private static final String MONITORING_RESOURCE_URL = "domain/configs/config/server-config/monitoring-service/module-monitoring-levels";
- private static final String JDBC_CONNECTION_POOL_URL = "domain/resources/jdbc-connection-pool";
- private static final String PING_CONNECTION_POOL_URL = "domain/resources/ping-connection-pool";
- private static final String CONTEXT_ROOT_MONITORING = "monitoring";
+
+ private static final String MONITORING_RESOURCE_URL = "/domain/configs/config/server-config/monitoring-service/module-monitoring-levels";
+ private static final String JDBC_CONNECTION_POOL_URL = "/domain/resources/jdbc-connection-pool";
+ private static final String PING_CONNECTION_POOL_URL = "/domain/resources/ping-connection-pool";
+ private static final String POOL_NAME_W_DOT = "poolNameWith.dot";
+
+ private static DomainAdminRestClient monitoringClient;
+
+ @BeforeAll
+ public static void init() {
+ monitoringClient = new DomainAdminRestClient(getBaseAdminUrl() + "/monitoring");
+ }
+
+
+ @AfterAll
+ public static void closeResources() {
+ Response responseDel = managementClient.delete(JDBC_CONNECTION_POOL_URL + '/' + POOL_NAME_W_DOT);
+ assertThat(responseDel.getStatus(), anyOf(equalTo(200), equalTo(202), equalTo(404)));
+ if (monitoringClient != null) {
+ monitoringClient.close();
+ }
+ }
+
@Test
@Order(1)
public void enableMonitoring() {
- String url = getManagementURL(MONITORING_RESOURCE_URL);
Map<String, String> payLoad = new HashMap<>() {
{
put("ThreadPool", "HIGH");
@@ -64,8 +93,8 @@
put("Jersey", "HIGH");
}
};
- Response response = post(url, payLoad);
- assertEquals(202, response.getStatus());
+ Response response = managementClient.post(MONITORING_RESOURCE_URL, payLoad);
+ assertThat(response.getStatus(), anyOf(equalTo(200), equalTo(202)));
}
/**
@@ -75,11 +104,11 @@
@Test
@Order(2)
public void testBaseURL() {
- Response response = get("domain");
- assertEquals(200, response.getStatus());
+ Response response = monitoringClient.get("/domain");
+ assertThat(response.getStatus(), anyOf(equalTo(200), equalTo(202)));
// monitoring/domain
Map<String, String> entity = getChildResources(response);
- assertNull(entity.get("server"), entity.toString());
+ assertNotNull(entity.get("server"), entity.toString());
}
/**
@@ -89,7 +118,7 @@
@Test
@Order(10)
public void testInvalidResource() {
- Response response = get("domain/server/foo");
+ Response response = monitoringClient.get("/domain/server/foo");
assertEquals(404, response.getStatus(), "Did not receive ");
}
@@ -100,75 +129,56 @@
@Test
@Order(20)
public void testDot() {
- // Step 1- Create a resource with "."
- final String poolNameWithDot = "poolNameWith.dot";
+ Response responseDel = managementClient.delete(JDBC_CONNECTION_POOL_URL + '/' + POOL_NAME_W_DOT);
+ assertThat(responseDel.getStatus(), equalTo(404));
- // Clean up from leftover from previous run
- String url = getManagementURL(JDBC_CONNECTION_POOL_URL + '/' + poolNameWithDot);
- Response responseDel = delete(url);
- assertEquals(202, responseDel.getStatus());
-
- url = getManagementURL(JDBC_CONNECTION_POOL_URL);
Map<String, String> payLoad = new HashMap<>() {
{
- put("name", poolNameWithDot);
+ put("name", POOL_NAME_W_DOT);
put("resType", "javax.sql.DataSource");
put("datasourceClassname", "foo.bar");
}
};
- Response response = post(url, payLoad);
- assertEquals(202, response.getStatus());
-
+ Response response = managementClient.post(JDBC_CONNECTION_POOL_URL, payLoad);
+ assertThat(response.getStatus(), anyOf(equalTo(200), equalTo(202)));
// Step 2- Ping the connection pool to generate some monitoring data
- url = getManagementURL(PING_CONNECTION_POOL_URL);
- Response responsePing = get(url, Map.of("id", poolNameWithDot));
- assertEquals(202, responsePing.getStatus());
+ Response responsePing = managementClient.get(PING_CONNECTION_POOL_URL, Map.of("id", POOL_NAME_W_DOT));
+ // foo.bar is invalid ds class
+ assertThat(responsePing.toString(), responsePing.getStatus(), equalTo(500));
// Step 3 - Access monitoring tree to assert it is accessible
- // FIXME: As of 03.04.2022 Utils.getJerseyClient here throws exception:
- // java.lang.ClassNotFoundException: Provider for jakarta.ws.rs.client.ClientBuilder cannot be found
-// Response responsePool = get("domain/server/resources/" + poolNameWithDot);
-// assertEquals(200, responsePool.getStatus());
-// Map<String, String> responseEntity = getEntityValues(responsePool);
-// assertThat("No Monitoring data found for pool " + poolNameWithDot, responseEntity, aMapWithSize(2));
+ Response responsePool = monitoringClient.get("/domain/server/resources/" + POOL_NAME_W_DOT);
+ assertEquals(200, responsePool.getStatus());
+ Map<String, String> responseEntity = getEntityValues(responsePool);
+ assertThat("Monitoring data: \n" + responseEntity, responseEntity, aMapWithSize(14));
}
@Test
@Order(1000)
public void testCleanup() {
- String url = getManagementURL(MONITORING_RESOURCE_URL);
Map<String, String> payLoad = new HashMap<>() {
{
- put("ThreadPool", "LOW");
- put("Orb", "LOW");
- put("EjbContainer", "LOW");
- put("WebContainer", "LOW");
- put("Deployment", "LOW");
- put("TransactionService", "LOW");
- put("HttpService", "LOW");
- put("JdbcConnectionPool", "LOW");
- put("ConnectorConnectionPool", "LOW");
- put("ConnectorService", "LOW");
- put("JmsService", "LOW");
- put("Jvm", "LOW");
- put("Security", "LOW");
- put("WebServicesContainer", "LOW");
- put("Jpa", "LOW");
- put("Jersey", "LOW");
+ put("ThreadPool", "OFF");
+ put("Orb", "OFF");
+ put("EjbContainer", "OFF");
+ put("WebContainer", "OFF");
+ put("Deployment", "OFF");
+ put("TransactionService", "OFF");
+ put("HttpService", "OFF");
+ put("JdbcConnectionPool", "OFF");
+ put("ConnectorConnectionPool", "OFF");
+ put("ConnectorService", "OFF");
+ put("JmsService", "OFF");
+ put("Jvm", "OFF");
+ put("Security", "OFF");
+ put("WebServicesContainer", "OFF");
+ put("Jpa", "OFF");
+ put("Jersey", "OFF");
}
};
- Response response = post(url, payLoad);
- assertEquals(202, response.getStatus());
- }
-
- @Override
- protected String getContextRoot() {
- return CONTEXT_ROOT_MONITORING;
- }
-
- private String getManagementURL(String targetResourceURL) {
- return getBaseAdminUrl() + CONTEXT_ROOT_MANAGEMENT + targetResourceURL;
+ Response response = managementClient.post(MONITORING_RESOURCE_URL, payLoad);
+ assertThat(response.getStatus(), anyOf(equalTo(200), equalTo(202)));
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java
index 46cb690..4e26dce 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java
@@ -23,6 +23,7 @@
import java.util.Map;
import org.codehaus.jettison.json.JSONObject;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -33,87 +34,92 @@
* @author jasonlee
*/
public class NetworkListenerITest extends RestTestBase {
- protected static final String URL_PROTOCOL = "domain/configs/config/server-config/network-config/protocols/protocol";
- protected static final String URL_SSL = "domain/configs/config/server-config/network-config/protocols/protocol/http-listener-2/ssl";
+ private static final String URL_PROTOCOL = "/domain/configs/config/server-config/network-config/protocols/protocol";
+ private static final String URL_SSL = "/domain/configs/config/server-config/network-config/protocols/protocol/http-listener-2/ssl";
+
+ private static final String redirectProtocolName = "http-redirect";
+ private static final String portUniProtocolName = "pu-protocol";
+
+ private static final String redirectFilterName = "redirect-filter";
+ private static final String finderName1 = "http-finder";
+ private static final String finderName2 = "http-redirect";
+
+ @AfterAll
+ public static void cleanup() {
+ Response response = managementClient.post(
+ "/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1",
+ Map.of("protocol", "http-listener-1"));
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(URL_PROTOCOL + "/" + portUniProtocolName + "/delete-protocol-finder",
+ Map.of("protocol", portUniProtocolName, "id", finderName1));
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(URL_PROTOCOL + "/" + portUniProtocolName + "/delete-protocol-finder",
+ Map.of("protocol", portUniProtocolName, "id", finderName2));
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(
+ URL_PROTOCOL + "/" + redirectProtocolName
+ + "/protocol-chain-instance-handler/protocol-chain/protocol-filter/" + redirectFilterName,
+ Map.of("protocol", redirectProtocolName));
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(URL_PROTOCOL + "/" + portUniProtocolName);
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(URL_PROTOCOL + "/" + redirectProtocolName);
+ assertEquals(200, response.getStatus());
+ }
+
@Test
public void createHttpListener() {
- final String redirectProtocolName = "http-redirect";
- final String portUniProtocolName = "pu-protocol";
+ Response response = managementClient.post("/domain/set", Map.of(
+ "configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol",
+ "http-listener-1"));
+ assertEquals(200, response.getStatus());
+ managementClient.delete(URL_PROTOCOL + "/" + portUniProtocolName);
+ assertEquals(200, response.getStatus());
+ managementClient.delete(URL_PROTOCOL + "/" + redirectProtocolName);
+ assertEquals(200, response.getStatus());
+ // asadmin commands taken from: http://www.antwerkz.com/port-unification-in-glassfish-3-part-1/
+ // asadmin create-protocol --securityenabled=false http-redirect
+ // asadmin create-protocol --securityenabled=false pu-protocol
+ response = managementClient.post(URL_PROTOCOL, Map.of("securityenabled", "false", "id", redirectProtocolName));
+ assertEquals(200, response.getStatus());
+ response = managementClient.post(URL_PROTOCOL, Map.of("securityenabled", "false", "id", portUniProtocolName));
+ assertEquals(200, response.getStatus());
- final String redirectFilterName = "redirect-filter";
- final String finderName1 = "http-finder";
- final String finderName2 = "http-redirect";
+ // asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter
+ response = managementClient.post(URL_PROTOCOL + "/" + redirectProtocolName + "/create-protocol-filter",
+ Map.of("id", redirectFilterName, "protocol", redirectProtocolName,
+ "classname", "org.glassfish.grizzly.config.portunif.HttpRedirectFilter"));
+ assertEquals(200, response.getStatus());
- try {
- Response response = post("domain/set", Map.of("configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol", "http-listener-1"));
- assertEquals(200, response.getStatus());
- delete(URL_PROTOCOL + "/" + portUniProtocolName);
- assertEquals(200, response.getStatus());
- delete(URL_PROTOCOL + "/" + redirectProtocolName);
- assertEquals(200, response.getStatus());
-// asadmin commands taken from: http://www.antwerkz.com/port-unification-in-glassfish-3-part-1/
-// asadmin create-protocol --securityenabled=false http-redirect
-// asadmin create-protocol --securityenabled=false pu-protocol
- response = post(URL_PROTOCOL, Map.of("securityenabled", "false", "id", redirectProtocolName));
- assertEquals(200, response.getStatus());
- response = post(URL_PROTOCOL, Map.of("securityenabled", "false", "id", portUniProtocolName));
- assertEquals(200, response.getStatus());
-
-// asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter
- response = post(URL_PROTOCOL + "/" + redirectProtocolName + "/create-protocol-filter",
- Map.of("id", redirectFilterName, "protocol", redirectProtocolName,
- "classname", "org.glassfish.grizzly.config.portunif.HttpRedirectFilter"));
- assertEquals(200, response.getStatus());
-
-// asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder
-// asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect
- response = post (URL_PROTOCOL + "/" + portUniProtocolName + "/create-protocol-finder",
- new HashMap<String, String>() {{
- put ("id", finderName1);
- put ("protocol", portUniProtocolName);
- put ("targetprotocol", "http-listener-2");
- put ("classname", "org.glassfish.grizzly.config.portunif.HttpProtocolFinder");
- }});
- assertEquals(200, response.getStatus());
- response = post (URL_PROTOCOL + "/" + portUniProtocolName + "/create-protocol-finder",
- new HashMap<String, String>() {{
- put ("id", finderName2);
- put ("protocol", portUniProtocolName);
- put ("targetprotocol", redirectProtocolName);
- put ("classname", "org.glassfish.grizzly.config.portunif.HttpProtocolFinder");
- }});
- assertEquals(200, response.getStatus());
+ // asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder
+ // asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect
+ response = managementClient.post(URL_PROTOCOL + "/" + portUniProtocolName + "/create-protocol-finder",
+ new HashMap<String, String>() {{
+ put ("id", finderName1);
+ put ("protocol", portUniProtocolName);
+ put ("targetprotocol", "http-listener-2");
+ put ("classname", "org.glassfish.grizzly.config.portunif.HttpProtocolFinder");
+ }});
+ assertEquals(200, response.getStatus());
+ response = managementClient.post(URL_PROTOCOL + "/" + portUniProtocolName + "/create-protocol-finder",
+ new HashMap<String, String>() {{
+ put ("id", finderName2);
+ put ("protocol", portUniProtocolName);
+ put ("targetprotocol", redirectProtocolName);
+ put ("classname", "org.glassfish.grizzly.config.portunif.HttpProtocolFinder");
+ }});
+ assertEquals(200, response.getStatus());
-// asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol
- response = post("domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1",
- Map.of("protocol", portUniProtocolName));
- assertEquals(200, response.getStatus());
+ // asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol
+ response = managementClient.post(
+ "/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1",
+ Map.of("protocol", portUniProtocolName));
+ assertEquals(200, response.getStatus());
- response = get("domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1/find-http-protocol");
- assertThat(response.readEntity(String.class), stringContainsInOrder("http-listener-2"));
- } finally {
- Response response = post(
- "domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1",
- Map.of("protocol", "http-listener-1"));
- assertEquals(200, response.getStatus());
- response = delete(URL_PROTOCOL + "/" + portUniProtocolName + "/delete-protocol-finder",
- Map.of("protocol", portUniProtocolName, "id", finderName1));
- assertEquals(200, response.getStatus());
- response = delete(URL_PROTOCOL + "/" + portUniProtocolName + "/delete-protocol-finder",
- Map.of("protocol", portUniProtocolName, "id", finderName2));
- assertEquals(200, response.getStatus());
- response = delete(
- URL_PROTOCOL + "/" + redirectProtocolName
- + "/protocol-chain-instance-handler/protocol-chain/protocol-filter/" + redirectFilterName,
- Map.of("protocol", redirectProtocolName));
- assertEquals(200, response.getStatus());
- response = delete(URL_PROTOCOL + "/" + portUniProtocolName);
- assertEquals(200, response.getStatus());
- response = delete(URL_PROTOCOL + "/" + redirectProtocolName);
- assertEquals(200, response.getStatus());
- }
+ response = managementClient.get("/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1/find-http-protocol");
+ assertThat(response.readEntity(String.class), stringContainsInOrder("http-listener-2"));
}
@Test
@@ -125,9 +131,9 @@
put("trustStore", "baz");
}};
- Response response = post(URL_SSL, params);
+ Response response = managementClient.post(URL_SSL, params);
assertEquals(200, response.getStatus());
- response = get(URL_SSL, params);
+ response = managementClient.get(URL_SSL, params);
Map<String, String> entity = this.getEntityValues(response);
assertEquals(params.get("keyStore"), entity.get("keyStore"));
assertEquals(params.get("trustAlgorithm"), entity.get("trustAlgorithm"));
@@ -137,9 +143,9 @@
params.put("keyStore", "");
params.put("trustAlgorithm", "");
params.put("trustStore", "");
- response = post(URL_SSL, params);
+ response = managementClient.post(URL_SSL, params);
assertEquals(200, response.getStatus());
- response = get(URL_SSL, params);
+ response = managementClient.get(URL_SSL, params);
entity = this.getEntityValues(response);
assertEquals(JSONObject.NULL, entity.get("keyStore"));
assertEquals(JSONObject.NULL, entity.get("trustAlgorithm"));
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java
index e248c4b..2e3a45e 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java
@@ -18,7 +18,6 @@
package org.glassfish.nucleus.admin.rest;
import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.HashMap;
@@ -26,6 +25,7 @@
import org.junit.jupiter.api.Test;
+import static jakarta.ws.rs.core.MediaType.APPLICATION_XML;
import static org.glassfish.admin.rest.client.utils.MarshallingUtils.getXmlForProperties;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,7 +33,8 @@
* @author Mitesh Meswani
*/
public class NoCLICommandResourceCreationITest extends RestTestBase {
- private static final String URL_SERVER_PROPERTY = "domain/servers/server/server/property";
+ private static final String URL_SERVER_PROPERTY = "/domain/servers/server/server/property";
+
@Test
public void testPropertyCreation() {
@@ -43,15 +44,14 @@
//Create a property
Map<String, String> param = new HashMap<>();
param.put("name", propertyKey);
- param.put("value",propertyValue);
- Response response = getClient().target(getAddress(URL_SERVER_PROPERTY))
- .request(RESPONSE_TYPE)
- .post(Entity.entity(getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class);
+ param.put("value", propertyValue);
+ Response response = managementClient.post(URL_SERVER_PROPERTY,
+ Entity.entity(getXmlForProperties(param), APPLICATION_XML));
assertEquals(200, response.getStatus());
//Verify the property got created
String propertyURL = URL_SERVER_PROPERTY + "/" + propertyKey;
- response = get (propertyURL);
+ response = managementClient.get(propertyURL);
assertEquals(200, response.getStatus());
Map<String, String> entity = getEntityValues(response);
assertEquals(propertyKey, entity.get("name"));
@@ -60,19 +60,16 @@
// Verify property update
propertyValue = generateRandomString();
param.put("value", propertyValue);
- response = getClient().target(getAddress(URL_SERVER_PROPERTY))
- .request(RESPONSE_TYPE)
- .put(Entity.entity(getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class);
+ response = managementClient.put(URL_SERVER_PROPERTY, Entity.entity(getXmlForProperties(param), APPLICATION_XML));
assertEquals(200, response.getStatus());
- response = get (propertyURL);
+ response = managementClient.get(propertyURL);
assertEquals(200, response.getStatus());
entity = getEntityValues(response);
assertEquals(propertyKey, entity.get("name"));
assertEquals(propertyValue, entity.get("value"));
//Clean up to leave domain.xml good for next run
- response = delete(propertyURL, new HashMap<String, String>());
+ response = managementClient.delete(propertyURL, new HashMap<String, String>());
assertEquals(200, response.getStatus());
}
-
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java
index 797c086..11f7751 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java
@@ -29,15 +29,16 @@
* @author jasonlee
*/
public class PartialUpdateITest extends RestTestBase {
+
@Test
public void testPartialUpdate() {
final String endpoint = URL_JDBC_CONNECTION_POOL + "/DerbyPool";
final String newDesc = generateRandomString();
- Map<String, String> origAttrs = getEntityValues(get(endpoint));
+ Map<String, String> origAttrs = getEntityValues(managementClient.get(endpoint));
Map<String, String> newAttrs = Map.of("description", newDesc);
- Response response = post(endpoint, newAttrs);
+ Response response = managementClient.post(endpoint, newAttrs);
assertEquals(200, response.getStatus());
- Map<String, String> updatedAttrs = getEntityValues(get(endpoint));
+ Map<String, String> updatedAttrs = getEntityValues(managementClient.get(endpoint));
assertEquals(newDesc, updatedAttrs.get("description"));
assertEquals(origAttrs.get("driverClassname"), updatedAttrs.get("driverClassname"));
assertEquals(origAttrs.get("resType"), updatedAttrs.get("resType"));
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java
index 9ca20a4..ba6a813 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java
@@ -18,7 +18,6 @@
package org.glassfish.nucleus.admin.rest;
import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
@@ -30,6 +29,7 @@
import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.junit.jupiter.api.Test;
+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -46,15 +46,14 @@
public class PropertiesBagITest extends RestTestBase {
private static final String PROP_DOMAIN_NAME = "administrative.domain.name";
- private static final String URL_DOMAIN_PROPERTIES = "domain/property";
- private static final String URL_JAVA_CONFIG_PROPERTIES = "domain/configs/config/default-config/java-config/property";
- private static final String URL_SERVER_PROPERTIES = "domain/servers/server/server/property";
- private static final String URL_DERBYPOOL_PROPERTIES = "domain/resources/jdbc-connection-pool/DerbyPool/property";
- private static final String REQUEST_FORMAT = MediaType.APPLICATION_JSON;
+ private static final String URL_DOMAIN_PROPERTIES = "/domain/property";
+ private static final String URL_JAVA_CONFIG_PROPERTIES = "/domain/configs/config/default-config/java-config/property";
+ private static final String URL_SERVER_PROPERTIES = "/domain/servers/server/server/property";
+ private static final String URL_DERBYPOOL_PROPERTIES = "/domain/resources/jdbc-connection-pool/DerbyPool/property";
@Test
public void propertyRetrieval() {
- Response response = get(URL_DOMAIN_PROPERTIES);
+ Response response = managementClient.get(URL_DOMAIN_PROPERTIES);
assertEquals(200, response.getStatus());
List<Map<String, String>> properties = getProperties(response);
assertTrue(isPropertyFound(properties, PROP_DOMAIN_NAME));
@@ -82,7 +81,7 @@
properties.add(createProperty(foo,"foovalue"));
properties.add(createProperty(bar,"barvalue"));
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- List<Map<String, String>> newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ List<Map<String, String>> newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
assertFalse(isPropertyFound(newProperties, empty));
assertTrue(isPropertyFound(newProperties, foo));
@@ -91,7 +90,7 @@
properties.clear();
properties.add(createProperty(abc,"abcvalue"));
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
assertTrue(isPropertyFound(newProperties, abc));
assertFalse(isPropertyFound(newProperties, empty));
@@ -112,7 +111,7 @@
properties.add(createProperty("foo","bar","test"));
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- List<Map<String, String>> newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ List<Map<String, String>> newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
for (Map<String, String> property : newProperties) {
if (property.get("name").equals("connectionAttributes")) {
assertEquals(";create=false", property.get("value"));
@@ -127,7 +126,7 @@
properties.add(createProperty("foo","bar 2","test 2"));
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
assertNotSame(1, newProperties);
for (Map<String, String> property : newProperties) {
if (property.get("name").equals("foo")) {
@@ -147,7 +146,7 @@
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
for (Map<String, String> property : newProperties) {
if (property.get("name").equals("connectionAttributes")) {
assertEquals(";create=true", property.get("value"));
@@ -157,8 +156,6 @@
}
}
- // FIXME: the prop name can not contain .
- // need to remove the . test when http://java.net/jira/browse/GLASSFISH-15418 is fixed
@Test
public void testPropertiesWithDots() {
List<Map<String, String>> properties = new ArrayList<>();
@@ -168,7 +165,7 @@
properties.add(createProperty(key, value, description));
createProperties(URL_DERBYPOOL_PROPERTIES, properties);
- List<Map<String, String>> newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES));
+ List<Map<String, String>> newProperties = getProperties(managementClient.get(URL_DERBYPOOL_PROPERTIES));
Map<String, String> newProp = getProperty(newProperties, key);
assertNotNull(newProp);
assertEquals(value, newProp.get("value"));
@@ -209,9 +206,9 @@
put("property", propertyList);
}};
- final String URL = "domain/resources/resource-adapter-config";
- delete(URL+"/jmsra");
- Response response = post(URL, attrs);
+ final String url = "/domain/resources/resource-adapter-config";
+ managementClient.delete(url + "/jmsra");
+ Response response = managementClient.post(url, attrs);
assertEquals(200, response.getStatus());
// Change one property value (AddressListIterations) and update the object
@@ -232,9 +229,9 @@
add(createProperty("doBind", "false"));
add(createProperty("startRMIRegistry", "false"));
}};
- createProperties(URL+"/jmsra/property", props);
+ createProperties(url + "/jmsra/property", props);
- delete(URL+"/jmsra");
+ managementClient.delete(url + "/jmsra");
}
@Test
@@ -248,18 +245,17 @@
payload.put("persistenceStoreHealthCheckEnabled","false");
payload.put("ssoFailoverEnabled","false");
- final String wcaUri = "domain/configs/config/default-config/availability-service/web-container-availability";
- Response response = post(wcaUri, payload);
+ final String wcaUri = "/domain/configs/config/default-config/availability-service/web-container-availability";
+ Response response = managementClient.post(wcaUri, payload);
assertThat(response.getStatus(), equalTo(200));
- assertThat(get(wcaUri).getStatus(), equalTo(200));
+ assertThat(managementClient.get(wcaUri).getStatus(), equalTo(200));
- response = getClient()
- .target(getAddress("domain/configs/config/default-config/availability-service/web-container-availability/property")).
- request(getResponseType())
- .post(Entity.json(new JSONArray()), Response.class);
+ response = managementClient.post(
+ "/domain/configs/config/default-config/availability-service/web-container-availability/property",
+ Entity.json(new JSONArray()));
assertThat(response.getStatus(), equalTo(200));
- assertThat(get(wcaUri).getStatus(), equalTo(200));
+ assertThat(managementClient.get(wcaUri).getStatus(), equalTo(200));
}
private String buildPropertyList(List<Map<String, String>> props) {
@@ -274,7 +270,7 @@
}
private void createAndDeleteProperties(String endpoint) {
- Response response = get(endpoint);
+ Response response = managementClient.get(endpoint);
assertEquals(200, response.getStatus());
assertNotNull(getProperties(response));
@@ -285,7 +281,7 @@
}
createProperties(endpoint, properties);
- response = delete(endpoint);
+ response = managementClient.delete(endpoint);
assertEquals(200, response.getStatus());
}
@@ -294,30 +290,36 @@
}
private Map<String, String> createProperty(final String name, final String value, final String description) {
- return new HashMap<>() {{
- put ("name", name);
- put ("value", value);
+ return new HashMap<>() {
+ {
+ put("name", name);
+ put("value", value);
if (description != null) {
- put ("description", description);
+ put("description", description);
}
- }};
+ }
+ };
}
private void createProperties(String endpoint, List<Map<String, String>> properties) {
final String payload = buildPayload(properties);
- Response response = getClient().target(getAddress(endpoint))
- .request(RESPONSE_TYPE)
- .post(Entity.entity(payload, REQUEST_FORMAT), Response.class);
+
+ Response response = managementClient.post(endpoint, Entity.entity(payload, APPLICATION_JSON));
assertEquals(200, response.getStatus());
- response = get(endpoint);
+ response = managementClient.get(endpoint);
assertEquals(200, response.getStatus());
// Retrieve the properties and make sure they were created.
-// List<Map<String, String>> newProperties = getProperties(response);
-//
-// for (Map<String, String> property : properties) {
-// assertTrue(isPropertyFound(newProperties, property.get("name")));
-// }
+ List<Map<String, String>> newProperties = getProperties(response);
+ for (Map<String, String> property : properties) {
+ String name = property.get("name");
+ String value = property.get("value");
+ if (value == null || value.isBlank()) {
+ assertFalse(isPropertyFound(newProperties, name));
+ } else {
+ assertTrue(isPropertyFound(newProperties, name));
+ }
+ }
}
// Restore and verify the default domain properties
@@ -326,21 +328,16 @@
put("name", PROP_DOMAIN_NAME);
put("value", "domain1");
}};
- Response response = getClient().target(getAddress(URL_DOMAIN_PROPERTIES))
- .request(RESPONSE_TYPE)
- .put(Entity.entity(buildPayload(new ArrayList<Map<String, String>>() {{ add(domainProps); }}), REQUEST_FORMAT), Response.class);
+ Response response = managementClient.put(URL_DOMAIN_PROPERTIES,
+ Entity.entity(buildPayload(List.of(domainProps)), APPLICATION_JSON));
assertEquals(200, response.getStatus());
- response = get(URL_DOMAIN_PROPERTIES);
+ response = managementClient.get(URL_DOMAIN_PROPERTIES);
assertEquals(200, response.getStatus());
assertTrue(isPropertyFound(getProperties(response), PROP_DOMAIN_NAME));
}
private String buildPayload(List<Map<String, String>> properties) {
- if (RESPONSE_TYPE.equals(MediaType.APPLICATION_XML)) {
- return MarshallingUtils.getXmlForProperties(properties);
- } else {
- return MarshallingUtils.getJsonForProperties(properties);
- }
+ return MarshallingUtils.getJsonForProperties(properties);
}
private boolean isPropertyFound(List<Map<String, String>> properties, String name) {
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java
index e6b2fc9..8d93960 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java
@@ -19,6 +19,9 @@
import jakarta.ws.rs.core.Response;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -27,135 +30,145 @@
* @author jasonlee
*/
public class ProvidersITest extends RestTestBase {
- private static final String URL_ACTION_REPORT_RESULT = "domain/uptime";
- private static final String URL_COMMAND_RESOURCE_GET_RESULT = "domain/stop";
- private static final String URL_GET_RESULT = "domain";
- private static final String URL_GET_RESULT_LIST = "domain/servers/server";
- private static final String URL_OPTIONS_RESULT = "domain";
- private static final String URL_STRING_LIST_RESULT = "domain/configs/config/server-config/java-config/jvm-options";
- private static String URL_TREE_NODE;
+ private static final String URL_ACTION_REPORT_RESULT = "/domain/uptime";
+ private static final String URL_COMMAND_RESOURCE_GET_RESULT = "/domain/stop";
+ private static final String URL_GET_RESULT = "/domain";
+ private static final String URL_GET_RESULT_LIST = "/domain/servers/server";
+ private static final String URL_OPTIONS_RESULT = "/domain";
+ private static final String URL_STRING_LIST_RESULT = "/domain/configs/config/server-config/java-config/jvm-options";
- public ProvidersITest() {
- URL_TREE_NODE = "http://localhost:" + getParameter("admin.port", "4848") + "/monitoring/domain";
+ private static DomainAdminRestClient monitoringClient;
+
+ @BeforeAll
+ public static void init() {
+ monitoringClient = new DomainAdminRestClient(getBaseAdminUrl() + "/monitoring/domain");
+ }
+
+
+ @AfterAll
+ public static void closeResources() {
+ if (monitoringClient != null) {
+ monitoringClient.close();
+ }
}
@Test
public void testActionReportResultHtmlProvider() {
- Response response = get(URL_ACTION_REPORT_RESULT + ".html");
+ Response response = managementClient.get(URL_ACTION_REPORT_RESULT + ".html");
assertEquals(200, response.getStatus());
}
@Test
public void testActionReportResultXmlProvider() {
- Response response = get(URL_ACTION_REPORT_RESULT + ".xml");
+ Response response = managementClient.get(URL_ACTION_REPORT_RESULT + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testActionReportResultJsonProvider() {
- Response response = get(URL_ACTION_REPORT_RESULT + ".json");
+ Response response = managementClient.get(URL_ACTION_REPORT_RESULT + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testCommandResourceGetResultHtmlProvider() {
- Response response = get(URL_COMMAND_RESOURCE_GET_RESULT + ".html");
+ Response response = managementClient.get(URL_COMMAND_RESOURCE_GET_RESULT + ".html");
assertEquals(200, response.getStatus());
}
@Test
public void testCommandResourceGetResultXmlProvider() {
- Response response = get(URL_COMMAND_RESOURCE_GET_RESULT + ".xml");
+ Response response = managementClient.get(URL_COMMAND_RESOURCE_GET_RESULT + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testCommandResourceGetResultJsonProvider() {
- Response response = get(URL_COMMAND_RESOURCE_GET_RESULT + ".json");
+ Response response = managementClient.get(URL_COMMAND_RESOURCE_GET_RESULT + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultHtmlProvider() {
- Response response = get(URL_GET_RESULT + ".html");
+ Response response = managementClient.get(URL_GET_RESULT + ".html");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultXmlProvider() {
- Response response = get(URL_GET_RESULT + ".xml");
+ Response response = managementClient.get(URL_GET_RESULT + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultJsonProvider() {
- Response response = get(URL_GET_RESULT + ".json");
+ Response response = managementClient.get(URL_GET_RESULT + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultListHtmlProvider() {
- Response response = get(URL_GET_RESULT_LIST + ".html");
+ Response response = managementClient.get(URL_GET_RESULT_LIST + ".html");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultListXmlProvider() {
- Response response = get(URL_GET_RESULT_LIST + ".xml");
+ Response response = managementClient.get(URL_GET_RESULT_LIST + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testGetResultListJsonProvider() {
- Response response = get(URL_GET_RESULT_LIST + ".json");
+ Response response = managementClient.get(URL_GET_RESULT_LIST + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testOptionsResultXmlProvider() {
- Response response = options(URL_OPTIONS_RESULT + ".xml");
+ Response response = managementClient.options(URL_OPTIONS_RESULT + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testOptionsResultJsonProvider() {
- Response response = options(URL_OPTIONS_RESULT + ".json");
+ Response response = managementClient.options(URL_OPTIONS_RESULT + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testStringListResultHtmlProvider() {
- Response response = get(URL_STRING_LIST_RESULT + ".html");
+ Response response = managementClient.get(URL_STRING_LIST_RESULT + ".html");
assertEquals(200, response.getStatus());
}
@Test
public void testStringListResultXmlProvider() {
- Response response = get(URL_STRING_LIST_RESULT + ".xml");
+ Response response = managementClient.get(URL_STRING_LIST_RESULT + ".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testStringListResultJsonProvider() {
- Response response = get(URL_STRING_LIST_RESULT + ".json");
+ Response response = managementClient.get(URL_STRING_LIST_RESULT + ".json");
assertEquals(200, response.getStatus());
}
@Test
public void testTreeNodeHtmlProvider() {
- Response response = get(URL_TREE_NODE + ".html");
+ Response response = monitoringClient.get(".html");
assertEquals(200, response.getStatus());
}
@Test
public void testTreeNodeXmlProvider() {
- Response response = get(URL_TREE_NODE + ".xml");
+ Response response = monitoringClient.get(".xml");
assertEquals(200, response.getStatus());
}
@Test
public void testTreeNodeJsonProvider() {
- Response response = get(URL_TREE_NODE + ".json");
+ Response response = monitoringClient.get(".json");
assertEquals(200, response.getStatus());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java
index ce658d3..cb71888 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java
@@ -22,22 +22,34 @@
import java.util.HashMap;
import java.util.Map;
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author jasonlee
*/
public class ResourceRefITest extends RestTestBase {
- private static final String URL_CREATE_INSTANCE = "domain/create-instance";
- private static final String URL_JDBC_RESOURCE = "domain/resources/jdbc-resource";
- private static final String URL_RESOURCE_REF = "domain/servers/server/server/resource-ref";
+ private static final String URL_CREATE_INSTANCE = "/domain/create-instance";
+ private static final String URL_JDBC_RESOURCE = "/domain/resources/jdbc-resource";
+ private static final String URL_RESOURCE_REF = "/domain/servers/server/server/resource-ref";
+
+ private final String instanceName = "instance_" + generateRandomString();
+ private final String jdbcResourceName = "jdbc_" + generateRandomString();
+
+ @AfterEach
+ public void cleanup() {
+ Asadmin asadmin = GlassFishTestEnvironment.getAsadmin();
+ asadmin.exec("delete-resource-ref", jdbcResourceName);
+ asadmin.exec("delete-jdbc-resource", jdbcResourceName);
+ asadmin.exec("delete-instance", instanceName);
+ }
+
@Test
public void testCreatingResourceRef() {
- final String instanceName = "instance_" + generateRandomString();
- final String jdbcResourceName = "jdbc_" + generateRandomString();
Map<String, String> newInstance = new HashMap<>() {{
put("id", instanceName);
put("node", "localhost-domain1");
@@ -52,31 +64,29 @@
put("target", "server");
}};
- try {
- Response response = post(URL_CREATE_INSTANCE, newInstance);
- assertEquals(200, response.getStatus());
+ Response response = managementClient.post(URL_CREATE_INSTANCE, newInstance);
+ assertEquals(200, response.getStatus());
- response = post(URL_JDBC_RESOURCE, jdbcResource);
- assertEquals(200, response.getStatus());
+ response = managementClient.post(URL_JDBC_RESOURCE, jdbcResource);
+ assertEquals(200, response.getStatus());
- response = post(URL_RESOURCE_REF, resourceRef);
- assertEquals(200, response.getStatus());
- } finally {
- Response response = delete("domain/servers/server/" + instanceName + "/resource-ref/" + jdbcResourceName,
- Map.of("target", instanceName));
- assertEquals(200, response.getStatus());
- response = get("domain/servers/server/" + instanceName + "/resource-ref/" + jdbcResourceName);
- assertEquals(404, response.getStatus());
+ response = managementClient.post(URL_RESOURCE_REF, resourceRef);
+ assertEquals(200, response.getStatus());
+ response = managementClient.delete(
+ "/domain/servers/server/" + instanceName + "/resource-ref/" + jdbcResourceName,
+ Map.of("target", instanceName));
+ assertEquals(200, response.getStatus());
+ response = managementClient.get("/domain/servers/server/" + instanceName + "/resource-ref/" + jdbcResourceName);
+ assertEquals(404, response.getStatus());
- response = delete(URL_JDBC_RESOURCE + "/" + jdbcResourceName);
- assertEquals(200, response.getStatus());
- response = get(URL_JDBC_RESOURCE + "/" + jdbcResourceName);
- assertEquals(404, response.getStatus());
+ response = managementClient.delete(URL_JDBC_RESOURCE + "/" + jdbcResourceName);
+ assertEquals(200, response.getStatus());
+ response = managementClient.get(URL_JDBC_RESOURCE + "/" + jdbcResourceName);
+ assertEquals(404, response.getStatus());
- response = delete("domain/servers/server/" + instanceName + "/delete-instance");
- assertEquals(200, response.getStatus());
- response = get("domain/servers/server/" + instanceName);
- assertEquals(404, response.getStatus());
- }
+ response = managementClient.delete("/domain/servers/server/" + instanceName + "/delete-instance");
+ assertEquals(200, response.getStatus());
+ response = managementClient.get("/domain/servers/server/" + instanceName);
+ assertEquals(404, response.getStatus());
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/RestTestBase.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/RestTestBase.java
index 3cc5ef7..76d9b9c 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/RestTestBase.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/RestTestBase.java
@@ -18,42 +18,26 @@
package org.glassfish.nucleus.admin.rest;
import jakarta.ws.rs.client.Client;
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.client.WebTarget;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
-import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.glassfish.admin.rest.client.ClientWrapper;
import org.glassfish.admin.rest.client.utils.MarshallingUtils;
-import org.glassfish.jersey.logging.LoggingFeature;
-import org.glassfish.jersey.logging.LoggingFeature.Verbosity;
-import org.glassfish.jersey.media.multipart.FormDataMultiPart;
-import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
-import org.glassfish.nucleus.test.tool.DomainLifecycleExtension;
-import org.glassfish.nucleus.test.tool.NucleusTestUtils;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
import org.glassfish.nucleus.test.webapp.HelloServlet;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
@@ -62,79 +46,61 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.w3c.dom.Document;
+import org.junit.jupiter.api.TestInfo;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.ADMIN_PASSWORD;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.ADMIN_USER;
+import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;
+import static org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment.getTargetDirectory;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
-@ExtendWith(DomainLifecycleExtension.class)
public class RestTestBase {
private static final Logger LOG = Logger.getLogger(RestTestBase.class.getName());
- protected static final String RESPONSE_TYPE = MediaType.APPLICATION_JSON;
+ protected static final String CONTEXT_ROOT_MANAGEMENT = "/management";
- protected static final String CONTEXT_ROOT_MANAGEMENT = "management";
+ protected static final String URL_CLUSTER = "/domain/clusters/cluster";
+ protected static final String URL_APPLICATION_DEPLOY = "/domain/applications/application";
+ protected static final String URL_CREATE_INSTANCE = "/domain/create-instance";
+ protected static final String URL_CONFIGS = "/domain/configs";
+ protected static final String URL_JDBC_RESOURCE = "/domain/resources/jdbc-resource";
+ protected static final String URL_JDBC_CONNECTION_POOL = "/domain/resources/jdbc-connection-pool";
- protected static final String URL_CLUSTER = "domain/clusters/cluster";
- protected static final String URL_APPLICATION_DEPLOY = "domain/applications/application";
- protected static final String URL_CREATE_INSTANCE = "domain/create-instance";
- protected static final String URL_CONFIGS = "domain/configs";
- protected static final String URL_JDBC_RESOURCE = "domain/resources/jdbc-resource";
- protected static final String URL_JDBC_CONNECTION_POOL = "domain/resources/jdbc-connection-pool";
-
- private static String adminHost;
- private static String adminPort;
- private static String instancePort;
private static String baseAdminUrl;
private static String baseInstanceUrl;
+ protected static DomainAdminRestClient managementClient;
- private static String currentTestClass;
private Client client;
@BeforeAll
public static void initialize() {
- adminPort = getParameter("admin.port", "4848");
- instancePort = getParameter("instance.port", "8080");
- adminHost = getParameter("instance.host", "localhost");
- baseAdminUrl = "http://" + adminHost + ':' + adminPort + '/';
- baseInstanceUrl = "http://" + adminHost + ':' + instancePort + '/';
-
- final RestTestBase rtb = new RestTestBase();
- rtb.get("domain/rotate-log");
+ baseAdminUrl = "http://localhost:4848";
+ baseInstanceUrl = "http://localhost:8080";
+ managementClient = new DomainAdminRestClient(baseAdminUrl + CONTEXT_ROOT_MANAGEMENT);
+ Response response = managementClient.get("/domain/rotate-log");
+ assertThat(response.getStatus(), equalTo(200));
}
@AfterAll
- public static void captureLog() {
- try {
- if (currentTestClass != null) {
- RestTestBase rtb = new RestTestBase();
- Client client = new ClientWrapper(new HashMap<String, String>(), ADMIN_USER, ADMIN_PASSWORD);
- Response response = client.target(rtb.getAddress("domain/view-log")).request().get(Response.class);
- File directory = NucleusTestUtils.BASEDIR.toPath().resolve(Path.of("target", "surefire-reports")).toFile();
- directory.mkdirs();
- File output = new File(directory, currentTestClass + "-server.log");
- try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(output)))) {
- out.write(response.readEntity(String.class));
- }
+ public static void captureLogAndCloseClient(final TestInfo testInfo) throws Exception {
+ if (managementClient != null) {
+ managementClient.close();
+ }
+ try (DomainAdminRestClient client = new DomainAdminRestClient(baseAdminUrl + CONTEXT_ROOT_MANAGEMENT, TEXT_PLAIN)) {
+ Response response = client.get("/domain/view-log");
+ assertThat(response.getStatus(), equalTo(200));
+ File directory = new File(getTargetDirectory(), "surefire-reports");
+ directory.mkdirs();
+ File output = new File(directory, testInfo.getTestClass().get().getName() + "-server.log");
+ try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(output)))) {
+ out.write(response.readEntity(String.class));
}
- } catch (Exception ex) {
- Logger.getLogger(RestTestBase.class.getName()).log(Level.SEVERE, null, ex);
}
}
- @BeforeEach
- public void setup() {
- currentTestClass = this.getClass().getName();
- }
-
@AfterEach
- protected void resetClient() {
+ protected void closeClient() throws Exception {
if (client == null) {
return;
}
@@ -143,19 +109,19 @@
}
public void createAndVerifyConfig(String configName, MultivaluedMap<String, String> configData) {
- Response response = post(URL_CONFIGS + "/copy-config", configData);
+ Response response = managementClient.post(URL_CONFIGS + "/copy-config", configData);
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_CONFIGS + "/config/" + configName);
- assertEquals(200, response.getStatus());
+ response = managementClient.get(URL_CONFIGS + "/config/" + configName);
+ assertThat(response.getStatus(), equalTo(200));
}
public void deleteAndVerifyConfig(String configName) {
- Response response = post(URL_CONFIGS + "/config/" + configName + "/delete-config");
+ Response response = managementClient.post(URL_CONFIGS + "/config/" + configName + "/delete-config");
assertThat(response.getStatus(), equalTo(200));
- response = get(URL_CONFIGS + "/config/" + configName);
- assertEquals(404, response.getStatus());
+ response = managementClient.get(URL_CONFIGS + "/config/" + configName);
+ assertThat(response.getStatus(), equalTo(404));
}
public String createCluster() {
@@ -166,48 +132,46 @@
public void createCluster(final String clusterName) {
Map<String, String> newCluster = Map.of("id", clusterName);
- Response response = post(URL_CLUSTER, newCluster);
+ Response response = managementClient.post(URL_CLUSTER, newCluster);
assertThat(response.getStatus(), equalTo(200));
}
public void startCluster(String clusterName) {
- Response response = post(URL_CLUSTER + "/" + clusterName + "/start-cluster");
+ Response response = managementClient.post(URL_CLUSTER + "/" + clusterName + "/start-cluster");
assertThat(response.getStatus(), equalTo(200));
}
public void stopCluster(String clusterName) {
- Response response = post(URL_CLUSTER + "/" + clusterName + "/stop-cluster");
+ Response response = managementClient.post(URL_CLUSTER + "/" + clusterName + "/stop-cluster");
assertThat(response.getStatus(), equalTo(200));
}
public void createClusterInstance(final String clusterName, final String instanceName) {
- Response response = post("domain/create-instance",
+ Response response = managementClient.post("/domain/create-instance",
Map.of("cluster", clusterName, "id", instanceName, "node", "localhost-domain1"));
assertThat(response.getStatus(), equalTo(200));
}
public void deleteCluster(String clusterName) {
- Response response = get(URL_CLUSTER + "/" + clusterName + "/list-instances");
- Map body = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
- Map extraProperties = (Map) body.get("extraProperties");
+ Response response = managementClient.get(URL_CLUSTER + "/" + clusterName + "/list-instances");
+ Map<String, ?> body = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
+ Map<String, ?> extraProperties = (Map<String, ?>) body.get("extraProperties");
if (extraProperties != null) {
List<Map<String, String>> instanceList = (List<Map<String, String>>) extraProperties.get("instanceList");
+ LOG.log(Level.INFO, "Found instances: {0}", instanceList);
if (instanceList != null && !instanceList.isEmpty()) {
for (Map<String, String> instance : instanceList) {
- String status = instance.get("status");
String instanceName = instance.get("name");
- if (!"NOT_RUNNING".equalsIgnoreCase(status)) {
- response = post("domain/servers/server/" + instanceName + "/stop-instance");
- assertThat(response.getStatus(), equalTo(200));
- }
- response = delete("domain/servers/server/" + instanceName + "/delete-instance");
- assertThat(response.getStatus(), equalTo(200));
+ response = managementClient.post("/domain/servers/server/" + instanceName + "/stop-instance");
+ assertThat(instanceName, response.getStatus(), equalTo(200));
+ response = managementClient.delete("/domain/servers/server/" + instanceName + "/delete-instance");
+ assertThat(instanceName, response.getStatus(), equalTo(200));
}
}
}
- response = delete(URL_CLUSTER + "/" + clusterName);
+ response = managementClient.delete(URL_CLUSTER + "/" + clusterName);
assertEquals(200, response.getStatus());
- response = get(URL_CLUSTER + "/" + clusterName);
+ response = managementClient.get(URL_CLUSTER + "/" + clusterName);
assertEquals(404, response.getStatus());
}
@@ -217,36 +181,25 @@
"contextroot", contextRoot,
"name", name
);
- Response response = postWithUpload(URL_APPLICATION_DEPLOY, app);
+ Response response = managementClient.postWithUpload(URL_APPLICATION_DEPLOY, app);
assertThat(response.getStatus(), equalTo(200));
- return getEntityValues(get(URL_APPLICATION_DEPLOY + "/" + app.get("name")));
+ return getEntityValues(managementClient.get(URL_APPLICATION_DEPLOY + "/" + app.get("name")));
}
public void addAppRef(final String applicationName, final String targetName){
- Response response = post("domain/servers/server/" + targetName + "/application-ref",
+ Response response = managementClient.post("/domain/servers/server/" + targetName + "/application-ref",
Map.of("id", applicationName, "target", targetName));
assertThat(response.getStatus(), equalTo(200));
}
public Response undeployApp(String appName) {
- Response response = delete(URL_APPLICATION_DEPLOY + "/" + appName);
+ Response response = managementClient.delete(URL_APPLICATION_DEPLOY + "/" + appName);
assertThat(response.getStatus(), equalTo(200));
return response;
}
- protected <T> T getTestClass(Class<T> clazz) {
- try {
- T test = clazz.getDeclaredConstructor().newInstance();
- ((RestTestBase) test).setup();
- return test;
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
-
protected static String generateRandomString() {
SecureRandom random = new SecureRandom();
-
return new BigInteger(130, random).toString(16);
}
@@ -260,11 +213,6 @@
return Math.abs(r.nextInt(max - 1)) + 1;
}
- protected String getResponseType() {
- return RESPONSE_TYPE;
- }
-
-
protected static String getBaseAdminUrl() {
return baseAdminUrl;
}
@@ -274,100 +222,6 @@
}
- protected String getContextRoot() {
- return CONTEXT_ROOT_MANAGEMENT;
- }
-
- protected String getAddress(String address) {
- if (address.startsWith("http://")) {
- return address;
- }
-
- return baseAdminUrl + getContextRoot() + '/' + address;
- }
-
- protected Client getClient() {
- if (client == null) {
- client = new ClientWrapper(new HashMap<String, String>(), ADMIN_USER, ADMIN_PASSWORD);
- client.register(LoggingFeature.builder().withLogger(Logger.getLogger("CLIENT")).level(Level.FINE).verbosity(Verbosity.PAYLOAD_TEXT).separator("\n").build());
- }
- return client;
- }
-
- protected Response get(String address) {
- return get(address, new HashMap<String, String>());
- }
-
- protected Response get(String address, Map<String, String> payload) {
- WebTarget target = getClient().target(getAddress(address));
- for (Map.Entry<String, String> entry : payload.entrySet()) {
- target = target.queryParam(entry.getKey(), entry.getValue());
- }
- return target.request(getResponseType())
- .get(Response.class);
- }
-
- protected Response options(String address) {
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- options(Response.class);
- }
-
- protected Response post(String address, Map<String, String> payload) {
- return post(address, buildMultivaluedMap(payload));
- }
-
- protected Response post(String address, MultivaluedMap<String, String> payload) {
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- post(Entity.entity(payload, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
- }
-
- protected Response post(String address) {
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- post(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
- }
-
- protected Response put(String address, Map<String, String> payload) {
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- put(Entity.entity(buildMultivaluedMap(payload), MediaType.APPLICATION_FORM_URLENCODED), Response.class);
- }
-
- protected Response put(String address) {
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- put(Entity.entity(null, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
- }
-
- protected Response postWithUpload(String address, Map<String, Object> payload) {
- FormDataMultiPart form = new FormDataMultiPart();
- for (Map.Entry<String, Object> entry : payload.entrySet()) {
- if (entry.getValue() instanceof File) {
- form.getBodyParts().
- add((new FileDataBodyPart(entry.getKey(), (File) entry.getValue())));
- } else {
- form.field(entry.getKey(), entry.getValue(), MediaType.TEXT_PLAIN_TYPE);
- }
- }
- return getClient().target(getAddress(address)).
- request(getResponseType()).
- post(Entity.entity(form, MediaType.MULTIPART_FORM_DATA), Response.class);
- }
-
- protected Response delete(String address) {
- return delete(address, new HashMap<String, String>());
- }
-
- protected Response delete(String address, Map<String, String> payload) {
- WebTarget target = getClient().target(getAddress(address));
- for (Map.Entry<String, String> entry : payload.entrySet()) {
- target = target.queryParam(entry.getKey(), entry.getValue());
- }
- return target.request(getResponseType()).delete(Response.class);
- }
-
/**
* This method will parse the provided XML document and return a map of the attributes and values on the root
* element
@@ -396,7 +250,6 @@
if (message != null && !"".equals(message)) {
results.add(message);
}
-
Object children = map.get("children");
if (children instanceof List) {
for (Object child : (List) children) {
@@ -407,7 +260,6 @@
}
}
}
-
return results;
}
@@ -422,18 +274,8 @@
return new HashMap<>();
}
- public Document getDocument(String input) {
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(new ByteArrayInputStream(input.getBytes()));
- return doc;
- } catch (Exception ex) {
- return null;
- }
- }
- public List<Map<String, String>> getProperties(Response response) {
+ protected List<Map<String, String>> getProperties(Response response) {
Map responseMap = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
Map extraProperties = (Map) responseMap.get("extraProperties");
if (extraProperties != null) {
@@ -442,38 +284,6 @@
return new ArrayList<>();
}
- private MultivaluedMap<String, String> buildMultivaluedMap(Map<String, String> payload) {
- MultivaluedMap<String, String> formData = new MultivaluedHashMap<>();
- if (payload != null) {
- for (final Entry<String, String> entry : payload.entrySet()) {
- formData.add(entry.getKey(), entry.getValue());
- }
- }
- return formData;
- }
-
- protected String getErrorMessage(Response cr) {
- String message = null;
- Map map = MarshallingUtils.buildMapFromDocument(cr.readEntity(String.class));
- if (map != null) {
- message = (String) map.get("message");
- }
-
- return message;
- }
-
- protected static String getParameter(String paramName, String defaultValue) {
- String value = System.getenv(paramName);
- if (value == null) {
- value = System.getProperty(paramName);
- }
- if (value == null) {
- value = defaultValue;
- }
-
- return value;
- }
-
protected static File getEar(final String appName) {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class).addAsModule(getWar(appName), "simple.war");
@@ -498,5 +308,4 @@
throw new IllegalStateException("Deployment failed - cannot load the input archive!", e);
}
}
-
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java
index a5e79f4..a68d242 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java
@@ -23,9 +23,9 @@
import java.util.List;
import java.util.Map;
-import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.junit.jupiter.api.Test;
+import static org.glassfish.admin.rest.client.utils.MarshallingUtils.buildMapFromDocument;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -33,33 +33,39 @@
* @author jasonlee
*/
public class SystemPropertiesITest extends RestTestBase {
- public static final String URL_CONFIG_SYSTEM_PROPERTIES = "domain/configs/config/%config%/system-properties";
- public static final String URL_CLUSTER_SYSTEM_PROPERTIES = "domain/clusters/cluster/%clusterName%/system-properties";
- public static final String URL_INSTANCE_SYSTEM_PROPERTIES = "domain/servers/server/%instanceName%/system-properties";
+ public static final String URL_CONFIG_SYSTEM_PROPERTIES = "/domain/configs/config/%config%/system-properties";
+ public static final String URL_CLUSTER_SYSTEM_PROPERTIES = "/domain/clusters/cluster/%clusterName%/system-properties";
+ public static final String URL_INSTANCE_SYSTEM_PROPERTIES = "/domain/servers/server/%instanceName%/system-properties";
public static final String URL_DAS_SYSTEM_PROPERTIES = URL_INSTANCE_SYSTEM_PROPERTIES.replaceAll("%instanceName%", "server");
- public static final String URL_CREATE_INSTANCE = "domain/create-instance";
+ public static final String URL_CREATE_INSTANCE = "/domain/create-instance";
public static final String PROP_VALUE = "${com.sun.aas.instanceRoot}/foo";
@Test
public void getSystemProperties() {
- Response response = get(URL_DAS_SYSTEM_PROPERTIES);
+ Response response = managementClient.get(URL_DAS_SYSTEM_PROPERTIES);
assertEquals(200, response.getStatus());
- List<Map<String, String>> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ List<Map<String, String>> systemProperties = getSystemProperties(
+ buildMapFromDocument(response.readEntity(String.class)));
assertNotNull(systemProperties);
}
+
@Test
public void createSystemProperties() {
final String prop1 = "property" + generateRandomString();
final String prop2 = "property" + generateRandomString();
- Map<String, String> payload = new HashMap<>() {{
- put(prop1, "value1");
- put(prop2, "value2");
- }};
- Response response = post(URL_DAS_SYSTEM_PROPERTIES, payload);
+ Map<String, String> payload = new HashMap<>() {
+
+ {
+ put(prop1, "value1");
+ put(prop2, "value2");
+ }
+ };
+ Response response = managementClient.post(URL_DAS_SYSTEM_PROPERTIES, payload);
assertEquals(200, response.getStatus());
- response = get(URL_DAS_SYSTEM_PROPERTIES);
- List<Map<String, String>> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ response = managementClient.get(URL_DAS_SYSTEM_PROPERTIES);
+ List<Map<String, String>> systemProperties = getSystemProperties(
+ buildMapFromDocument(response.readEntity(String.class)));
assertNotNull(systemProperties);
int testPropsFound = 0;
@@ -72,9 +78,9 @@
assertEquals(2, testPropsFound);
- response = delete(URL_DAS_SYSTEM_PROPERTIES+"/"+prop1);
+ response = managementClient.delete(URL_DAS_SYSTEM_PROPERTIES+"/"+prop1);
assertEquals(200, response.getStatus());
- response = delete(URL_DAS_SYSTEM_PROPERTIES+"/"+prop2);
+ response = managementClient.delete(URL_DAS_SYSTEM_PROPERTIES+"/"+prop2);
assertEquals(200, response.getStatus());
}
@@ -84,11 +90,11 @@
Map<String, String> payload = new HashMap<>() {{
put(prop1, "http://localhost:4848");
}};
- Response response = post(URL_DAS_SYSTEM_PROPERTIES, payload);
+ Response response = managementClient.post(URL_DAS_SYSTEM_PROPERTIES, payload);
assertEquals(200, response.getStatus());
- response = get(URL_DAS_SYSTEM_PROPERTIES);
+ response = managementClient.get(URL_DAS_SYSTEM_PROPERTIES);
List<Map<String, String>> systemProperties = getSystemProperties(
- MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ buildMapFromDocument(response.readEntity(String.class)));
assertNotNull(systemProperties);
int testPropsFound = 0;
@@ -101,7 +107,7 @@
assertEquals(1, testPropsFound);
- response = delete(URL_DAS_SYSTEM_PROPERTIES + "/" + prop1);
+ response = managementClient.delete(URL_DAS_SYSTEM_PROPERTIES + "/" + prop1);
assertEquals(200, response.getStatus());
}
@@ -117,7 +123,7 @@
final String instanceName = "in" + generateRandomNumber();
final String propertyName = "property" + generateRandomString();
- Response response = post(URL_CREATE_INSTANCE, Map.of("id", instanceName, "node", "localhost-domain1"));
+ Response response = managementClient.post(URL_CREATE_INSTANCE, Map.of("id", instanceName, "node", "localhost-domain1"));
assertEquals(200, response.getStatus());
createAndTestConfigProperty(propertyName, PROP_VALUE, instanceName + "-config");
@@ -127,8 +133,8 @@
@Test
public void testNotResolvingClusterProperties() {
final String propertyName = "property" + generateRandomString();
- final String clusterName = "c" + generateRandomNumber();
- final String instanceName = clusterName + "in" + generateRandomNumber();
+ final String clusterName = "cluster_" + generateRandomNumber();
+ final String instanceName = clusterName + "_instance_" + generateRandomNumber();
createCluster(clusterName);
createClusterInstance(clusterName, instanceName);
@@ -141,14 +147,14 @@
private void createAndTestConfigProperty(final String propertyName, final String propertyValue, String configName) {
final String url = URL_CONFIG_SYSTEM_PROPERTIES.replaceAll("%config%", configName);
- Response response = get(url);
- Map<String, String> payload = getSystemPropertiesMap(getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))));
+ Response response = managementClient.get(url);
+ Map<String, String> payload = getSystemPropertiesMap(getSystemProperties(buildMapFromDocument(response.readEntity(String.class))));
payload.put(propertyName, propertyValue);
- response = post(url, payload);
+ response = managementClient.post(url, payload);
assertEquals(200, response.getStatus());
- response = get(url);
- List<Map<String, String>> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ response = managementClient.get(url);
+ List<Map<String, String>> systemProperties = getSystemProperties(buildMapFromDocument(response.readEntity(String.class)));
Map<String, String> sysProp = getSystemProperty(propertyName, systemProperties);
assertNotNull(sysProp);
assertEquals(propertyValue, sysProp.get("value"));
@@ -157,18 +163,18 @@
private void createAndTestClusterOverride(final String propertyName, final String defaultValue, final String propertyValue, final String clusterName) {
final String clusterSysPropsUrl = URL_CLUSTER_SYSTEM_PROPERTIES.replaceAll("%clusterName%", clusterName);
- Response response = get(clusterSysPropsUrl);
- List<Map<String, String>> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ Response response = managementClient.get(clusterSysPropsUrl);
+ List<Map<String, String>> systemProperties = getSystemProperties(buildMapFromDocument(response.readEntity(String.class)));
Map<String, String> sysProp = getSystemProperty(propertyName, systemProperties);
assertNotNull(sysProp);
assertEquals(sysProp.get("defaultValue"), defaultValue);
- response = post(clusterSysPropsUrl, Map.of(propertyName, propertyValue));
+ response = managementClient.post(clusterSysPropsUrl, Map.of(propertyName, propertyValue));
assertEquals(200, response.getStatus());
// Check updated/overriden system property
- response = get(clusterSysPropsUrl);
- systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ response = managementClient.get(clusterSysPropsUrl);
+ systemProperties = getSystemProperties(buildMapFromDocument(response.readEntity(String.class)));
sysProp = getSystemProperty(propertyName, systemProperties);
assertNotNull(sysProp);
assertEquals(sysProp.get("value"), propertyValue);
@@ -178,18 +184,18 @@
private void createAndTestInstanceOverride(final String propertyName, final String defaultValue, final String propertyValue, final String instanceName) {
final String instanceSysPropsUrl = URL_INSTANCE_SYSTEM_PROPERTIES.replaceAll("%instanceName%", instanceName);
- Response response = get(instanceSysPropsUrl);
- List<Map<String, String>> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ Response response = managementClient.get(instanceSysPropsUrl);
+ List<Map<String, String>> systemProperties = getSystemProperties(buildMapFromDocument(response.readEntity(String.class)));
Map<String, String> sysProp = getSystemProperty(propertyName, systemProperties);
assertNotNull(sysProp);
assertEquals(sysProp.get("defaultValue"), defaultValue);
- response = post(instanceSysPropsUrl, Map.of(propertyName, propertyValue));
+ response = managementClient.post(instanceSysPropsUrl, Map.of(propertyName, propertyValue));
assertEquals(200, response.getStatus());
// Check updated/overriden system property
- response = get(instanceSysPropsUrl);
- systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)));
+ response = managementClient.get(instanceSysPropsUrl);
+ systemProperties = getSystemProperties(buildMapFromDocument(response.readEntity(String.class)));
sysProp = getSystemProperty(propertyName, systemProperties);
assertNotNull(sysProp);
assertEquals(propertyValue, sysProp.get("value"));
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java
index 92a3619..db2456d 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java
@@ -17,21 +17,19 @@
package org.glassfish.nucleus.admin.rest;
-import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Cookie;
import jakarta.ws.rs.core.Response;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.HashMap;
import java.util.Map;
import org.glassfish.admin.rest.client.ClientWrapper;
import org.glassfish.admin.rest.client.utils.MarshallingUtils;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.junit.jupiter.api.AfterEach;
+import org.glassfish.nucleus.test.tool.DomainAdminRestClient;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -39,85 +37,85 @@
* @author Mitesh Meswani
*/
public class TokenAuthenticationITest extends RestTestBase {
- private static final String URL_DOMAIN_SESSIONS = "sessions";
- private static final String URL_CREATE_USER = "domain/configs/config/server-config/security-service/auth-realm/admin-realm/create-user";
- private static final String URL_DELETE_USER = "domain/configs/config/server-config/security-service/auth-realm/admin-realm/delete-user";
+ private static final String URL_DOMAIN_SESSIONS = "/sessions";
+ private static final String URL_CREATE_USER = "/domain/configs/config/server-config/security-service/auth-realm/admin-realm/create-user";
+ private static final String URL_DELETE_USER = "/domain/configs/config/server-config/security-service/auth-realm/admin-realm/delete-user";
private static final String GF_REST_TOKEN_COOKIE_NAME = "gfresttoken";
- private static final String TEST_GROUP = "newgroup";
private static final String AUTH_USER_NAME = "dummyuser";
private static final String AUTH_PASSWORD = "dummypass";
private static final HttpAuthenticationFeature AUTH_DUMMY = HttpAuthenticationFeature.basic(AUTH_USER_NAME, AUTH_PASSWORD);
- private static final HttpAuthenticationFeature AUTH_NONE = HttpAuthenticationFeature.digest();
- private final DummyClient client = new DummyClient();
-
- @AfterEach
- public void closeClient() throws Exception {
- if (client != null) {
- client.close();
- }
+ @AfterAll
+ public static void cleanup() {
+ managementClient.delete(URL_DELETE_USER, Map.of("id", AUTH_USER_NAME));
}
@Test
public void testTokenCreateAndDelete() {
- String token = getSessionToken(this);
+ String token = getSessionToken(managementClient);
assertNotNull(token, "token");
// Verify we can use the session token.
- Response response = getClient().target(getAddress("domain")).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).get(Response.class);
+ Response response = managementClient.getRequestBuilder("/domain")
+ .cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).get(Response.class);
assertEquals(200, response.getStatus());
// Delete the token
- response = getClient().target(getAddress(URL_DOMAIN_SESSIONS) + "/" + token).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).delete(Response.class);
- delete(URL_DOMAIN_SESSIONS);
+ response = managementClient.getRequestBuilder(URL_DOMAIN_SESSIONS + "/" + token)
+ .cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).delete(Response.class);
+ managementClient.delete(URL_DOMAIN_SESSIONS);
assertEquals(200, response.getStatus());
}
+
@Test
public void testAuthRequired() {
- String token = null;
- try {
- deleteUserAuthTestUser(null);
+ Response delResponse = managementClient.delete(URL_DELETE_USER, Map.of("id", AUTH_USER_NAME));
+ // as of gf6 any error means 500. The user doesn't exist.
+ assertEquals(500, delResponse.getStatus());
- // Verify that we can get unauthenticated access to the server
- Response response = client.get("domain");
+ try (DummyClient client = new DummyClient()) {
+ Response response = client.get("/domain");
assertEquals(401, response.getStatus());
-
+ }
+ {
// Create the new user
Map<String, String> newUser = Map.of(
"id", AUTH_USER_NAME,
"groups", "asadmin",
"authrealmname", "admin-realm",
"AS_ADMIN_USERPASSWORD", AUTH_PASSWORD
- );
- response = post(URL_CREATE_USER, newUser);
- assertEquals(200, response.getStatus());
-
- // Verify that we must now authentication (response.status = 401)
- response = client.get("domain");
+ );
+ Response createUserResponse = managementClient.post(URL_CREATE_USER, newUser);
+ assertEquals(200, createUserResponse.getStatus());
+ }
+ try (AnonymousClient client = new AnonymousClient()) {
+ Response response = client.getRequestBuilder("/domain").get(Response.class);
assertEquals(401, response.getStatus());
+ }
+ final String token;
+ try (DummyClient dummyClient = new DummyClient()) {
+ token = getSessionToken(dummyClient);
+ }
- // Authenticate, get the token, then "clear" the authentication
- client.getClient().register(AUTH_DUMMY);
- token = getSessionToken(client);
- client.resetClient();
-
- // Build this request manually so we can pass the cookie
- response = client.getClient().target(getAddress("domain")).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).get(Response.class);
+ try (CookieClient cookieClient = new CookieClient(token)) {
+ Response response = cookieClient.get("/domain");
assertEquals(200, response.getStatus());
- client.resetClient();
-
- // Request again w/o the cookie. This should fail.
- response = client.getClient().target(getAddress("domain")).request().get(Response.class);
+ }
+ try (AnonymousClient client = new AnonymousClient()) {
+ Response response = client.getRequestBuilder("/domain").get(Response.class);
assertEquals(401, response.getStatus());
- } finally {
- deleteUserAuthTestUser(token);
+ }
+ try (CookieClient cookieClient = new CookieClient(token)) {
+ Response response = cookieClient.delete(URL_DELETE_USER, Map.of("id", AUTH_USER_NAME));
+ assertEquals(200, response.getStatus());
}
}
- private String getSessionToken(RestTestBase client) {
+
+ private String getSessionToken(DomainAdminRestClient client) {
Response response = client.post(URL_DOMAIN_SESSIONS);
assertEquals(200, response.getStatus());
Map<String, ?> responseMap = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class));
@@ -125,48 +123,50 @@
return (String) extraProperties.get("token");
}
- private void deleteUserAuthTestUser(String token) {
- if (token == null) {
- Response response = delete(URL_DELETE_USER, Map.of("id", AUTH_USER_NAME));
- if (response.getStatus() == 401) {
- response = delete(URL_DELETE_USER, Map.of("id", AUTH_USER_NAME));
- assertEquals(200, response.getStatus());
- }
- } else {
- final String address = getAddress(URL_DELETE_USER);
- Response response = getClient().target(address).queryParam("id", AUTH_USER_NAME).request()
- .cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).delete(Response.class);
- assertEquals(200, response.getStatus());
+
+ private static final class AnonymousClient extends DomainAdminRestClient {
+
+ public AnonymousClient() {
+ super(new ClientWrapper(), managementClient.getBaseUrl(), APPLICATION_JSON);
}
}
- private static class DummyClient extends RestTestBase implements Closeable {
+ private static final class DummyClient extends DomainAdminRestClient {
- Client client;
+ public DummyClient() {
+ super(createClient(), managementClient.getBaseUrl(), APPLICATION_JSON);
+ }
- @Override
- protected Client getClient() {
- if (client == null) {
- client = new ClientWrapper(new HashMap<String, String>(), null, null);
- }
+ private static ClientWrapper createClient() {
+ ClientWrapper client = new ClientWrapper();
+ client.register(AUTH_DUMMY);
return client;
}
+ }
+ private static final class CookieClient extends DomainAdminRestClient {
+
+ private final String securityCookie;
+
+ public CookieClient(final String securityCookie) {
+ super(new ClientWrapper(), managementClient.getBaseUrl(), APPLICATION_JSON);
+ this.securityCookie = securityCookie;
+ }
+
@Override
- protected void resetClient() {
- if (client == null) {
- return;
- }
- client.close();
- client = null;
+ public Response delete(final String relativePath, final Map<String, String> queryParams) {
+ return getTarget(relativePath, queryParams).request()
+ .cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, securityCookie)).delete(Response.class);
}
@Override
- public void close() throws IOException {
- resetClient();
+ public Response get(final String relativePath, final Map<String, String> queryParams) {
+ return getTarget(relativePath, queryParams).request()
+ .cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, securityCookie)).get(Response.class);
}
+
}
}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java
index 5016830..5e3da6b 100644
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java
@@ -37,15 +37,16 @@
* @author jdlee
*/
public class ZeroConfigITest extends RestTestBase {
- public static final String BASE_SERVER_CONFIG_URL = "domain/configs/config/server-config";
+ public static final String BASE_SERVER_CONFIG_URL = "/domain/configs/config/server-config";
+
/**
* Currently (6/29/2012), the transaction-service element is missing from
- * server-config out of the box. This should continue to be the case once
+ * server-config stdOut of the box. This should continue to be the case once
* zero-config is fully implemented and integrated.
*/
@Test
public void testTransactionService() {
- final Response response = get(BASE_SERVER_CONFIG_URL + "/transaction-service");
+ final Response response = managementClient.get(BASE_SERVER_CONFIG_URL + "/transaction-service");
assertEquals(200, response.getStatus());
Map<String, String> entity = getEntityValues(response);
assertNotNull(entity);
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/AsadminResultMatcher.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/AsadminResultMatcher.java
new file mode 100644
index 0000000..960ae54
--- /dev/null
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/AsadminResultMatcher.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2022 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.nucleus.test.tool;
+
+import org.glassfish.nucleus.test.tool.asadmin.Asadmin;
+import org.glassfish.nucleus.test.tool.asadmin.AsadminResult;
+import org.hamcrest.CustomTypeSafeMatcher;
+
+
+/**
+ * Matcher checking that {@link Asadmin} command succeeded. Prints it's output otherwise.
+ *
+ * @author David Matejcek
+ */
+public class AsadminResultMatcher extends CustomTypeSafeMatcher<AsadminResult> {
+
+ private AsadminResultMatcher() {
+ super("asadmin succeeded");
+ }
+
+
+ @Override
+ protected boolean matchesSafely(AsadminResult item) {
+ return !item.isError();
+ }
+
+
+ /**
+ * @return matcher checking that {@link Asadmin} command succeeded. Prints it's output otherwise.
+ */
+ public static AsadminResultMatcher asadminOK() {
+ return new AsadminResultMatcher();
+ }
+}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainAdminRestClient.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainAdminRestClient.java
new file mode 100644
index 0000000..0c86fb7
--- /dev/null
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainAdminRestClient.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2022 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.nucleus.test.tool;
+
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation.Builder;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MultivaluedHashMap;
+import jakarta.ws.rs.core.MultivaluedMap;
+import jakarta.ws.rs.core.Response;
+
+import java.io.Closeable;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.glassfish.admin.rest.client.ClientWrapper;
+import org.glassfish.jersey.media.multipart.FormDataMultiPart;
+import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
+import org.glassfish.nucleus.test.tool.asadmin.GlassFishTestEnvironment;
+
+import static jakarta.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED;
+
+/**
+ * @author David Matejcek
+ */
+public class DomainAdminRestClient implements Closeable {
+
+ private final ClientWrapper client;
+ private final String baseUrl;
+ private final String responseType;
+
+ public DomainAdminRestClient(final String baseUrl) {
+ this(baseUrl, MediaType.APPLICATION_JSON);
+ }
+
+
+ public DomainAdminRestClient(final String baseUrl, final String responseType) {
+ this(GlassFishTestEnvironment.createClient(), baseUrl, responseType);
+ }
+
+
+ public DomainAdminRestClient(final ClientWrapper client, final String baseUrl, final String responseType) {
+ this.client = client;
+ this.baseUrl = baseUrl;
+ this.responseType = responseType;
+ }
+
+
+ /**
+ * @return http://localhost:4848/management or something else, see constructor.
+ */
+ public final String getBaseUrl() {
+ return baseUrl;
+ }
+
+
+ public Response options(final String relativePath) {
+ return getRequestBuilder(relativePath).options(Response.class);
+ }
+
+
+ public Response get(final String relativePath) {
+ return get(relativePath, new HashMap<String, String>());
+ }
+
+
+ public Response get(final String relativePath, final Map<String, String> queryParams) {
+ final WebTarget target = getTarget(relativePath, queryParams);
+ return target.request(responseType).get(Response.class);
+ }
+
+ public <T> Response put(final String relativePath, final Entity<T> entityPayload) {
+ return getRequestBuilder(relativePath).put(entityPayload, Response.class);
+ }
+
+
+ public Response post(final String relativePath) {
+ return getRequestBuilder(relativePath).post(Entity.entity(null, APPLICATION_FORM_URLENCODED), Response.class);
+ }
+
+
+ public Response post(final String relativePath, final Map<String, String> payload) {
+ return post(relativePath, buildMultivaluedMap(payload));
+ }
+
+
+ public Response post(final String relativePath, final MultivaluedMap<String, String> payload) {
+ return getRequestBuilder(relativePath).post(Entity.entity(payload, APPLICATION_FORM_URLENCODED), Response.class);
+ }
+
+
+ public <T> Response post(final String relativePath, final Entity<T> entityPayload) {
+ return getRequestBuilder(relativePath).post(entityPayload, Response.class);
+ }
+
+ public Response postWithUpload(final String relativePath, final Map<String, Object> payload) {
+ final FormDataMultiPart form = new FormDataMultiPart();
+ for (final Map.Entry<String, Object> entry : payload.entrySet()) {
+ if (entry.getValue() instanceof File) {
+ form.getBodyParts().add((new FileDataBodyPart(entry.getKey(), (File) entry.getValue())));
+ } else {
+ form.field(entry.getKey(), entry.getValue(), MediaType.TEXT_PLAIN_TYPE);
+ }
+ }
+ return getRequestBuilder(relativePath).post(Entity.entity(form, MediaType.MULTIPART_FORM_DATA), Response.class);
+ }
+
+
+ public Response delete(final String relativePath) {
+ return delete(relativePath, new HashMap<String, String>());
+ }
+
+ public Response delete(final String relativePath, final Map<String, String> queryParams) {
+ final WebTarget target = getTarget(relativePath, queryParams);
+ return target.request(responseType).delete(Response.class);
+ }
+
+
+ public Builder getRequestBuilder(final String relativePath) {
+ return getTarget(relativePath, null).request(responseType);
+ }
+
+
+ public WebTarget getTarget(final String relativePath, final Map<String, String> queryParams) {
+ WebTarget target = client.target(baseUrl + relativePath);
+ if (queryParams == null) {
+ return target;
+ }
+ for (final Map.Entry<String, String> entry : queryParams.entrySet()) {
+ target = target.queryParam(entry.getKey(), entry.getValue());
+ }
+ return target;
+ }
+
+
+ @Override
+ public void close() {
+ client.close();
+ }
+
+
+ private MultivaluedMap<String, String> buildMultivaluedMap(final Map<String, String> payload) {
+ final MultivaluedMap<String, String> formData = new MultivaluedHashMap<>();
+ if (payload != null) {
+ for (final Entry<String, String> entry : payload.entrySet()) {
+ formData.add(entry.getKey(), entry.getValue());
+ }
+ }
+ return formData;
+ }
+}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainLifecycleExtension.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainLifecycleExtension.java
deleted file mode 100644
index 866c4a0..0000000
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/DomainLifecycleExtension.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2022 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.nucleus.test.tool;
-
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-
-/**
- * @author David Matejcek
- */
-public class DomainLifecycleExtension extends StopDomainExtension implements BeforeAllCallback {
-
-
- @Override
- public void beforeAll(ExtensionContext context) throws Exception {
- NucleusTestUtils.nadmin(20000, "start-domain", "--debug", "domain1");
- }
-}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/NucleusTestUtils.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/NucleusTestUtils.java
deleted file mode 100644
index 0072006..0000000
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/NucleusTestUtils.java
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * Copyright (c) 2022 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.nucleus.test.tool;
-
-import com.sun.enterprise.universal.process.ProcessManager;
-import com.sun.enterprise.universal.process.ProcessManagerException;
-import com.sun.enterprise.universal.process.ProcessManagerTimeoutException;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Locale;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-/**
- * @author David Matejcek
- *
- */
-public class NucleusTestUtils {
- private static final int DEFAULT_TIMEOUT_MSEC = 8 * 60 * 1000;
- public static final String ADMIN_USER = "admin";
- public static final String ADMIN_PASSWORD = "admintest";
- public static final File BASEDIR = getBasedir();
- public static final File GF_ROOT = getGlassFishRoot();
- private static final File PASSWORD_FILE_FOR_UPDATE = getPasswordFile("password_update.txt");
- private static final File PASSWORD_FILE = getPasswordFile("password.txt");
-
- static {
- final NadminReturn result = changePassword();
- if (result.returnValue) {
- System.out.println("Admin password changed.");
- } else {
- // probably changed by previous execution without maven clean
- System.out.println("Admin password NOT changed.");
- }
- }
-
-
- /**
- * Useful for a heuristic inside Eclipse and other environments.
- *
- * @return Absolute path to the glassfish directory.
- */
- private static File getBasedir() {
- String basedir = System.getProperty("basedir");
- if (basedir == null) {
- File target = new File("target");
- if (target.exists()) {
- return target.getAbsoluteFile().getParentFile();
- }
- return new File(".").getAbsoluteFile().getParentFile();
- }
- return new File(basedir);
- }
-
- private static File getGlassFishRoot() {
- System.out.println("Using basedir: " + BASEDIR);
- return BASEDIR.toPath().resolve(Path.of("target", "glassfish6", "glassfish")).toFile();
- }
-
- private static File getPasswordFile(final String filename) {
- try {
- URL url = NucleusTestUtils.class.getResource("/" + filename);
- assertNotNull(url, filename + " not found");
- return Path.of(url.toURI()).toFile().getAbsoluteFile();
- } catch (URISyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
-
- private NucleusTestUtils() {
- // All methods are static, do not allow an object to be created.
- }
-
-
- public static File getNucleusRoot() {
- return GF_ROOT;
- }
-
-
- public static void deleteSubpaths(final Path path) {
- try {
- Files.walk(path).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
- } catch (Exception e) {
- throw new IllegalStateException("Cannot delete path recursively: " + path, e);
- }
- }
-
-
- /**
- * This will delete the jobs.xml file
- */
- public static void deleteJobsFile() {
- Path path = GF_ROOT.toPath().resolve(Paths.get("domains", "domain1", "config", "jobs.xml"));
- System.out.println("Deleting.. " + path);
- try {
- Files.deleteIfExists(path);
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
-
- /**
- * osgi-cache workaround
- */
- public static void deleteOsgiDirectory() {
- Path osgiCacheDir = GF_ROOT.toPath().resolve(Paths.get("domains", "domain1", "osgi-cache"));
- try {
- Files.list(osgiCacheDir).forEach(NucleusTestUtils::deleteSubpaths);
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
-
- public static boolean nadmin(final String... args) {
- return nadmin(DEFAULT_TIMEOUT_MSEC, args);
- }
-
- /**
- * Runs the command with the args given
- *
- * @param args
- *
- * @return true if successful
- */
- public static boolean nadmin(int timeout, final String... args) {
- return nadminWithOutput(timeout, args).returnValue;
- }
-
- /**
- * Runs the command with the args given
- * Returns the precious output strings for further processing.
- *
- * @param args
- *
- * @return true if successful
- */
- public static NadminReturn nadminWithOutput(final String... args) {
- return nadminWithOutput(DEFAULT_TIMEOUT_MSEC, args);
- }
-
-
- public static NadminReturn nadminWithOutput(final int timeout, final String... args) {
- File cmd = new File(GF_ROOT, isWindows() ? "bin/asadmin.bat" : "bin/asadmin");
- return cmdWithOutput(cmd, timeout, args);
- }
-
-
- public static NadminReturn nadminDetachWithOutput(final String... args) {
- File cmd = new File(GF_ROOT, isWindows() ? "bin/asadmin.bat" : "bin/asadmin");
- return cmdDetachWithOutput(cmd, DEFAULT_TIMEOUT_MSEC, args);
- }
-
-
- private static NadminReturn changePassword() {
- File cmd = new File(GF_ROOT, isWindows() ? "bin/asadmin.bat" : "bin/asadmin");
- return cmdWithOutput(cmd, PASSWORD_FILE_FOR_UPDATE, DEFAULT_TIMEOUT_MSEC, "change-admin-password");
- }
-
- public static NadminReturn cmdWithOutput(final File cmd, final int timeout, final String... args) {
- return cmdWithOutput(cmd, PASSWORD_FILE, timeout, args);
- }
-
- public static NadminReturn cmdWithOutput(final File cmd, final File passwordFile, final int timeout, final String... args) {
- List<String> command = new ArrayList<>();
- command.add(cmd.getAbsolutePath());
- command.add("--user");
- command.add(ADMIN_USER);
- command.add("--passwordfile");
- command.add(passwordFile.getAbsolutePath());
- command.addAll(Arrays.asList(args));
-
- ProcessManager pm = new ProcessManager(command);
-
- // the tests may be running unattended -- don't wait forever!
- pm.setTimeoutMsec(timeout);
- pm.setEcho(false);
-
- int exit;
- String myErr = "";
- try {
- exit = pm.execute();
- } catch (ProcessManagerTimeoutException tex) {
- myErr = "\nProcessManagerTimeoutException: command timed out after " + timeout + " ms.";
- exit = 1;
- } catch (ProcessManagerException ex) {
- ex.printStackTrace();
- myErr = "\n" + ex.getMessage();
- exit = 1;
- }
-
- NadminReturn ret = new NadminReturn(exit, pm.getStdout(), pm.getStderr() + myErr, args[0]);
- write(ret.outAndErr);
- return ret;
- }
-
-
- public static NadminReturn cmdDetachWithOutput(final File cmd, final int timeout, final String... args) {
- List<String> command = new ArrayList<>();
- command.add(cmd.getAbsolutePath());
- command.add("--user");
- command.add(ADMIN_USER);
- command.add("--passwordfile");
- command.add(PASSWORD_FILE.getAbsolutePath());
- command.add("--detach");
- command.addAll(Arrays.asList(args));
-
- ProcessManager pm = new ProcessManager(command);
-
- // the tests may be running unattended -- don't wait forever!
- pm.setTimeoutMsec(timeout);
- pm.setEcho(false);
-
- int exit;
- String myErr = "";
- try {
- exit = pm.execute();
- } catch (ProcessManagerTimeoutException tex) {
- myErr = "\nProcessManagerTimeoutException: command timed out after " + timeout + " ms.";
- exit = 1;
- } catch (ProcessManagerException ex) {
- exit = 1;
- }
-
- NadminReturn ret = new NadminReturn(exit, pm.getStdout(), pm.getStderr() + myErr, args[0]);
- write(ret.outAndErr);
- return ret;
- }
-
- private static boolean validResults(String text, String... invalidResults) {
- for (String result : invalidResults) {
- if (text.contains(result)) {
- return false;
- }
- }
- return true;
- }
-
- private static void write(final String text) {
- if (!text.isEmpty()) {
- System.out.print(text);
- }
- }
-
-
- protected static boolean isWindows() {
- return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
- }
-
-
- /**
- * This methods opens a connection to the given URL and
- * returns the string that is returned from that URL. This
- * is useful for simple servlet retrieval
- *
- * @param urlstr The URL to connect to
- * @return The string returned from that URL, or empty
- * string if there was a problem contacting the URL
- */
- public static String getURL(String urlstr) {
- URLConnection urlc = openConnection(urlstr);
- try (
- BufferedReader ir = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "ISO-8859-1"));
- StringWriter ow = new StringWriter();
- ) {
- String line;
- while ((line = ir.readLine()) != null) {
- ow.write(line);
- ow.write("\n");
- }
- return ow.getBuffer().toString();
- } catch (IOException ex) {
- System.out.println("unable to fetch URL:" + urlstr + ", reason: " + ex.getMessage());
- return "";
- }
- }
-
- private static URLConnection openConnection(String url) {
- try {
- return new URL(url).openConnection();
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
-
- public static class NadminReturn {
-
- public boolean returnValue;
- public String out;
- public String err;
- public String outAndErr;
-
- NadminReturn(int exit, String out, String err, String cmd) {
- this.returnValue = exit == 0 && validResults(out,
- String.format("Command %s failed.", cmd));
- this.out = out;
- this.err = err;
- this.outAndErr = this.out + this.err;
- }
- }
-
-}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/StopDomainExtension.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/StopDomainExtension.java
deleted file mode 100644
index ea5699a..0000000
--- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/StopDomainExtension.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2022 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.nucleus.test.tool;
-
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteJobsFile;
-import static org.glassfish.nucleus.test.tool.NucleusTestUtils.deleteOsgiDirectory;
-
-public class StopDomainExtension implements AfterAllCallback {
-
- @Override
- public void afterAll(ExtensionContext context) throws Exception {
- NucleusTestUtils.nadmin(10000, "stop-domain", "domain1");
- deleteJobsFile();
- deleteOsgiDirectory();
- }
-
-}
\ No newline at end of file
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/Asadmin.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/Asadmin.java
new file mode 100644
index 0000000..12da171
--- /dev/null
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/Asadmin.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2022 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.nucleus.test.tool.asadmin;
+
+import com.sun.enterprise.universal.process.ProcessManager;
+import com.sun.enterprise.universal.process.ProcessManagerException;
+import com.sun.enterprise.universal.process.ProcessManagerTimeoutException;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static java.util.Arrays.asList;
+
+/**
+ * Tool for executing asadmin/asadmin.bat commands.
+ * The tool is stateless.
+ *
+ * @author David Matejcek
+ */
+public class Asadmin {
+ private static final Logger LOG = Logger.getLogger(Asadmin.class.getName());
+
+ private static final int DEFAULT_TIMEOUT_MSEC = 10 * 1000;
+
+ private final File asadmin;
+ private final String adminUser;
+ private final File adminPasswordFile;
+
+
+ /**
+ * Creates a stateless instance of the tool.
+ *
+ * @param asadmin - executable file
+ * @param adminUser - username authorized to use the domain
+ * @param adminPasswordFile - a file containing admin's password set as <code>AS_ADMIN_PASSWORD=...</code>
+ */
+ public Asadmin(final File asadmin, final String adminUser, final File adminPasswordFile) {
+ this.asadmin = asadmin;
+ this.adminUser = adminUser;
+ this.adminPasswordFile = adminPasswordFile;
+ }
+
+
+ /**
+ * @return asadmin command file name
+ */
+ public String getCommandName() {
+ return asadmin.getName();
+ }
+
+
+ /**
+ * Executes the command with arguments asynchronously with {@value #DEFAULT_TIMEOUT_MSEC} ms timeout.
+ * The command can be attached by the attach command.
+ * You should find the job id in the {@link AsadminResult#getStdOut()} as <code>Job ID: [0-9]+</code>
+ *
+ * @param args
+ * @return {@link AsadminResult} never null.
+ */
+ public AsadminResult execDetached(final String... args) {
+ return exec(DEFAULT_TIMEOUT_MSEC, true, args);
+ }
+
+ /**
+ * Executes the command with arguments synchronously with {@value #DEFAULT_TIMEOUT_MSEC} ms timeout.
+ *
+ * @param args
+ * @return {@link AsadminResult} never null.
+ */
+ public AsadminResult exec(final String... args) {
+ return exec(DEFAULT_TIMEOUT_MSEC, false, args);
+ }
+
+
+ /**
+ * Executes the command with arguments.
+ *
+ * @param timeout timeout in millis
+ * @param detached - detached command is executed asynchronously, can be attached later by the attach command.
+ * @param args - command and arguments.
+ * @return {@link AsadminResult} never null.
+ */
+ public AsadminResult exec(final int timeout, final boolean detached, final String... args) {
+ final List<String> parameters = asList(args);
+ LOG.log(Level.INFO, "exec(timeout={0}, detached={1}, args={2})", new Object[] {timeout, detached, parameters});
+ final List<String> command = new ArrayList<>();
+ command.add(asadmin.getAbsolutePath());
+ command.add("--user");
+ command.add(adminUser);
+ command.add("--passwordfile");
+ command.add(adminPasswordFile.getAbsolutePath());
+ if (detached) {
+ command.add("--detach");
+ }
+ command.addAll(parameters);
+
+ final ProcessManager pm = new ProcessManager(command);
+ pm.setTimeoutMsec(timeout);
+ pm.setEcho(false);
+
+ int exitCode;
+ String asadminErrorMessage = "";
+ try {
+ exitCode = pm.execute();
+ } catch (final ProcessManagerTimeoutException e) {
+ asadminErrorMessage = "ProcessManagerTimeoutException: command timed stdOut after " + timeout + " ms.\n";
+ exitCode = 1;
+ } catch (final ProcessManagerException e) {
+ LOG.log(Level.SEVERE, "The execution failed.", e);
+ asadminErrorMessage = e.getMessage();
+ exitCode = 1;
+ }
+
+ final String stdErr = pm.getStderr() + '\n' + asadminErrorMessage;
+ final AsadminResult ret = new AsadminResult(args[0], exitCode, pm.getStdout(), stdErr);
+ writeToStdOut(ret.getOutput());
+ return ret;
+ }
+
+
+ private static void writeToStdOut(final String text) {
+ if (!text.isEmpty()) {
+ System.out.print(text);
+ }
+ }
+}
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/AsadminResult.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/AsadminResult.java
new file mode 100644
index 0000000..1850ea5
--- /dev/null
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/AsadminResult.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2022 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.nucleus.test.tool.asadmin;
+
+/**
+ * Result of the {@link Asadmin} execution.
+ *
+ * @author David Matejcek
+ */
+public class AsadminResult {
+
+ private final boolean error;
+ private final String stdOut;
+ private final String stdErr;
+ private final String output;
+
+ /**
+ * Creates a value object instance.
+ *
+ * @param cmd - command name
+ * @param exitCode
+ * @param stdOut
+ * @param stdErr
+ */
+ public AsadminResult(final String cmd, final int exitCode, final String stdOut, final String stdErr) {
+ this.error = exitCode != 0 || containsError(stdOut, String.format("Command %s failed.", cmd));
+ this.stdOut = stdOut;
+ this.stdErr = stdErr;
+ this.output = this.stdOut + this.stdErr;
+ }
+
+
+ /**
+ * @return true if the error code was not zero OR stdOut contained text <i>Command x failed</i>.
+ */
+ public boolean isError() {
+ return error;
+ }
+
+
+ /**
+ * @return standard output made by the command.
+ */
+ public String getStdOut() {
+ return stdOut;
+ }
+
+ /**
+ * @return error output made by the command.
+ */
+ public String getStdErr() {
+ return stdErr;
+ }
+
+
+ /**
+ * @return {@link #getStdOut()} + {@link #getStdErr()}
+ */
+ public String getOutput() {
+ return output;
+ }
+
+
+ /**
+ * Returns {@link #getOutput()}. Important for hamcrest matchers!
+ */
+ @Override
+ public String toString() {
+ return getOutput();
+ }
+
+
+ private static boolean containsError(final String text, final String... invalidResults) {
+ for (final String result : invalidResults) {
+ if (text.contains(result)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/GlassFishTestEnvironment.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/GlassFishTestEnvironment.java
new file mode 100644
index 0000000..a8f057f
--- /dev/null
+++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/tool/asadmin/GlassFishTestEnvironment.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2022 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.nucleus.test.tool.asadmin;
+
+import jakarta.ws.rs.client.Client;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.PasswordAuthentication;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.glassfish.admin.rest.client.ClientWrapper;
+import org.glassfish.nucleus.test.tool.AsadminResultMatcher;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * This class represents GlassFish installation outside test environment.
+ * <p>
+ * Ensures that the domain in executed before first test started, and that the domain stops
+ * after tests are finished.
+ *
+ * @author David Matejcek
+ */
+public class GlassFishTestEnvironment {
+ private static final Logger LOG = Logger.getLogger(GlassFishTestEnvironment.class.getName());
+
+ private static final File BASEDIR = detectBasedir();
+ private static final File GF_ROOT = resolveGlassFishRoot();
+
+ private static final String ADMIN_USER = "admin";
+ private static final String ADMIN_PASSWORD = "admintest";
+
+ private static final File ASADMIN = findAsadmin();
+ private static final File PASSWORD_FILE_FOR_UPDATE = findPasswordFile("password_update.txt");
+ private static final File PASSWORD_FILE = findPasswordFile("password.txt");
+
+
+ static {
+ LOG.log(Level.INFO, "Using basedir: {0}", BASEDIR);
+ LOG.log(Level.INFO, "Expected GlassFish directory: {0}", GF_ROOT);
+ changePassword();
+ Thread hook = new Thread(() -> {
+ getAsadmin().exec(10_000, false, "stop-domain", "--kill", "--force");
+ });
+ Runtime.getRuntime().addShutdownHook(hook);
+ assertThat(getAsadmin().exec(30_000, false, "start-domain"), AsadminResultMatcher.asadminOK());
+ }
+
+ /**
+ * @return {@link Asadmin} command api for tests.
+ */
+ public static Asadmin getAsadmin() {
+ return new Asadmin(ASADMIN, ADMIN_USER, PASSWORD_FILE);
+ }
+
+
+ /**
+ * @return project's target directory.
+ */
+ public static File getTargetDirectory() {
+ return new File(BASEDIR, "target");
+ }
+
+
+ /**
+ * Creates a {@link Client} instance for the domain administrator.
+ * Caller is responsible for closing.
+ *
+ * @return new {@link Client} instance
+ */
+ public static ClientWrapper createClient() {
+ return new ClientWrapper(new HashMap<String, String>(), ADMIN_USER, ADMIN_PASSWORD);
+ }
+
+
+ /**
+ * Creates a {@link HttpURLConnection} for the admin administrator.
+ *
+ * @param context - part of the url behind the <code>http://localhost:4848</code>
+ * @return a new disconnected {@link HttpURLConnection}.
+ * @throws IOException
+ */
+ public static HttpURLConnection openConnection(final String context) throws IOException {
+ final HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:4848" + context)
+ .openConnection();
+ connection.setRequestProperty("X-Requested-By", "JUnit5Test");
+ connection.setAuthenticator(new DasAuthenticator());
+ return connection;
+ }
+
+
+ /**
+ * This will delete the jobs.xml file
+ */
+ public static void deleteJobsFile() {
+ Path path = GF_ROOT.toPath().resolve(Paths.get("domains", "domain1", "config", "jobs.xml"));
+ LOG.log(Level.CONFIG, "Deleting: " + path);
+ try {
+ Files.deleteIfExists(path);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+
+ /**
+ * osgi-cache workaround
+ */
+ public static void deleteOsgiDirectory() {
+ Path osgiCacheDir = GF_ROOT.toPath().resolve(Paths.get("domains", "domain1", "osgi-cache"));
+ try {
+ Files.list(osgiCacheDir).forEach(GlassFishTestEnvironment::deleteSubpaths);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+
+ public static void deleteSubpaths(final Path path) {
+ try {
+ Files.walk(path).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot delete path recursively: " + path, e);
+ }
+ }
+
+
+ /**
+ * Useful for a heuristic inside Eclipse and other environments.
+ *
+ * @return Absolute path to the glassfish directory.
+ */
+ private static File detectBasedir() {
+ final String basedir = System.getProperty("basedir");
+ if (basedir != null) {
+ return new File(basedir);
+ }
+ final File target = new File("target");
+ if (target.exists()) {
+ return target.getAbsoluteFile().getParentFile();
+ }
+ return new File(".").getAbsoluteFile().getParentFile();
+ }
+
+
+ private static File resolveGlassFishRoot() {
+ final File gfDir = BASEDIR.toPath().resolve(Path.of("target", "glassfish6", "glassfish")).toFile();
+ if (gfDir == null || !gfDir.exists()) {
+ throw new IllegalStateException("The expected GlassFish home directory doesn't exist: " + gfDir);
+ }
+ return gfDir;
+ }
+
+
+ private static File findAsadmin() {
+ return new File(GF_ROOT, isWindows() ? "bin/asadmin.bat" : "bin/asadmin");
+ }
+
+
+ private static boolean isWindows() {
+ return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
+ }
+
+
+ private static File findPasswordFile(final String filename) {
+ try {
+ final URL url = Asadmin.class.getResource("/" + filename);
+ if (url == null) {
+ throw new IllegalStateException(filename + " not found");
+ }
+ return Path.of(url.toURI()).toFile().getAbsoluteFile();
+ } catch (final URISyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+
+ private static void changePassword() {
+ final Asadmin asadmin = new Asadmin(ASADMIN, ADMIN_USER, PASSWORD_FILE_FOR_UPDATE);
+ final AsadminResult result = asadmin.exec(5_000, false, "change-admin-password");
+ if (result.isError()) {
+ // probably changed by previous execution without maven clean
+ System.out.println("Admin password NOT changed.");
+ } else {
+ System.out.println("Admin password changed.");
+ }
+ }
+
+ private static class DasAuthenticator extends Authenticator {
+
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(ADMIN_USER, ADMIN_PASSWORD.toCharArray());
+ }
+ }
+}