From f7901c4b7614529a3550bb7d680d0e4bdcf97121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 3 Apr 2022 12:13:11 +0200 Subject: [PATCH] #23507 Fixed admin-tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - now they detect bugs, see next commits - 2 tests are reproducers of bugs I could not fix easily - new test dependency - ShrinkWrap Signed-off-by: David Matějček --- appserver/tests/admin/admin-extension/pom.xml | 20 +- .../progress/ProgressComplexCommand.java | 12 +- .../tests/progress/ProgressCustomCommand.java | 18 +- .../progress/ProgressDoubleTotalsCommand.java | 4 +- .../progress/ProgressExecOtherCommand.java | 15 +- .../progress/ProgressFailInHalfCommand.java | 1 + .../progress/ProgressFullAnnotCommand.java | 2 +- .../progress/ProgressPayloadCommand.java | 9 +- .../tests/progress/ProgressSimpleCommand.java | 1 + .../progress/ProgressStepBackCommand.java | 4 +- .../ProgressWithSupplementCommand.java | 10 +- .../tests/progress/SupplementAfter.java | 1 + .../tests/progress/SupplementBefore.java | 1 + appserver/tests/admin/tests/pom.xml | 47 ++-- .../{ClusterTest.java => ClusterITest.java} | 53 ++--- ...mmandsTest.java => MiscCommandsITest.java} | 2 +- ...mmandsTest.java => OSGiCommandsITest.java} | 70 +++--- .../admin/{RestTest.java => RestITest.java} | 2 +- ...AttachTest.java => DetachAttachITest.java} | 2 +- ...bManagerTest.java => JobManagerITest.java} | 2 +- .../admin/progress/ProgressMessage.java | 36 ++- ...est.java => ProgressStatusBasicITest.java} | 15 +- ...t.java => ProgressStatusComplexITest.java} | 31 ++- ...Test.java => ProgressStatusFailITest.java} | 2 +- ...t.java => ProgressStatusSpecialITest.java} | 20 +- ...icationTest.java => ApplicationITest.java} | 114 +++++----- ...AuthRealmTest.java => AuthRealmITest.java} | 2 +- .../{ClusterTest.java => ClusterITest.java} | 10 +- .../{ConfigTest.java => ConfigITest.java} | 30 +-- .../{DomainTest.java => DomainITest.java} | 8 +- ...entStarTest.java => ElementStarITest.java} | 61 +++--- ...ceTest.java => ExternalResourceITest.java} | 31 ++- .../nucleus/admin/rest/JdbcITest.java | 107 +++++++++ .../nucleus/admin/rest/JdbcTest.java | 117 ---------- .../rest/{JmsTest.java => JmsITest.java} | 205 ++++++------------ ...sourceTest.java => JobsResourceITest.java} | 43 ++-- ...mOptionsTest.java => JvmOptionsITest.java} | 90 ++++---- .../{MetadataTest.java => MetadataITest.java} | 16 +- ...nitoringTest.java => MonitoringITest.java} | 120 ++++++---- ...nerTest.java => NetworkListenerITest.java} | 68 +++--- ...=> NoCLICommandResourceCreationITest.java} | 19 +- ...pdateTest.java => PartialUpdateITest.java} | 17 +- ...esBagTest.java => PropertiesBagITest.java} | 37 ++-- ...ProvidersTest.java => ProvidersITest.java} | 4 +- ...urceRefTest.java => ResourceRefITest.java} | 11 +- .../nucleus/admin/rest/RestTestBase.java | 106 ++++++--- ...esTest.java => SystemPropertiesITest.java} | 19 +- ...est.java => TokenAuthenticationITest.java} | 2 +- ...roConfigTest.java => ZeroConfigITest.java} | 4 +- .../test/tool/DomainLifecycleExtension.java | 2 +- .../nucleus/test/webapp/HelloServlet.java | 38 ++++ nucleus/parent/pom.xml | 6 + 52 files changed, 812 insertions(+), 855 deletions(-) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/{ClusterTest.java => ClusterITest.java} (60%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/{MiscCommandsTest.java => MiscCommandsITest.java} (98%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/{OSGiCommandsTest.java => OSGiCommandsITest.java} (94%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/{RestTest.java => RestITest.java} (99%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{DetachAttachTest.java => DetachAttachITest.java} (99%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{JobManagerTest.java => JobManagerITest.java} (99%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{ProgressStatusBasicTest.java => ProgressStatusBasicITest.java} (88%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{ProgressStatusComplexTest.java => ProgressStatusComplexITest.java} (86%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{ProgressStatusFailTest.java => ProgressStatusFailITest.java} (98%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/{ProgressStatusSpecialTest.java => ProgressStatusSpecialITest.java} (77%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ApplicationTest.java => ApplicationITest.java} (57%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{AuthRealmTest.java => AuthRealmITest.java} (99%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ClusterTest.java => ClusterITest.java} (85%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ConfigTest.java => ConfigITest.java} (59%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{DomainTest.java => DomainITest.java} (85%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ElementStarTest.java => ElementStarITest.java} (61%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ExternalResourceTest.java => ExternalResourceITest.java} (64%) create mode 100644 appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java delete mode 100644 appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcTest.java rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{JmsTest.java => JmsITest.java} (55%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{JobsResourceTest.java => JobsResourceITest.java} (75%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{JvmOptionsTest.java => JvmOptionsITest.java} (75%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{MetadataTest.java => MetadataITest.java} (82%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{MonitoringTest.java => MonitoringITest.java} (54%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{NetworkListenerTest.java => NetworkListenerITest.java} (66%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{NoCLICommandResourceCreationTest.java => NoCLICommandResourceCreationITest.java} (76%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{PartialUpdateTest.java => PartialUpdateITest.java} (83%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{PropertiesBagTest.java => PropertiesBagITest.java} (94%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ProvidersTest.java => ProvidersITest.java} (98%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ResourceRefTest.java => ResourceRefITest.java} (90%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{SystemPropertiesTest.java => SystemPropertiesITest.java} (93%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{TokenAuthenticationTest.java => TokenAuthenticationITest.java} (99%) rename appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/{ZeroConfigTest.java => ZeroConfigITest.java} (95%) create mode 100644 appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/webapp/HelloServlet.java diff --git a/appserver/tests/admin/admin-extension/pom.xml b/appserver/tests/admin/admin-extension/pom.xml index 071b62225cd..11648ba174d 100644 --- a/appserver/tests/admin/admin-extension/pom.xml +++ b/appserver/tests/admin/admin-extension/pom.xml @@ -25,31 +25,33 @@ 6.2.6-SNAPSHOT test-progress-admin-extension - GlassFish Admin Tests - Progress Admin Extension glassfish-jar + + GlassFish Admin Tests - Progress Admin Extension + org.glassfish.main.common glassfish-api ${project.version} + provided org.glassfish.main.common common-util ${project.version} + provided - - org.glassfish.main.admin - config-api - ${project.version} - + org.glassfish.hk2 - hk2 + hk2-api + provided - org.glassfish.hk2 - hk2-junitrunner + jakarta.inject + jakarta.inject-api + provided diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressComplexCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressComplexCommand.java index 8f61b6fa779..7e095aec37b 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressComplexCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressComplexCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -16,24 +17,22 @@ package com.sun.enterprise.tests.progress; -import com.sun.enterprise.config.serverbeans.Domain; import com.sun.logging.LogDomains; -import java.util.logging.Level; + import java.util.logging.Logger; + import org.glassfish.api.I18n; -import org.glassfish.api.Param; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; import org.glassfish.api.admin.CommandLock; import org.glassfish.api.admin.ManagedJob; import org.glassfish.api.admin.Progress; import org.glassfish.api.admin.ProgressStatus; -import org.glassfish.api.admin.RestEndpoint; -import org.glassfish.api.admin.RestEndpoints; import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; -/** Basic progress status example. +/** + * Basic progress status example. * Contains 10 steps * * @author mmares @@ -137,6 +136,7 @@ public ProgressRunnable(ProgressStatus ps, int count, long interval, String mess this.message = message; } + @Override public void run() { doProgress(ps, count, interval, message); } diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressCustomCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressCustomCommand.java index 974c6f125dc..7d30c49a4c4 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressCustomCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressCustomCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -19,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.regex.Pattern; + import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -31,7 +33,6 @@ import org.jvnet.hk2.annotations.Service; /** - * * @author mmares */ @Service(name = "progress-custom") @@ -51,14 +52,14 @@ public class ProgressCustomCommand implements AdminCommand { private static class Interval { private boolean valid = true; - private String origInteval; + private String origInterval; private int multiplicator = 1; private int minSec = -1; private int maxSec = 0; private boolean spin = false; private Interval(String interval) { - origInteval = interval; + origInterval = interval; try { if (!keyPattern.matcher(interval).matches()) { valid = false; @@ -99,13 +100,8 @@ public boolean isSpin() { public int getMultiplicator() { if (valid) { return multiplicator; - } else { - return 1; } - } - - public String getOrigInteval() { - return origInteval; + return 1; } public boolean isValid() { @@ -128,7 +124,7 @@ public long getMilis() { @Override public String toString() { - return origInteval; + return origInterval; } } @@ -149,7 +145,7 @@ private int getStepCount() { @Override public void execute(AdminCommandContext context) { ProgressStatus ps = context.getProgressStatus(); - parsedIntervals = new ArrayList(intervals != null ? intervals.length : 0); + parsedIntervals = new ArrayList<>(intervals != null ? intervals.length : 0); ActionReport report = context.getActionReport(); for (String interval : intervals) { parsedIntervals.add(new Interval(interval)); diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressDoubleTotalsCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressDoubleTotalsCommand.java index 08d5ba70024..698a113bf17 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressDoubleTotalsCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressDoubleTotalsCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -26,7 +27,8 @@ import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; -/** Basic progress status example. +/** + * Basic progress status example. * Contains 10 steps * * @author mmares diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressExecOtherCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressExecOtherCommand.java index 042eaf9e3bd..1ef602ee4c4 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressExecOtherCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressExecOtherCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -55,15 +56,11 @@ public void execute(AdminCommandContext context) { } // Execute other command - commandRunner.getCommandInvocation( - "progress-simple", - context.getActionReport() - .addSubActionsReport(), + // Number 20 is little bit tricky. Please see javadoc of ProgressStatus + commandRunner.getCommandInvocation("progress-simple", + context.getActionReport().addSubActionsReport(), context.getSubject()) - .progressStatusChild( - // Number 20 is little bit tricky. Please see javadoc of ProgressStatus - progressStatus.createChild("subcommand", 20)) - .execute(); + .progressStatusChild(progressStatus.createChild("subcommand", 20)).execute(); // Do some after logic progressStatus.progress("Finishing outer command"); @@ -73,8 +70,6 @@ public void execute(AdminCommandContext context) { } progressStatus.complete("Finished outer command"); - - System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } private void doSomeLogic() { diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFailInHalfCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFailInHalfCommand.java index 029930eda40..eae97507349 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFailInHalfCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFailInHalfCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFullAnnotCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFullAnnotCommand.java index 84c4e07b467..f19189f0147 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFullAnnotCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressFullAnnotCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -42,5 +43,4 @@ public void execute(AdminCommandContext context) { cmd.noTotalSteps = true; cmd.execute(context); } - } diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressPayloadCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressPayloadCommand.java index 4892191b575..09f2e607ca3 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressPayloadCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressPayloadCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -18,10 +19,12 @@ import com.sun.enterprise.util.StringUtils; import com.sun.logging.LogDomains; + import java.io.File; import java.io.IOException; import java.net.URI; import java.util.logging.Logger; + import org.glassfish.api.ActionReport; import org.glassfish.api.I18n; import org.glassfish.api.Param; @@ -35,7 +38,8 @@ import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; -/** Doing progress and send some payload. +/** + * Doing progress and send some payload. * * @author mmares */ @@ -47,8 +51,7 @@ @ManagedJob public class ProgressPayloadCommand implements AdminCommand { - private final static Logger logger = - LogDomains.getLogger(ProgressPayloadCommand.class, LogDomains.ADMIN_LOGGER); + private final static Logger logger = LogDomains.getLogger(ProgressPayloadCommand.class, LogDomains.ADMIN_LOGGER); @Param(name = "down", multiple = false, primary = true, optional = true) String down; diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressSimpleCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressSimpleCommand.java index 41b0df81a80..c6e81cb8127 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressSimpleCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressSimpleCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressStepBackCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressStepBackCommand.java index 614d59d57f3..27fd174bc39 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressStepBackCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressStepBackCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -26,7 +27,8 @@ import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; -/** Basic progress status example. +/** + * Basic progress status example. * Contains 10 steps * * @author mmares diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressWithSupplementCommand.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressWithSupplementCommand.java index 37273cccefa..c49b1e7a47b 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressWithSupplementCommand.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/ProgressWithSupplementCommand.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -16,7 +17,6 @@ package com.sun.enterprise.tests.progress; -import com.sun.enterprise.universal.i18n.LocalStringsImpl; import org.glassfish.api.I18n; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; @@ -26,7 +26,8 @@ import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; -/** Same as {@code ProgressSimpleCommand} but this one has supplements. +/** + * Same as {@code ProgressSimpleCommand} but this one has supplements. * It also does not specify totalStepCount in annotation but using API. * Percentage can be printed after {@code SupplementBefore} will be done. * @@ -38,12 +39,9 @@ @PerLookup @CommandLock(CommandLock.LockType.NONE) @I18n("progress") -@Progress() +@Progress public class ProgressWithSupplementCommand implements AdminCommand { - private static final LocalStringsImpl strings = - new LocalStringsImpl(ProgressWithSupplementCommand.class); - @Override public void execute(AdminCommandContext context) { ProgressStatus ps = context.getProgressStatus(); diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementAfter.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementAfter.java index f24e8761184..f094f548ce2 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementAfter.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementAfter.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the diff --git a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementBefore.java b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementBefore.java index 2faed1d56a5..f0f68665c2a 100644 --- a/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementBefore.java +++ b/appserver/tests/admin/admin-extension/src/main/java/com/sun/enterprise/tests/progress/SupplementBefore.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2022 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the diff --git a/appserver/tests/admin/tests/pom.xml b/appserver/tests/admin/tests/pom.xml index 488be10476d..3a64f8479e0 100644 --- a/appserver/tests/admin/tests/pom.xml +++ b/appserver/tests/admin/tests/pom.xml @@ -31,16 +31,13 @@ GlassFish Admin Tests - - org.glassfish.hk2 - hk2-api - test - + org.glassfish.jersey.core - jersey-server + jersey-client test + org.glassfish.jersey.inject jersey-hk2 @@ -53,18 +50,28 @@ test - org.glassfish.main.admin - rest-service + org.glassfish.main.common + common-util ${project.version} - jar test - org.glassfish.main.common - common-util + org.glassfish.main.security + security + ${project.version} + test + + + org.glassfish.main.security + security-ee ${project.version} test + + jakarta.servlet + jakarta.servlet-api + test + org.glassfish.main.distributions @@ -79,6 +86,7 @@ ${project.version} test + org.junit.jupiter junit-jupiter-engine @@ -87,14 +95,9 @@ org.hamcrest hamcrest - - - jakarta.xml.bind - jakarta.xml.bind-api - - com.sun.xml.bind - jaxb-osgi + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven-archive @@ -127,14 +130,6 @@ - - maven-surefire-plugin - - - alphabetical - - - diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java similarity index 60% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java index dc1b66bb42b..1a8f196c854 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/ClusterITest.java @@ -35,30 +35,28 @@ */ @TestMethodOrder(OrderAnnotation.class) @ExtendWith(DomainLifecycleExtension.class) -public class ClusterTest { +public class ClusterITest { - private final String tn = "QLCluster"; - private final String port1 = "55123"; - private final String port2 = "55124"; - private final String cname = "eec1"; - private final String i1name = "eein1-with-a-very-very-very-long-name"; - private final String i2name = "eein2"; - private final String i1url = "http://localhost:" + port1; - private final String i2url = "http://localhost:" + port2; + private static final String PORT1 = "55123"; + private static final String PORT2 = "55124"; + private static final String CLUSTER_NAME = "eec1"; + private static final String INSTANCE_NAME_1 = "eein1-with-a-very-very-very-long-name"; + private static final String INSTANCE_NAME_2 = "eein2"; + private static final String URL1 = "http://localhost:" + PORT1; + private static final String URL2 = "http://localhost:" + PORT2; @Test @Order(1) public void createClusterTest() { - // create a cluster and two instances - assertTrue(nadmin("create-cluster", cname), "create cluster"); + assertTrue(nadmin("create-cluster", CLUSTER_NAME), "create cluster"); } @Test @Order(2) public void createInstancesTest() { assertTrue( - nadmin("create-local-instance", "--cluster", cname, "--systemproperties", - "HTTP_LISTENER_PORT=" + port1 + ":" + + 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:" + @@ -66,52 +64,49 @@ public void createInstancesTest() { "IIOP_SSL_MUTUALAUTH_PORT=13801:" + "JMS_PROVIDER_PORT=18686:" + "ASADMIN_LISTENER_PORT=14848", - i1name), "create instance1"); + INSTANCE_NAME_1), "create instance1"); assertTrue( - nadmin("create-local-instance", "--cluster", cname, "--systemproperties", - "HTTP_LISTENER_PORT=" + port2 + + 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", - i2name), "create instance2"); + INSTANCE_NAME_2), "create instance2"); } @Test @Order(3) public void startInstancesTest() { - // start the instances - assertTrue(nadmin("start-local-instance", i1name), "start instance1"); - assertTrue(nadmin("start-local-instance", i2name), "start instance2"); + assertTrue(nadmin("start-local-instance", INSTANCE_NAME_1), "start instance1"); + assertTrue(nadmin("start-local-instance", INSTANCE_NAME_2), "start instance2"); } @Test @Order(4) public void checkClusterTest() { - // check that the instances are there assertTrue(nadmin("list-instances"), "list-instances"); - assertThat(getURL(i1url), stringContainsInOrder("GlassFish Server")); - assertThat(getURL(i2url), stringContainsInOrder("GlassFish Server")); + assertThat(getURL(URL1), stringContainsInOrder("GlassFish Server")); + assertThat(getURL(URL2), stringContainsInOrder("GlassFish Server")); } @Test @Order(5) public void stopInstancesTest() { - // stop and delete the instances and cluster - assertTrue(nadmin("stop-local-instance", "--kill", i1name), "stop instance1"); - assertTrue(nadmin("stop-local-instance", "--kill", i2name), "stop instance2"); + assertTrue(nadmin("stop-local-instance", "--kill", INSTANCE_NAME_1), "stop instance1"); + assertTrue(nadmin("stop-local-instance", "--kill", INSTANCE_NAME_2), "stop instance2"); } @Test @Order(6) public void deleteInstancesTest() { - assertTrue(nadmin("delete-local-instance", i1name), "delete instance1"); - assertTrue(nadmin("delete-local-instance", i2name), "delete instance2"); + assertTrue(nadmin("delete-local-instance", INSTANCE_NAME_1), "delete instance1"); + assertTrue(nadmin("delete-local-instance", INSTANCE_NAME_2), "delete instance2"); } @Test @Order(7) public void deleteClusterTest() { - assertTrue(nadmin("delete-cluster", cname), "delete cluster"); + assertTrue(nadmin("delete-cluster", CLUSTER_NAME), "delete cluster"); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java similarity index 98% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java index 1771a4b709b..97d7e4bc240 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/MiscCommandsITest.java @@ -33,7 +33,7 @@ */ @ExtendWith(DomainLifecycleExtension.class) @TestMethodOrder(OrderAnnotation.class) -public class MiscCommandsTest { +public class MiscCommandsITest { @Test @Order(1) diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java similarity index 94% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java index 35bab2a5f11..fa209726c4c 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/OSGiCommandsITest.java @@ -45,41 +45,13 @@ * @author sanjeeb.sahoo@oracle.com */ @ExtendWith(DomainLifecycleExtension.class) -public class OSGiCommandsTest { +public class OSGiCommandsITest { @Test public void basicOsgiCmd() { assertTrue(nadmin("osgi", "lb")); } - private List runCmd(String... cmd) throws Exception { - NadminReturn value = nadminWithOutput(cmd); - if (!value.returnValue) { - throw new Exception("Cmd failed: \n" + value.outAndErr); - } - List 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 value = runCmd("osgi", "--session", "new"); - if (value.size() != 1) { - throw new Exception("Unexpected output: \n " + value); - } - return value.get(0); - } - - private Set listCmdSessions() throws Exception { - List sessions = runCmd("osgi", "--session", "list"); - return new HashSet<>(sessions); - } /** * Tests functionality of session handling of osgi command. @@ -99,8 +71,7 @@ public void osgiCmdSession() throws Exception { assertEquals(sessions, actual, "listed sessions do not match with created sessions"); // Let's set the same variable in each command session with a different value and make sure - // the variables - // are scoped to sessions. + // the variables are scoped to sessions. for (String sessionId : sessions) { List result = runCmd("osgi", "--session", "execute", "--session-id", sessionId, "var=" + sessionId); assertThat(result, IsEmptyCollection.empty()); @@ -129,18 +100,41 @@ public void osgiCmdSession() throws Exception { public void osgiShell() throws IOException { File cmdFile = File.createTempFile("osgi-commands", ".txt"); cmdFile.deleteOnExit(); - PrintStream ps = new PrintStream(new FileOutputStream(cmdFile)); - try { + 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")); - } finally { - try { - ps.close(); - } catch (Exception e) { - // ignore + } + } + + + private List runCmd(String... cmd) throws Exception { + NadminReturn value = nadminWithOutput(cmd); + if (!value.returnValue) { + throw new Exception("Cmd failed: \n" + value.outAndErr); + } + List 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 value = runCmd("osgi", "--session", "new"); + if (value.size() != 1) { + throw new Exception("Unexpected output: \n " + value); + } + return value.get(0); + } + + private Set listCmdSessions() throws Exception { + List sessions = runCmd("osgi", "--session", "list"); + return new HashSet<>(sessions); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java similarity index 99% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java index fd3985e1332..9112ad4562b 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/RestITest.java @@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(DomainLifecycleExtension.class) -public class RestTest { +public class RestITest { @Test public void testManagementEndpoint() throws Exception { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java similarity index 99% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java index fe64fec5ab5..c8a89d9e8ac 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/DetachAttachITest.java @@ -51,7 +51,7 @@ * @author martinmares */ @ExtendWith(DomainLifecycleExtension.class) -public class DetachAttachTest { +public class DetachAttachITest { @AfterEach public void cleanUp() throws Exception { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java similarity index 99% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java index 14742681f88..8c5ebfa9ade 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/JobManagerITest.java @@ -42,7 +42,7 @@ */ @TestMethodOrder(OrderAnnotation.class) @ExtendWith(DomainLifecycleExtension.class) -public class JobManagerTest { +public class JobManagerITest { private static final String COMMAND_PROGRESS_SIMPLE = "progress-simple"; diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressMessage.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressMessage.java index ed36b1c5700..0be7e34449d 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressMessage.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressMessage.java @@ -18,6 +18,7 @@ package org.glassfish.nucleus.admin.progress; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; @@ -26,6 +27,8 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.hamcrest.CustomTypeSafeMatcher; + /** * Parse progress status message. * @@ -75,6 +78,11 @@ public String getMessage() { return message; } + @Override + public String toString() { + return Arrays.toString(new Object[] {value, percentage, scope, message}); + } + public static List grepProgressMessages(String txt) { StringTokenizer stok = new StringTokenizer(txt, System.lineSeparator()); return Collections.list(stok).stream().map(Object::toString).filter(PREDICATE).map(ProgressMessage::new) @@ -95,18 +103,24 @@ public static String[] uniqueMessages(List pms) { return messages.toArray(result); } - public static boolean isNonDecreasing(List pms) { - if (pms == null) { - return false; - } - int lastVal = Integer.MIN_VALUE; - for (ProgressMessage pm : pms) { - if (pm.getValue() < lastVal) { - return false; + public static CustomTypeSafeMatcher> isIncreasing() { + return new CustomTypeSafeMatcher<>("is increasing") { + + @Override + protected boolean matchesSafely(List pms) { + if (pms == null) { + return false; + } + int lastVal = Integer.MIN_VALUE; + for (ProgressMessage pm : pms) { + if (pm.getValue() < lastVal) { + return false; + } + lastVal = pm.getValue(); + } + return true; } - lastVal = pm.getValue(); - } - return true; + }; } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java similarity index 88% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java index 4e0047cdf42..609c9970fa7 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusBasicITest.java @@ -24,7 +24,10 @@ 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.hamcrest.MatcherAssert.assertThat; +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; @@ -33,19 +36,19 @@ * @author martinmares */ @ExtendWith(DomainLifecycleExtension.class) -public class ProgressStatusBasicTest { +public class ProgressStatusBasicITest { @Test public void simple() { NadminReturn result = nadminWithOutput("progress-simple"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); + assertThat(prgs, isIncreasing()); assertEquals(12, prgs.size()); for (int i = 0; i < 11; i++) { assertEquals(10 * i, prgs.get(i + 1).getValue()); assertTrue(prgs.get(i + 1).isPercentage()); } - assertTrue(ProgressMessage.isNonDecreasing(prgs)); } @Test @@ -53,6 +56,7 @@ public void simpleNoTotal() { NadminReturn result = nadminWithOutput("progress-simple", "--nototalsteps"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); + assertThat(prgs, isIncreasing()); boolean nonPercentageExists = false; for (ProgressMessage prg : prgs) { if (prg.getValue() != 0 && prg.getValue() != 100) { @@ -61,7 +65,6 @@ public void simpleNoTotal() { } } assertTrue(nonPercentageExists); - assertTrue(ProgressMessage.isNonDecreasing(prgs)); } @Test @@ -69,12 +72,12 @@ public void simpleSpecInAnnotation() { NadminReturn result = nadminWithOutput("progress-full-annotated"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); - assertEquals(12, prgs.size()); + assertThat(prgs, hasSize(12)); + assertThat(prgs, isIncreasing()); for (int i = 0; i < 11; i++) { assertEquals(10 * i, prgs.get(i + 1).getValue()); assertTrue(prgs.get(i + 1).isPercentage()); } - assertTrue(ProgressMessage.isNonDecreasing(prgs)); assertEquals("annotated:", prgs.get(5).getScope()); } @@ -83,6 +86,6 @@ public void simpleTerse() { NadminReturn result = nadminWithOutput("--terse", "progress-simple"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); - assertTrue(prgs.isEmpty()); + assertThat(prgs, hasSize(0)); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java similarity index 86% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java index c92044b476e..069081af76a 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusComplexITest.java @@ -22,14 +22,18 @@ import org.glassfish.nucleus.test.tool.DomainLifecycleExtension; import org.glassfish.nucleus.test.tool.NucleusTestUtils; import org.glassfish.nucleus.test.tool.NucleusTestUtils.NadminReturn; -import org.junit.jupiter.api.Disabled; 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.isNonDecreasing; +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.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -39,54 +43,46 @@ * @author martinmares */ @ExtendWith(DomainLifecycleExtension.class) -public class ProgressStatusComplexTest { +public class ProgressStatusComplexITest { @Test public void executeCommandFromCommand() { NadminReturn result = nadminWithOutput("progress-exec-other"); - assertTrue(result.returnValue); - assertArrayEquals(new String[] { "Starting", "Preparing", "Parsing", "Working on main part", "Cleaning", "Finished", "Finishing outer command", "Finished outer command" }, - uniqueMessages(grepProgressMessages(result.out))); } @Test - @Disabled public void executeCommandWithSupplements() { NadminReturn result = nadminWithOutput("progress-supplement"); assertTrue(result.returnValue); List prgs = grepProgressMessages(result.out); - assertArrayEquals(new String[] { "Starting", "2 seconds supplemental command", "Parsing", "Working on main part", "Finished", "3 seconds supplemental" }, - uniqueMessages(prgs)); - assertTrue(prgs.size() > 10); + assertThat(prgs, hasSize(21)); + assertThat(prgs, isIncreasing()); assertFalse(prgs.get(4).isPercentage()); assertTrue(prgs.get(10).isPercentage()); - assertTrue(isNonDecreasing(prgs)); } - // Test disabled till intermittent failures are fixed @Test - @Disabled public void executeVeryComplexCommand() { NucleusTestUtils.NadminReturn result = nadminWithOutput("progress-complex"); - assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); - assertTrue(prgs.size() > 40); - assertTrue(scopeCount(prgs, "complex:") >= 4); + assertThat(prgs, hasSize(greaterThanOrEqualTo(100))); + assertThat(prgs, isIncreasing()); + assertEquals(5, scopeCount(prgs, "complex:")); assertEquals(0, scopeCount(prgs, "complex.ch1:")); - assertEquals(5, scopeCount(prgs, "complex.ch2-paral:")); + assertThat(scopeCount(prgs, "complex.ch2-paral:"), anyOf(equalTo(5), equalTo(6))); assertEquals(4, scopeCount(prgs, "complex.ch3:")); assertEquals(5, scopeCount(prgs, "complex.ch1.ch11:")); assertEquals(6, scopeCount(prgs, "complex.ch1.ch12:")); @@ -96,7 +92,6 @@ public void executeVeryComplexCommand() { assertEquals(25, scopeCount(prgs, "complex.ch2-paral.ch24:")); assertEquals(5, scopeCount(prgs, "complex.ch3.ch31:")); assertEquals(5, scopeCount(prgs, "complex.ch3.ch32:")); - assertTrue(ProgressMessage.isNonDecreasing(prgs)); } private int scopeCount(List prgs, String scope) { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java similarity index 98% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java index b6890ee2531..7d9fe7bc47d 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusFailITest.java @@ -32,7 +32,7 @@ * @author martinmares */ @ExtendWith(DomainLifecycleExtension.class) -public class ProgressStatusFailTest { +public class ProgressStatusFailITest { @Test public void failDuringExecution() { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java similarity index 77% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java index 3825f7da78a..68573f07bd7 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/progress/ProgressStatusSpecialITest.java @@ -25,22 +25,26 @@ 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.junit.jupiter.api.Assertions.assertFalse; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author martinmares */ @ExtendWith(DomainLifecycleExtension.class) -public class ProgressStatusSpecialTest { +public class ProgressStatusSpecialITest { @Test public void stepBackCommand() { NadminReturn result = nadminWithOutput("progress-step-back"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); - assertFalse(ProgressMessage.isNonDecreasing(prgs)); + assertThat(prgs, not(isIncreasing())); Iterator itr = prgs.iterator(); while (itr.hasNext()) { ProgressMessage prg = itr.next(); @@ -48,17 +52,17 @@ public void stepBackCommand() { break; } } - assertTrue(itr.hasNext()); //Exist more record + assertTrue(itr.hasNext(), "Exist more records"); while (itr.hasNext()) { ProgressMessage prg = itr.next(); - assertTrue(prg.getValue() <= 80); + assertThat(prg.getValue(), lessThanOrEqualTo(80)); if (prg.getValue() < 80) { break; } } - assertTrue(itr.hasNext()); //Exist more record + assertTrue(itr.hasNext(), "Exist more records"); ProgressMessage prg = itr.next(); - assertTrue(prg.getValue() < 80); + assertThat(prg.getValue(), lessThan(80)); } @Test @@ -66,7 +70,7 @@ public void doubleTotalCommand() { NadminReturn result = nadminWithOutput("progress-double-totals"); assertTrue(result.returnValue); List prgs = ProgressMessage.grepProgressMessages(result.out); - assertFalse(ProgressMessage.isNonDecreasing(prgs)); + assertThat(prgs, not(isIncreasing())); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java similarity index 57% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java index 5abb8de2379..bb91938ec85 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ApplicationITest.java @@ -20,31 +20,35 @@ import jakarta.ws.rs.core.Response; import java.io.File; +import java.io.IOException; import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashMap; import java.util.Map; +import java.util.logging.Logger; -import org.junit.jupiter.api.Disabled; +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.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jasonlee */ -@Disabled("Missing test application") -public class ApplicationTest extends RestTestBase { +public class ApplicationITest extends RestTestBase { @Test public void testApplicationDeployment() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); try { - Map deployedApp = deployApp(getFile("test.war"), appName, appName); + Map deployedApp = deployApp(getWar("test"), appName, appName); assertEquals(appName, deployedApp.get("name")); - assertEquals("/" + appName, deployedApp.get("contextRoot")); } catch (Exception e) { throw new RuntimeException(e); @@ -57,27 +61,27 @@ public void testApplicationDeployment() throws URISyntaxException { public void testApplicationDisableEnable() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - Map deployedApp = deployApp(getFile("test.war"), appName, appName); + Map deployedApp = deployApp(getWar("test"), appName, appName); assertEquals(appName, deployedApp.get("name")); assertEquals("/" + appName, deployedApp.get("contextRoot")); try { - String appUrl = getBaseAdminUrl() + appName; + String appUrl = getBaseInstanceUrl() + appName; Response response = get(appUrl); - assertEquals ("Test", response.readEntity(String.class).trim()); + assertEquals ("Hello!", response.readEntity(String.class)); response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/disable"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(appUrl); assertEquals(404, response.getStatus()); response = post(URL_APPLICATION_DEPLOY + "/" + appName + "/enable"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(appUrl); - assertEquals ("Test", response.readEntity(String.class).trim()); + assertEquals ("Hello!", response.readEntity(String.class).trim()); } finally { undeployApp(appName); } @@ -88,16 +92,16 @@ public void listSubComponents() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); try { - deployApp(getFile("stateless-simple.ear"), appName, appName); + deployApp(getEar("simple"), appName, appName); Response response = get(URL_APPLICATION_DEPLOY +"/" + appName + "/list-sub-components?id=" + appName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); String subComponents = response.readEntity(String.class); - assertTrue(subComponents.contains("stateless-simple.war")); + assertThat(subComponents, stringContainsInOrder("simple")); - response = get(URL_APPLICATION_DEPLOY +"/" + appName + "/list-sub-components?id=stateless-simple.war&appname=" + appName); - checkStatus(response); + response = get(URL_APPLICATION_DEPLOY +"/" + appName + "/list-sub-components?id=simple.war&appname=" + appName); + assertThat(response.getStatus(), equalTo(200)); subComponents = response.readEntity(String.class); - assertTrue(subComponents.contains("GreeterServlet")); + assertThat(subComponents, stringContainsInOrder(HelloServlet.class.getName())); } finally { undeployApp(appName); } @@ -109,32 +113,26 @@ public void testCreatingAndDeletingApplicationRefs() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); final String appRefUrl = "domain/servers/server/" + instanceName + "/application-ref"; - Map newInstance = new HashMap<>() {{ - put("id", instanceName); - put("node", "localhost-domain1"); - }}; - Map applicationRef = new HashMap<>() {{ - put("id", appName); - put("target", instanceName); - }}; + Map newInstance = Map.of("id", instanceName, "node", "localhost-domain1"); + Map applicationRef = Map.of("id", appName, "target", instanceName); try { Response response = post(URL_CREATE_INSTANCE, newInstance); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); - deployApp(getFile("test.war"), appName, appName); + deployApp(getWar("test"), appName, appName); response = post (appRefUrl, applicationRef); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(appRefUrl + "/" + appName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); - response = delete(appRefUrl + "/" + appName, new HashMap() {{ put("target", instanceName); }}); - checkStatus(response); + response = delete(appRefUrl + "/" + appName, Map.of("target", instanceName)); + assertThat(response.getStatus(), equalTo(200)); } finally { Response response = delete("domain/servers/server/" + instanceName + "/delete-instance"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get("domain/servers/server/" + instanceName); assertEquals(404, response.getStatus()); undeployApp(appName); @@ -144,18 +142,15 @@ public void testCreatingAndDeletingApplicationRefs() throws URISyntaxException { @Test public void testGetContextRoot() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); - try { - Map deployedApp = deployApp(getFile("stateless-simple.ear"), appName, appName); + Map deployedApp = deployApp(getEar("simple"), appName, appName); assertEquals(appName, deployedApp.get("name")); - Map contextRootPayload = new HashMap<>() {{ - put("appname", appName); - put("modulename", "stateless-simple.war"); - }}; - - Response response = get("domain/applications/application/" +appName + "/get-context-root", contextRootPayload); - checkStatus(response); - assertTrue(response.readEntity(String.class).contains("helloworld")); + Map contextRootPayload = Map.of("appname", appName, "modulename", "simple"); + Response response = 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")); } finally { undeployApp(appName); } @@ -166,34 +161,23 @@ public void testUndeploySubActionWarnings() throws URISyntaxException { final String appName = "testApp" + generateRandomString(); final String serverName = "in" + generateRandomNumber(); try { - Response response = post ("domain/create-instance", new HashMap() {{ - put("id", serverName); - put("node", "localhost-domain1"); - }}); - checkStatus(response); + Response response = post ("domain/create-instance", Map.of("id", serverName, "node", "localhost-domain1")); + assertThat(response.getStatus(), equalTo(200)); response = post("domain/servers/server/" + serverName + "/start-instance"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); - deployApp(getFile("test.war"), appName, appName); + deployApp(getWar("test"), appName, appName); addAppRef(appName, serverName); response = post("domain/servers/server/" + serverName + "/stop-instance"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); - response = delete ("domain/applications/application/"+appName, new HashMap() {{ - put("target", "domain"); - }}); - assertTrue(response.readEntity(String.class).contains("WARNING: Instance " + serverName + " seems to be offline")); + response = 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, new HashMap() {{ - put("target", "domain"); - }}); + delete("domain/applications/application/" + appName, Map.of("target", "domain")); } } - - private File getFile(String fileName) throws URISyntaxException { - final URL resource = getClass().getResource("/" + fileName); - return new File(resource.toURI()); - } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java similarity index 99% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java index 281092d16f4..02033d74511 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/AuthRealmITest.java @@ -43,7 +43,7 @@ import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; import static org.junit.jupiter.api.Assertions.assertEquals; -public class AuthRealmTest extends RestTestBase { +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"; diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java similarity index 85% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java index 243b19a0a05..68a72f6b330 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ClusterITest.java @@ -23,12 +23,14 @@ import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author jasonlee */ -public class ClusterTest extends RestTestBase { +public class ClusterITest extends RestTestBase { @Test public void testClusterCreationAndDeletion() { @@ -45,13 +47,13 @@ public void testClusterCreationAndDeletion() { public void testListLifecycleModules() { final String clusterName = "cluster_" + generateRandomString(); Response response = post(URL_CLUSTER, Map.of("id", clusterName)); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(URL_CLUSTER + "/" + clusterName + "/list-lifecycle-modules"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = delete(URL_CLUSTER + "/" + clusterName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(URL_CLUSTER + "/" + clusterName); assertEquals(404, response.getStatus()); diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java similarity index 59% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java index 945aaf38d3f..4f9cb1fd744 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ConfigITest.java @@ -18,21 +18,17 @@ package org.glassfish.nucleus.admin.rest; import jakarta.ws.rs.core.MultivaluedHashMap; -import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author jasonlee */ -public class ConfigTest extends RestTestBase { - - public static final String BASE_CONFIGS_URL = "domain/configs"; +public class ConfigITest extends RestTestBase { @Test public void testConfigCopy() { @@ -49,24 +45,8 @@ public void duplicitCopyShouldFail() { MultivaluedHashMap formData = new MultivaluedHashMap<>(); formData.add("id", "default-config"); formData.add("id", "server-config"); - Response response = post(BASE_CONFIGS_URL + "/copy-config", formData); - // FIXME: causes HTTP 500 without any log - assertThat(response.getStatus(), greaterThanOrEqualTo(400)); - } - - public void createAndVerifyConfig(String configName, MultivaluedMap configData) { - Response response = post(BASE_CONFIGS_URL + "/copy-config", configData); - checkStatus(response); - - response = get(BASE_CONFIGS_URL + "/config/" + configName); - checkStatus(response); - } - - public void deleteAndVerifyConfig(String configName) { - Response response = post(BASE_CONFIGS_URL + "/config/" + configName + "/delete-config"); - checkStatus(response); - - response = get(BASE_CONFIGS_URL + "/config/" + configName); - assertEquals(404, response.getStatus()); + Response response = 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/DomainTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java similarity index 85% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java index 1b243911d0c..532094ee140 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/DomainITest.java @@ -27,13 +27,17 @@ import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -public class DomainTest extends RestTestBase { +public class DomainITest extends RestTestBase { @Test public void testDomainGet() throws Exception { - Map current = getEntityValues(get("/domain")); + Response response0 = get("domain"); + assertThat(response0.getStatus(), equalTo(200)); + Map current = getEntityValues(response0); // Select a random locale so we're not setting the locale to its current value List locales = new ArrayList<>(List.of("en_US", "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC")); diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java similarity index 61% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java index 780a5691fc7..c10e9a1f06d 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ElementStarITest.java @@ -20,61 +20,60 @@ import jakarta.ws.rs.core.Response; import java.net.URISyntaxException; -import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import 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.assertTrue; /** * This class tests the changes to the handling of @Element("*") instances + * * @author jasonlee */ -public class ElementStarTest extends RestTestBase { - protected static final String URL_CREATE_INSTANCE = "domain/create-instance"; +public class ElementStarITest extends RestTestBase { + private static final String URL_CREATE_INSTANCE = "domain/create-instance"; - protected String instanceName1; - protected String instanceName2; + private String instanceName1; + private String instanceName2; @BeforeEach public void before() { instanceName1 = "instance_" + generateRandomString(); instanceName2 = "instance_" + generateRandomString(); - Response response = post(URL_CREATE_INSTANCE, new HashMap() {{ put("id", instanceName1); put("node", "localhost-domain1"); }}); - checkStatus(response); - response = post(URL_CREATE_INSTANCE, new HashMap() {{ put("id", instanceName2); put("node", "localhost-domain1"); }}); - checkStatus(response); + Response response = 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")); + assertEquals(200, response.getStatus()); } @AfterEach public void after() { - Response response = delete("domain/servers/server/" + instanceName1 + "/delete-instance"); // FIXME: This url should be fixed - checkStatus(response); + Response response = delete("domain/servers/server/" + instanceName1 + "/delete-instance"); + assertEquals(200, response.getStatus()); response = delete("domain/servers/server/" + instanceName2 + "/delete-instance"); - checkStatus(response); + assertEquals(200, response.getStatus()); } @Test - @Disabled("Unavailable webapp") public void testApplications() throws URISyntaxException { final String app1 = "app" + generateRandomString(); final String app2 = "app" + generateRandomString(); - // FIXME: we need some example webapp -// deployApp("test.war", app1, app1); -// deployApp("test.war", app2, app2); + deployApp(getWar("test"), app1, app1); + deployApp(getWar("test"), app2, app2); addAppRef(app1, instanceName1); addAppRef(app2, instanceName1); Response response = get("domain/servers/server/" + instanceName1 + "/application-ref"); Map children = this.getChildResources(response); - assertEquals(2, children.size()); + assertThat(children, aMapWithSize(2)); } @Test @@ -82,28 +81,20 @@ 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"); Map children = this.getChildResources(response); - assertTrue(children.size() >= 2); + assertThat(children, aMapWithSize(7)); } @Test - @Disabled public void testLoadBalancerConfigs() { final String lbName = "lbconfig-" + generateRandomString(); - Response response = post ("domain/lb-configs/lb-config/", - new HashMap() {{ - put("id", lbName); - put("target", instanceName1); - }}); - checkStatus(response); - - response = post("domain/lb-configs/lb-config/" + lbName + "/create-http-lb-ref", - new HashMap() {{ - put ("id", instanceName2); - }}); - checkStatus(response); + Response response = 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)); + assertEquals(200, response.getStatus()); response = get ("domain/lb-configs/lb-config/" + lbName + "/server-ref"); - Map children = this.getChildResources(response); - assertTrue(!children.isEmpty()); + Map children = getChildResources(response); + assertThat(children, aMapWithSize(1)); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java similarity index 64% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java index 50a5671b73c..be1425e7ca9 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ExternalResourceITest.java @@ -19,40 +19,37 @@ import jakarta.ws.rs.core.Response; -import java.util.HashMap; import java.util.Map; -import org.glassfish.resources.custom.factory.PrimitivesAndStringFactory; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + /** * @author jasonlee */ -@Disabled -public class ExternalResourceTest extends RestTestBase { +public class ExternalResourceITest extends RestTestBase { - protected 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() { final String resourceName = "resource_" + generateRandomString(); final String jndiName = "jndi/" + resourceName; - Map newResource = new HashMap<>() { - { - put("id", resourceName); - put("jndilookupname", jndiName); - put("factoryClass", PrimitivesAndStringFactory.class.getName()); - put("restype", Double.class.getName()); - } - }; + Map newResource = Map.of( + "id", resourceName, + "jndilookupname", jndiName, + "factoryClass", "org.glassfish.resources.custom.factory.PrimitivesAndStringFactory", + "restype", Double.class.getName() + ); Response response = post(URL_EXTERNAL_RESOURCE, newResource); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(URL_EXTERNAL_RESOURCE + "/" + resourceName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = delete(URL_EXTERNAL_RESOURCE + "/" + resourceName); - checkStatus(response); + 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 new file mode 100644 index 00000000000..4cb903e00d6 --- /dev/null +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcITest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.nucleus.admin.rest; + +import jakarta.ws.rs.core.Response; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author jasonlee + */ +public class JdbcITest extends RestTestBase { + + @Test + public void testReadingPoolEntity() { + Map entity = getEntityValues(get(URL_JDBC_CONNECTION_POOL + "/__TimerPool")); + assertEquals("__TimerPool", entity.get("name")); + } + + + @Test + public void testCreateAndDeletePool() { + String poolName = "TestPool" + generateRandomString(); + Map params = new HashMap<>(); + params.put("name", poolName); + params.put("datasourceClassname", "org.apache.derby.jdbc.ClientDataSource"); + Response response = post(URL_JDBC_CONNECTION_POOL, params); + assertEquals(200, response.getStatus()); + + Map entity = getEntityValues(get(URL_JDBC_CONNECTION_POOL + "/" + poolName)); + assertThat(entity, aMapWithSize(greaterThan(40))); + + response = delete(URL_JDBC_CONNECTION_POOL + "/" + poolName, Map.of()); + assertEquals(200, response.getStatus()); + + response = get(URL_JDBC_CONNECTION_POOL + "/" + poolName); + assertEquals(404, response.getStatus()); + } + + + @Test + public void testBackslashValidation() { + String poolName = "TestPool\\" + generateRandomString(); + String encodedPoolName = URLEncoder.encode(poolName, StandardCharsets.UTF_8); + Map params = new HashMap<>(); + params.put("name", poolName); + params.put("poolName", "DerbyPool"); + + Response response = post(URL_JDBC_RESOURCE, params); + assertEquals(500, response.getStatus()); + + Response responseGet = get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName); + assertEquals(500, response.getStatus()); + Map entity = getEntityValues(responseGet); + assertNull(entity); + + response = delete("/" + encodedPoolName, Map.of()); + assertEquals(500, response.getStatus()); + + response = get(URL_JDBC_CONNECTION_POOL + "/" + encodedPoolName); + assertEquals(500, response.getStatus()); + } + + + @Test + public void createDuplicateResource() { + final String resourceName = "jdbc/__default"; + Map params = Map.of("id", resourceName, "poolName", "DerbyPool"); + Response response = post(URL_JDBC_RESOURCE, params); + assertEquals(500, response.getStatus()); + } + + + @Test + public void createDuplicateConnectionPool() { + final String poolName = "DerbyPool"; + Map params = Map.of("id", poolName, "datasourceClassname", + "org.apache.derby.jdbc.ClientDataSource"); + Response response = 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/JdbcTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcTest.java deleted file mode 100644 index 74a513039c3..00000000000 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JdbcTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2022 Contributors to the Eclipse Foundation - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.nucleus.admin.rest; - -import jakarta.ws.rs.core.Response; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotSame; - -/** - * @author jasonlee - */ -@Disabled -public class JdbcTest extends RestTestBase { - public static final String BASE_JDBC_RESOURCE_URL = "domain/resources/jdbc-resource"; - public static final String BASE_JDBC_CONNECTION_POOL_URL = "domain/resources/jdbc-connection-pool"; - - @Test - public void testReadingPoolEntity() { - Map entity = getEntityValues(get(BASE_JDBC_CONNECTION_POOL_URL + "/__TimerPool")); - assertEquals("__TimerPool", entity.get("name")); - } - - @Test - public void testCreateAndDeletePool() { - String poolName = "TestPool" + generateRandomString(); - Map params = new HashMap<>(); - params.put("name", poolName); - params.put("datasourceClassname","org.apache.derby.jdbc.ClientDataSource"); - Response response = post(BASE_JDBC_CONNECTION_POOL_URL, params); - assertEquals(200, response.getStatus()); - - Map entity = getEntityValues(get(BASE_JDBC_CONNECTION_POOL_URL + "/"+poolName)); - assertNotSame(0, entity.size()); - - response = delete(BASE_JDBC_CONNECTION_POOL_URL+"/"+poolName, new HashMap()); - assertEquals(200, response.getStatus()); - - response = get(BASE_JDBC_CONNECTION_POOL_URL + "/" + poolName); - assertEquals(404, response.getStatus()); - } - - @Test - public void testCreateResourceWithBackslash() { - String poolName = "TestPool\\" + generateRandomString(); - String encodedPoolName = poolName; - try { - encodedPoolName = URLEncoder.encode(poolName, "UTF-8"); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(JdbcTest.class.getName()).log(Level.SEVERE, null, ex); - } - Map params = new HashMap<>(); - params.put("name", poolName); - params.put("poolName", "DerbyPool"); - - Response response = post (BASE_JDBC_RESOURCE_URL, params); - assertEquals(200, response.getStatus()); - - Map entity = getEntityValues(get(BASE_JDBC_CONNECTION_POOL_URL + "/" + encodedPoolName)); - assertNotSame(0, entity.size()); - - response = delete("/" + encodedPoolName, new HashMap()); - assertEquals(200, response.getStatus()); - - response = get(BASE_JDBC_CONNECTION_POOL_URL + "/" + encodedPoolName); - assertEquals(404, response.getStatus()); - } - - @Test - public void createDuplicateResource() { - final String resourceName = "jdbc/__default"; - Map params = new HashMap<>() {{ - put("id", resourceName); - put("poolName", "DerbyPool"); - }}; - - Response response = post (BASE_JDBC_RESOURCE_URL, params); - assertEquals(404, response.getStatus()); - } - - @Test - public void createDuplicateConnectionPool() { - final String poolName = "DerbyPool"; - Map params = new HashMap<>() {{ - put("id", poolName); - put("datasourceClassname", "org.apache.derby.jdbc.ClientDataSource"); - }}; - - Response response = post (BASE_JDBC_CONNECTION_POOL_URL, params); - assertEquals(404, response.getStatus()); - } -} diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java similarity index 55% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java index 88d085bdd9e..748ac679adb 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JmsITest.java @@ -19,24 +19,27 @@ import jakarta.ws.rs.core.Response; -import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +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.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jasonlee * @since May 26, 2010 */ -@Disabled -public class JmsTest extends RestTestBase { +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"; @@ -46,93 +49,61 @@ public class JmsTest extends RestTestBase { @Test public void testJmsConnectionFactories() { - final String poolName = "JmsConnectionFactory" + generateRandomString(); - Map ccp_attrs = new HashMap<>() { - { - put("name", poolName); - put("connectiondefinition", "jakarta.jms.ConnectionFactory"); - put("raname", "jmsra"); - } - }; - Map cr_attrs = new HashMap<>() { - { - put("id", poolName); - put("poolname", poolName); - } - }; - // Create connection pool + final String poolName = "JmsConnectionFactory" + generateRandomString(); + Map ccp_attrs = Map.of("name", poolName, "connectiondefinition", + "jakarta.jms.ConnectionFactory", "raname", "jmsra"); Response response = post(URL_CONNECTOR_CONNECTION_POOL, ccp_attrs); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); // Check connection pool creation Map pool = getEntityValues(get(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName)); - assertFalse(pool.isEmpty()); + assertThat(pool, aMapWithSize(greaterThanOrEqualTo(26))); // Create connector resource + String resourceName = poolName + "Resource"; + Map cr_attrs = Map.of("name", resourceName, "poolname", poolName); response = post(URL_CONNECTOR_RESOURCE, cr_attrs); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); // Check connector resource - Map resource = getEntityValues(get(URL_CONNECTOR_RESOURCE + "/" + poolName)); - assertFalse(resource.isEmpty()); + Map resource = getEntityValues(get(URL_CONNECTOR_RESOURCE + "/" + resourceName)); + assertThat(resource, aMapWithSize(6)); // Edit and check ccp - response = post(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, new HashMap() { - { - put("description", poolName); - } - }); - checkStatus(response); + response = 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)); // Edit and check cr - response = post(URL_CONNECTOR_RESOURCE + "/" + poolName, new HashMap() { - { - put("description", poolName); - } - }); - checkStatus(response); - - resource = getEntityValues(get(URL_CONNECTOR_RESOURCE + "/" + poolName)); + response = 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)); // Delete objects - response = delete(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, new HashMap() { - { - put("cascade", "true"); - } - }); - checkStatus(response); + response = delete(URL_CONNECTOR_CONNECTION_POOL + "/" + poolName, Map.of("cascade", "true")); + assertThat(response.getStatus(), equalTo(200)); } @Test public void testJmsDestinationResources() { final String jndiName = "jndi/" + generateRandomString(); - String encodedJndiName = jndiName; - try { - encodedJndiName = URLEncoder.encode(jndiName, "UTF-8"); - } catch (UnsupportedEncodingException e) { - } + String encodedJndiName = URLEncoder.encode(jndiName, StandardCharsets.UTF_8); - Map attrs = new HashMap<>() { - { - put("id", jndiName); - put("raname", "jmsra"); - put("restype", "jakarta.jms.Topic"); - } - }; + Map attrs = Map.of("id", jndiName, "raname", "jmsra", "restype", "jakarta.jms.Topic"); Response response = post(URL_ADMIN_OBJECT_RESOURCE, attrs); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); Map entity = getEntityValues(get(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName)); - assertFalse(entity.isEmpty()); + assertThat(entity, aMapWithSize(8)); response = delete(URL_ADMIN_OBJECT_RESOURCE + "/" + encodedJndiName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } @Test @@ -143,27 +114,18 @@ public void testJmsPhysicalDestination() { createJmsPhysicalDestination(destName, DEST_TYPE, URL_SEVER_JMS_DEST); - final HashMap newDest = new HashMap<>() { - { - put("id", destName); - put("desttype", DEST_TYPE); - } - }; - Map destProps = new HashMap<>() { - { - putAll(newDest); - put("property", "MaxNumMsgs=" + maxNumMsgs + ":ConsumerFlowLimit=" + consumerFlowLimit); - } - }; + final Map newDest = Map.of("id", destName, "desttype", DEST_TYPE); + Map destProps = new HashMap<>(newDest); + destProps.putAll(Map.of("property", "MaxNumMsgs=" + maxNumMsgs + ":ConsumerFlowLimit=" + consumerFlowLimit)); Response response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = post(URL_SEVER_JMS_DEST + "/__update-jmsdest", destProps); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest); - checkStatus(response); - Map entity = this.getEntityValues(response); + assertThat(response.getStatus(), equalTo(200)); + Map entity = getEntityValues(response); assertEquals(maxNumMsgs, entity.get("MaxNumMsgs")); assertEquals(consumerFlowLimit, entity.get("ConsumerFlowLimit")); @@ -171,114 +133,79 @@ public void testJmsPhysicalDestination() { } @Test + @Disabled("Enable and fix OpenMQ - require more detailed message and probably to fix the cause:" + + " MQJMSRA_RA4001: getJMXServiceURLList:Exception:Message=Caught exception when contacing portmapper.]]") public void testJmsPhysicalDestionationsWithClusters() { final String destName = "jmsDest" + generateRandomString(); - ClusterTest ct = getTestClass(ClusterTest.class); - final String clusterName = ct.createCluster(); - ct.createClusterInstance(clusterName, "in1_"+clusterName); - ct.startCluster(clusterName); - final String endpoint = "/domain/clusters/cluster/" + clusterName; + final String clusterName = createCluster(); + createClusterInstance(clusterName, "in1_" + clusterName); + startCluster(clusterName); + final String endpoint = "domain/clusters/cluster/" + clusterName; try { - createJmsPhysicalDestination(destName, "topic", endpoint); - final HashMap newDest = new HashMap<>() { - { - put("id", destName); - put("desttype", DEST_TYPE); - } - }; - + final Map newDest = Map.of("id", destName, "desttype", DEST_TYPE); Response response = get(endpoint + "/__get-jmsdest", newDest); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); response = get(URL_SEVER_JMS_DEST + "/__get-jmsdest", newDest); - checkStatus(response); - } - finally { + assertThat(response.getStatus(), equalTo(200)); + } finally { deleteJmsPhysicalDestination(destName, endpoint); - ct.stopCluster(clusterName); - ct.deleteCluster(clusterName); + stopCluster(clusterName); + deleteCluster(clusterName); } } @Test public void testJmsPing() { String results = get(URL_SEVER_JMS_DEST + "/jms-ping").readEntity(String.class); - assertTrue(results.contains("JMS-ping command executed successfully")); + assertThat(results, stringContainsInOrder("JMS-ping command executed successfully")); } @Test public void testJmsFlush() { - Map payload = new HashMap<>() { - { - put("id", "mq.sys.dmq"); - put("destType", "queue"); - } - }; - + Map payload = Map.of("id", "mq.sys.dmq", "destType", "queue"); Response response = post(URL_SEVER_JMS_DEST + "/flush-jmsdest", payload); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } @Test public void testJmsHosts() { final String jmsHostName = "jmshost" + generateRandomString(); - Map newHost = new HashMap<>() { - { - put("id", jmsHostName); - put("adminPassword", "admin"); - put("port", "7676"); - put("adminUserName", "admin"); - put("host", "localhost"); - } - }; + Map newHost = Map.of("id", jmsHostName, "adminPassword", "admin", "port", "7676", + "adminUserName", "admin", "host", "localhost"); // Test create Response response = post(URL_JMS_HOST, newHost); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); // Test edit Map entity = getEntityValues(get(URL_JMS_HOST + "/" + jmsHostName)); - assertFalse(entity.isEmpty()); + assertThat(entity, aMapWithSize(greaterThanOrEqualTo(6))); assertEquals(jmsHostName, entity.get("name")); entity.put("port", "8686"); response = post(URL_JMS_HOST + "/" + jmsHostName, entity); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); entity = getEntityValues(get(URL_JMS_HOST + "/" + jmsHostName)); assertEquals("8686", entity.get("port")); // Test delete response = delete(URL_JMS_HOST + "/" + jmsHostName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } - public void createJmsPhysicalDestination(final String destName, final String type, String endpoint) { - final Map newDest = new HashMap<>() { - { - put("id", destName); - put("desttype", type); - } - }; - - // Test Create + public void createJmsPhysicalDestination(final String destName, final String type, final String endpoint) { + final Map newDest = Map.of("id", destName, "desttype", type); Response response = post(endpoint + "/create-jmsdest", newDest); - // This command returns 200 instead of 201, for some reason. Odd. - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } - public void deleteJmsPhysicalDestination(final String destName, String endpoint) { - final HashMap newDest = new HashMap<>() { - { - put("id", destName); - put("desttype", DEST_TYPE); - } - }; - - // Test deletion - Response response = delete(endpoint + "/delete-jmsdest", newDest); // You POST to commands - checkStatus(response); + public void deleteJmsPhysicalDestination(final String destName, final String endpoint) { + final Map newDest = Map.of("id", destName, "desttype", DEST_TYPE); + Response response = delete(endpoint + "/delete-jmsdest", newDest); + assertThat(response.getStatus(), equalTo(200)); response = get(endpoint + "__get-jmsdest", newDest); - assertFalse(response.getStatus() == 200); + assertThat(response.getStatus(), equalTo(404)); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java similarity index 75% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java index 122aa0ed7e4..c56b0089549 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JobsResourceITest.java @@ -19,25 +19,22 @@ import jakarta.ws.rs.core.Response; -import java.util.Locale; - import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; -import org.glassfish.admin.rest.Constants; -import org.glassfish.admin.rest.composite.CompositeUtil; -import org.glassfish.admin.rest.resources.composite.Job; import org.junit.jupiter.api.Test; import static org.glassfish.nucleus.test.tool.NucleusTestUtils.nadminWithOutput; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jdlee */ -public class JobsResourceTest extends RestTestBase { +public class JobsResourceITest extends RestTestBase { public static final String URL_JOBS = "jobs"; @Test @@ -46,9 +43,9 @@ public void testJobsListing() { } @Test - public void testGetJob() throws JSONException { - // make sure we have at least one job - issueDetachedCommand(); + public void testGetJob() throws Exception { + // make sure we have at least one detached job + nadminWithOutput("--detach", "uptime"); // verify getting the collection Response response = get(URL_JOBS); @@ -58,10 +55,10 @@ public void testGetJob() throws JSONException { JSONObject json = response.readEntity(JSONObject.class); JSONArray resources = json.getJSONArray("resources"); assertNotNull(resources); - assertTrue(resources.length() > 0); + assertThat(resources.length(), equalTo(1)); JSONArray items = json.getJSONArray("items"); assertNotNull(items); - assertTrue(items.length() > 0); + assertThat(items.length(), equalTo(1)); // unlike most resources that also return a parent link, // the jobs resource only returns child links. @@ -72,7 +69,7 @@ public void testGetJob() throws JSONException { assertEquals("job", resource.getString("rel")); String jobId = resource.getString("title"); assertNotNull(jobId); - assertTrue(uri.endsWith(URL_JOBS + "/id/" + 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 @@ -80,13 +77,14 @@ public void testGetJob() throws JSONException { assertEquals(200, response.getStatus()); json = response.readEntity(JSONObject.class); JSONObject item = json.getJSONObject("item"); + System.out.println(item.toString()); verifyItem(jobId, item); resources = json.getJSONArray("resources"); assertNotNull(resources); - assertTrue(resources.length() == 1); + assertThat(resources.length(), equalTo(1)); resource = resources.getJSONObject(0); assertEquals("parent", resource.getString("rel")); - assertTrue(resource.getString("uri").endsWith(URL_JOBS)); + assertThat(resource.getString("uri"), endsWith(URL_JOBS)); // verify that the collection returned the item too item = null; @@ -99,20 +97,13 @@ public void testGetJob() throws JSONException { verifyItem(jobId, item); } - private void verifyItem(String jobIdWant, JSONObject itemHave) throws JSONException { - assertNotNull(itemHave); - Locale locale = null; - Job job = CompositeUtil.instance().unmarshallClass(locale, Job.class, itemHave); - assertNotNull(job); - assertEquals(jobIdWant, job.getJobId()); - } - - private void issueDetachedCommand() { - nadminWithOutput("--detach", "uptime"); + private void verifyItem(String expectedJobId, JSONObject jobJsonObject) throws JSONException { + assertNotNull(jobJsonObject); + assertEquals(expectedJobId, jobJsonObject.getString("jobId")); } @Override protected String getResponseType() { - return Constants.MEDIA_TYPE_JSON; + return "application/vnd.oracle.glassfish+json"; } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java similarity index 75% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java index 542149c46ef..24e0260f3c8 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/JvmOptionsITest.java @@ -27,6 +27,7 @@ import org.glassfish.admin.rest.client.utils.MarshallingUtils; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +41,7 @@ /** * @author jasonlee */ -public class JvmOptionsTest extends RestTestBase { +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"; @@ -52,31 +53,31 @@ public class JvmOptionsTest extends RestTestBase { 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 ConfigTest configTest; + private static RestTestBase configManagement; private String testConfigName; - private String URL_TEST_CONFIG; - private String URL_TEST_CONFIG_JVM_OPTIONS; + private String testConfigUrl; + private String testConfigJvmOptionsUrl; + + @BeforeAll + public static void initConfig() { + configManagement = new RestTestBase(); + } @BeforeEach public void createConfig() { - if (configTest == null) { - configTest = getTestClass(ConfigTest.class); - } - testConfigName = "config-" + generateRandomString(); - MultivaluedMap formData = new MultivaluedHashMap() {{ + MultivaluedMap formData = new MultivaluedHashMap<>() {{ add("id", "default-config"); add("id", testConfigName); }}; - configTest.createAndVerifyConfig(testConfigName, formData); - - URL_TEST_CONFIG = "domain/configs/config/" + testConfigName; - URL_TEST_CONFIG_JVM_OPTIONS = URL_TEST_CONFIG + "/java-config/jvm-options"; + configManagement.createAndVerifyConfig(testConfigName, formData); + testConfigUrl = "domain/configs/config/" + testConfigName; + testConfigJvmOptionsUrl = testConfigUrl + "/java-config/jvm-options"; } @AfterEach public void deleteConfig() { - configTest.deleteAndVerifyConfig(testConfigName); + configManagement.deleteAndVerifyConfig(testConfigName); } @@ -96,20 +97,19 @@ public void createAndDeleteOptions() { put(option1Name, "someValue"); }}; - Response response = post(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + Response response = post(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(option1Name+"=someValue")); - response = delete(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + response = delete(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); jvmOptions = getJvmOptions(response); assertFalse(jvmOptions.contains(option1Name+"=someValue")); } - // http://java.net/jira/browse/GLASSFISH-19069 @Test public void createAndDeleteOptionsWithBackslashes() { final String optionName = "-Dfile" + generateRandomString(); @@ -118,15 +118,15 @@ public void createAndDeleteOptionsWithBackslashes() { put(optionName, escape(optionValue)); }}; - Response response = post(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + Response response = post(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(optionName+"="+optionValue)); - response = delete(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + response = delete(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); jvmOptions = getJvmOptions(response); assertFalse(jvmOptions.contains(optionName+"="+optionValue)); } @@ -140,18 +140,18 @@ public void createAndDeleteOptionsWithoutValues() { put(option2Name, ""); }}; - Response response = post(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + Response response = post(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(option1Name)); assertFalse(jvmOptions.contains(option1Name+"=")); assertTrue(jvmOptions.contains(option2Name)); assertFalse(jvmOptions.contains(option2Name+"=")); - response = delete(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + response = delete(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); jvmOptions = getJvmOptions(response); assertFalse(jvmOptions.contains(option1Name)); assertFalse(jvmOptions.contains(option2Name)); @@ -167,9 +167,9 @@ public void testIsolatedOptionsCreationOnNewConfig() { }}; // Test new config to make sure option is there - Response response = post(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + Response response = post(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(optionName)); @@ -183,29 +183,21 @@ public void testIsolatedOptionsCreationOnNewConfig() { public void testProfilerJvmOptions() { final String profilerName = "profiler" + generateRandomString(); final String optionName = "-Doption" + generateRandomString(); - Map attrs = new HashMap<>() {{ - put("name", profilerName); - put("target", testConfigName); - }}; - Map newOptions = new HashMap<>() {{ -// put("target", testConfigName); -// put("profiler", "true"); - put(optionName, ""); - }}; - - deleteProfiler(URL_TEST_CONFIG + "/java-config/profiler/delete-profiler", testConfigName, false); + Map attrs = Map.of("name", profilerName, "target", testConfigName); + Map newOptions = Map.of(optionName, ""); + deleteProfiler(testConfigUrl + "/java-config/profiler/delete-profiler", testConfigName, false); - Response response = post(URL_TEST_CONFIG + "/java-config/create-profiler", attrs); + Response response = post(testConfigUrl + "/java-config/create-profiler", attrs); assertEquals(200, response.getStatus()); - response = post(URL_TEST_CONFIG + "/java-config/profiler/jvm-options", newOptions); + response = post(testConfigUrl + "/java-config/profiler/jvm-options", newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG + "/java-config/profiler/jvm-options"); + response = get(testConfigUrl + "/java-config/profiler/jvm-options"); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(optionName)); - deleteProfiler(URL_TEST_CONFIG + "/java-config/profiler/delete-profiler", testConfigName, true); + deleteProfiler(testConfigUrl + "/java-config/profiler/delete-profiler", testConfigName, true); } @Test @@ -216,16 +208,16 @@ public void testJvmOptionWithColon() { put(escape(optionName), optionValue); }}; - Response response = post(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + Response response = post(testConfigJvmOptionsUrl, newOptions); + assertEquals(200, response.getStatus()); + response = get(testConfigJvmOptionsUrl); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); -// assertEquals(200, response.getStatus()); List jvmOptions = getJvmOptions(response); assertTrue(jvmOptions.contains(optionName+"="+optionValue)); - response = delete(URL_TEST_CONFIG_JVM_OPTIONS, newOptions); + response = delete(testConfigJvmOptionsUrl, newOptions); assertEquals(200, response.getStatus()); - response = get(URL_TEST_CONFIG_JVM_OPTIONS); + response = get(testConfigJvmOptionsUrl); jvmOptions = getJvmOptions(response); assertFalse(jvmOptions.contains(optionName+"="+optionValue)); } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java similarity index 82% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java index 24afd793554..27dcde002ab 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MetadataITest.java @@ -24,14 +24,15 @@ import org.glassfish.admin.rest.client.utils.MarshallingUtils; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author jasonlee */ -public class MetadataTest extends RestTestBase { +public class MetadataITest extends RestTestBase { private static final String URL_CONFIG = "domain/configs/config.json"; private static final String URL_UPTIMECOMMAND = "domain/uptime.json"; @@ -46,11 +47,12 @@ public void configParameterTest() { // Another dumb test to make sure that "name" shows up on the HTML page response = getClient().target(getAddress(URL_CONFIG)).request().get(Response.class); - assertTrue(response.readEntity(String.class).contains("extraProperties")); + String data = response.readEntity(String.class); + assertThat(data, stringContainsInOrder("extraProperties")); } @Test - public void UpTimeMetadaDataTest() { + public void upTimeMetadaDataTest() { Response response = options(URL_UPTIMECOMMAND); assertEquals(200, response.getStatus()); @@ -60,10 +62,10 @@ public void UpTimeMetadaDataTest() { // Another dumb test to make sure that "extraProperties" shows up on the HTML page response = getClient().target(getAddress(URL_UPTIMECOMMAND)).request().get(Response.class); String resp = response.readEntity(String.class); - assertTrue(resp.contains("extraProperties")); + assertThat(resp, stringContainsInOrder("extraProperties")); // test to see if we get the milliseconds parameter description which is an //optional param metadata for the uptime command - assertTrue(resp.contains("milliseconds")); - assertTrue(resp.contains("GET")); + assertThat(resp, stringContainsInOrder("milliseconds")); + assertThat(resp, stringContainsInOrder("GET")); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java similarity index 54% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java index 42a40a9efc6..0ad5cdfc300 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/MonitoringITest.java @@ -19,36 +19,30 @@ import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.Response.Status; - import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Disabled; +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.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Mitesh Meswani */ -@Disabled -public class MonitoringTest 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"; +@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"; - @Override - protected String getContextRoot() { - return CONTEXT_ROOT_MONITORING; - } - @Test - public void initializeMonitoring() { - // Enable monitoring + @Order(1) + public void enableMonitoring() { String url = getManagementURL(MONITORING_RESOURCE_URL); Map payLoad = new HashMap<>() { { @@ -71,7 +65,7 @@ public void initializeMonitoring() { } }; Response response = post(url, payLoad); - assertEquals(200, response.getStatus()); + assertEquals(202, response.getStatus()); } /** @@ -79,9 +73,24 @@ public void initializeMonitoring() { * Strategy - Call /monitoring/domain and assert that "server" is present as child element */ @Test + @Order(2) public void testBaseURL() { - Map entity = getChildResources(get("domain")); // monitoring/domain - assertNotNull(entity.get("server")); + Response response = get("domain"); + assertEquals(200, response.getStatus()); + // monitoring/domain + Map entity = getChildResources(response); + assertNull(entity.get("server"), entity.toString()); + } + + /** + * Objective - Verify that invalid resources returns 404 + * Strategy - Request an invalid resource under monitoring and ensure that 404 is returned + */ + @Test + @Order(10) + public void testInvalidResource() { + Response response = get("domain/server/foo"); + assertEquals(404, response.getStatus(), "Did not receive "); } /** @@ -89,54 +98,77 @@ public void testBaseURL() { * Strategy - create a resource with "." in name and then try to access it */ @Test + @Order(20) public void testDot() { // Step 1- Create a resource with "." - final String POOL_NAME = "poolNameWith.dot"; + final String poolNameWithDot = "poolNameWith.dot"; // Clean up from leftover from previous run - String url = getManagementURL(JDBC_CONNECTION_POOL_URL + '/' + POOL_NAME); - delete(url); + String url = getManagementURL(JDBC_CONNECTION_POOL_URL + '/' + poolNameWithDot); + Response responseDel = delete(url); + assertEquals(202, responseDel.getStatus()); url = getManagementURL(JDBC_CONNECTION_POOL_URL); Map payLoad = new HashMap<>() { { - put("name", POOL_NAME); + put("name", poolNameWithDot); put("resType", "javax.sql.DataSource"); put("datasourceClassname", "foo.bar"); } }; Response response = post(url, payLoad); - assertEquals(200, response.getStatus()); + assertEquals(202, response.getStatus()); // Step 2- Ping the connection pool to generate some monitoring data url = getManagementURL(PING_CONNECTION_POOL_URL); - payLoad.clear(); - payLoad.put("id", POOL_NAME); - get(url, payLoad); - - // Step 3 - Access monitoring tree to assert it is accessible - response = get("domain/server/resources/"+ POOL_NAME); - assertEquals(200, response.getStatus()); - Map responseEntity = getEntityValues(response); - assertTrue(responseEntity.size() > 0, "No Monitoring data found for pool " + POOL_NAME); + Response responsePing = get(url, Map.of("id", poolNameWithDot)); + assertEquals(202, responsePing.getStatus()); + + // 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 responseEntity = getEntityValues(responsePool); +// assertThat("No Monitoring data found for pool " + poolNameWithDot, responseEntity, aMapWithSize(2)); } - /** - * Objective - Verify that invalid resources returns 404 - * Strategy - Request an invalid resource under monitoring and ensure that 404 is returned - */ + @Test - public void testInvalidResource() { - Response response = get("domain/server/foo"); - assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus(), "Did not receive "); + @Order(1000) + public void testCleanup() { + String url = getManagementURL(MONITORING_RESOURCE_URL); + Map 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"); + } + }; + 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; - } - - } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java similarity index 66% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java index d51c7d9aca4..46cb69071a5 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NetworkListenerITest.java @@ -23,34 +23,30 @@ import java.util.Map; import org.codehaus.jettison.json.JSONObject; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** - * * @author jasonlee */ -public class NetworkListenerTest extends RestTestBase { +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"; @Test - @Disabled public void createHttpListener() { - final String redirectProtocolName = "http-redirect"; //protocol_" + generateRandomString(); - final String portUniProtocolName = "pu-protocol"; //protocol_" + generateRandomString(); + final String redirectProtocolName = "http-redirect"; + final String portUniProtocolName = "pu-protocol"; - final String redirectFilterName = "redirect-filter"; //filter_" + generateRandomString(); - final String finderName1 = "http-finder"; //finder" + generateRandomString(); - final String finderName2 = "http-redirect"; //finder" + generateRandomString(); + final String redirectFilterName = "redirect-filter"; + final String finderName1 = "http-finder"; + final String finderName2 = "http-redirect"; try { - Response response = post("domain/set", new HashMap() {{ - put("configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol", "http-listener-1"); - }}); + 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()); @@ -59,18 +55,15 @@ public void createHttpListener() { // 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, new HashMap() {{ put ("securityenabled", "false"); put("id", redirectProtocolName); }}); + response = post(URL_PROTOCOL, Map.of("securityenabled", "false", "id", redirectProtocolName)); assertEquals(200, response.getStatus()); - response = post(URL_PROTOCOL, new HashMap() {{ put ("securityenabled", "false"); put("id", portUniProtocolName); }}); + 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", - new HashMap() {{ - put ("id", redirectFilterName); - put ("protocol", redirectProtocolName); - put ("classname", "org.glassfish.grizzly.config.portunif.HttpRedirectFilter"); - }}); + 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 @@ -94,40 +87,33 @@ public void createHttpListener() { // 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", new HashMap() {{ - put("protocol", portUniProtocolName); - }}); + response = 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"); - assertTrue(response.readEntity(String.class).contains("http-listener-2")); + 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 { -// ClientResponse response = post("/domain/set", new HashMap() {{ - Response response = post("/domain/configs/config/server-config/network-config/network-listeners/network-listener/http-listener-1", new HashMap() {{ - put("protocol", "http-listener-1"); - }}); + 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", - new HashMap() {{ - put("protocol", portUniProtocolName); - put("id", finderName1); - }} ); + Map.of("protocol", portUniProtocolName, "id", finderName1)); assertEquals(200, response.getStatus()); response = delete(URL_PROTOCOL + "/" + portUniProtocolName + "/delete-protocol-finder", - new HashMap() {{ - put("protocol", portUniProtocolName); - put("id", finderName2); - }} ); + Map.of("protocol", portUniProtocolName, "id", finderName2)); assertEquals(200, response.getStatus()); - response = delete(URL_PROTOCOL + "/" + redirectProtocolName + "/protocol-chain-instance-handler/protocol-chain/protocol-filter/" + redirectFilterName, - new HashMap() {{ put("protocol", redirectProtocolName); }} ); + 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()); } - } @Test diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java similarity index 76% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java index 6aa002a189e..e248c4b5324 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/NoCLICommandResourceCreationITest.java @@ -24,21 +24,20 @@ import java.util.HashMap; 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.getXmlForProperties; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Mitesh Meswani */ -public class NoCLICommandResourceCreationTest extends RestTestBase { +public class NoCLICommandResourceCreationITest extends RestTestBase { private static final String URL_SERVER_PROPERTY = "domain/servers/server/server/property"; @Test public void testPropertyCreation() { - final String propertyKey = "propertyName" + generateRandomString(); + final String propertyKey = "propertyName" + generateRandomString(); String propertyValue = generateRandomString(); //Create a property @@ -47,7 +46,7 @@ public void testPropertyCreation() { param.put("value",propertyValue); Response response = getClient().target(getAddress(URL_SERVER_PROPERTY)) .request(RESPONSE_TYPE) - .post(Entity.entity(MarshallingUtils.getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class); + .post(Entity.entity(getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class); assertEquals(200, response.getStatus()); //Verify the property got created @@ -55,21 +54,21 @@ public void testPropertyCreation() { response = get (propertyURL); assertEquals(200, response.getStatus()); Map entity = getEntityValues(response); - assertTrue(entity.get("name").equals(propertyKey)); - assertTrue(entity.get("value").equals(propertyValue)); + assertEquals(propertyKey, entity.get("name")); + assertEquals(propertyValue, entity.get("value")); // Verify property update propertyValue = generateRandomString(); param.put("value", propertyValue); response = getClient().target(getAddress(URL_SERVER_PROPERTY)) .request(RESPONSE_TYPE) - .put(Entity.entity(MarshallingUtils.getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class); + .put(Entity.entity(getXmlForProperties(param), MediaType.APPLICATION_XML), Response.class); assertEquals(200, response.getStatus()); response = get (propertyURL); assertEquals(200, response.getStatus()); entity = getEntityValues(response); - assertTrue(entity.get("name").equals(propertyKey)); - assertTrue(entity.get("value").equals(propertyValue)); + 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()); diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java similarity index 83% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java index 1759439188a..797c086880d 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PartialUpdateITest.java @@ -17,10 +17,10 @@ package org.glassfish.nucleus.admin.rest; -import java.util.HashMap; +import jakarta.ws.rs.core.Response; + import java.util.Map; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -28,18 +28,15 @@ /** * @author jasonlee */ -public class PartialUpdateTest extends RestTestBase { +public class PartialUpdateITest extends RestTestBase { @Test - @Disabled - // TODO: rework this to use something nucleus-friendly public void testPartialUpdate() { - final String endpoint = JdbcTest.BASE_JDBC_CONNECTION_POOL_URL + "/DerbyPool"; + final String endpoint = URL_JDBC_CONNECTION_POOL + "/DerbyPool"; final String newDesc = generateRandomString(); Map origAttrs = getEntityValues(get(endpoint)); - Map newAttrs = new HashMap<>() {{ - put ("description", newDesc); - }}; - post(endpoint, newAttrs); + Map newAttrs = Map.of("description", newDesc); + Response response = post(endpoint, newAttrs); + assertEquals(200, response.getStatus()); Map updatedAttrs = getEntityValues(get(endpoint)); assertEquals(newDesc, updatedAttrs.get("description")); assertEquals(origAttrs.get("driverClassname"), updatedAttrs.get("driverClassname")); diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java similarity index 94% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java index 95558971df2..9ca20a451e0 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/PropertiesBagITest.java @@ -28,20 +28,22 @@ import org.codehaus.jettison.json.JSONArray; import org.glassfish.admin.rest.client.utils.MarshallingUtils; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; 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.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; /** * @author jasonlee */ -public class PropertiesBagTest extends RestTestBase { +public class PropertiesBagITest extends RestTestBase { private static final String PROP_DOMAIN_NAME = "administrative.domain.name"; private static final String URL_DOMAIN_PROPERTIES = "domain/property"; @@ -69,7 +71,6 @@ public void serverProperties() { } @Test - @Disabled public void propsWithEmptyValues() { List> properties = new ArrayList<>(); final String empty = "empty" + generateRandomNumber(); @@ -99,7 +100,6 @@ public void propsWithEmptyValues() { } @Test - @Disabled public void testOptimizedPropertyHandling() { // First, test changing one property and adding a new List> properties = new ArrayList<>(); @@ -160,19 +160,19 @@ public void testOptimizedPropertyHandling() { // FIXME: the prop name can not contain . // need to remove the . test when http://java.net/jira/browse/GLASSFISH-15418 is fixed @Test - @Disabled public void testPropertiesWithDots() { List> properties = new ArrayList<>(); - final String prop = "some.property.with.dots." + generateRandomNumber(); + final String key = "some.property.with.dots." + generateRandomNumber(); final String description = "This is the description"; final String value = generateRandomString(); - properties.add(createProperty(prop, value, description)); + properties.add(createProperty(key, value, description)); createProperties(URL_DERBYPOOL_PROPERTIES, properties); + List> newProperties = getProperties(get(URL_DERBYPOOL_PROPERTIES)); - Map newProp = getProperty(newProperties, prop); - assertTrue(newProp != null); - assertTrue(value.equals(newProp.get("value"))); - assertTrue(description.equals(newProp.get("description"))); + Map newProp = getProperty(newProperties, key); + assertNotNull(newProp); + assertEquals(value, newProp.get("value")); + assertNull(newProp.get("description"), "Descriptions are not returned at this moment: " + newProp); } // This operation is taking a REALLY long time from the console, probably due @@ -183,7 +183,6 @@ public void testPropertiesWithDots() { // then update only one the object's properties, which should be a very quick, // inexpensive operation. @Test - @Disabled public void testJmsRaCreateAndUpdate() { List> props = new ArrayList<>(){{ add(createProperty("AddressListBehavior", "random")); @@ -238,7 +237,6 @@ public void testJmsRaCreateAndUpdate() { delete(URL+"/jmsra"); } - @Disabled("Disable this test for now. The functionality this tests is not available in nucleus") @Test public void test20810() { Map payload = new HashMap<>(); @@ -251,18 +249,17 @@ public void test20810() { payload.put("ssoFailoverEnabled","false"); final String wcaUri = "domain/configs/config/default-config/availability-service/web-container-availability"; - Response r = post(wcaUri, payload); - checkStatus(r); + Response response = post(wcaUri, payload); + assertThat(response.getStatus(), equalTo(200)); - checkStatus(get(wcaUri)); + assertThat(get(wcaUri).getStatus(), equalTo(200)); - r = getClient() + response = getClient() .target(getAddress("domain/configs/config/default-config/availability-service/web-container-availability/property")). request(getResponseType()) .post(Entity.json(new JSONArray()), Response.class); - checkStatus(r); - - checkStatus(get(wcaUri)); + assertThat(response.getStatus(), equalTo(200)); + assertThat(get(wcaUri).getStatus(), equalTo(200)); } private String buildPropertyList(List> props) { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java similarity index 98% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java index c5b219f8151..e6b2fc9e880 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ProvidersITest.java @@ -26,7 +26,7 @@ /** * @author jasonlee */ -public class ProvidersTest extends RestTestBase { +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"; @@ -35,7 +35,7 @@ public class ProvidersTest extends RestTestBase { private static final String URL_STRING_LIST_RESULT = "domain/configs/config/server-config/java-config/jvm-options"; private static String URL_TREE_NODE; - public ProvidersTest() { + public ProvidersITest() { URL_TREE_NODE = "http://localhost:" + getParameter("admin.port", "4848") + "/monitoring/domain"; } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java similarity index 90% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java index 826f0719ba3..ce658d3dc02 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ResourceRefITest.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -30,13 +29,12 @@ /** * @author jasonlee */ -public class ResourceRefTest extends RestTestBase { +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"; @Test - @Disabled public void testCreatingResourceRef() { final String instanceName = "instance_" + generateRandomString(); final String jdbcResourceName = "jdbc_" + generateRandomString(); @@ -63,12 +61,9 @@ public void testCreatingResourceRef() { response = post(URL_RESOURCE_REF, resourceRef); assertEquals(200, response.getStatus()); - } catch (Exception e) { - e.printStackTrace(); } finally { - Response response = delete("domain/servers/server/" + instanceName + "/resource-ref/" + jdbcResourceName, new HashMap() {{ - put("target", instanceName); - }}); + 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()); 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 44a54e54bb8..3cc5ef7070d 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 @@ -29,6 +29,7 @@ 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; @@ -53,6 +54,11 @@ 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.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.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -62,20 +68,25 @@ import static org.glassfish.nucleus.test.tool.NucleusTestUtils.ADMIN_PASSWORD; import static org.glassfish.nucleus.test.tool.NucleusTestUtils.ADMIN_USER; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.jupiter.api.Assertions.assertAll; 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 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; @@ -131,6 +142,21 @@ protected void resetClient() { client = null; } + public void createAndVerifyConfig(String configName, MultivaluedMap configData) { + Response response = post(URL_CONFIGS + "/copy-config", configData); + assertThat(response.getStatus(), equalTo(200)); + + response = get(URL_CONFIGS + "/config/" + configName); + assertEquals(200, response.getStatus()); + } + + public void deleteAndVerifyConfig(String configName) { + Response response = post(URL_CONFIGS + "/config/" + configName + "/delete-config"); + assertThat(response.getStatus(), equalTo(200)); + + response = get(URL_CONFIGS + "/config/" + configName); + assertEquals(404, response.getStatus()); + } public String createCluster() { final String clusterName = "cluster_" + generateRandomString(); @@ -141,23 +167,23 @@ public String createCluster() { public void createCluster(final String clusterName) { Map newCluster = Map.of("id", clusterName); Response response = post(URL_CLUSTER, newCluster); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } public void startCluster(String clusterName) { Response response = post(URL_CLUSTER + "/" + clusterName + "/start-cluster"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } public void stopCluster(String clusterName) { Response response = post(URL_CLUSTER + "/" + clusterName + "/stop-cluster"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } public void createClusterInstance(final String clusterName, final String instanceName) { Response response = post("domain/create-instance", Map.of("cluster", clusterName, "id", instanceName, "node", "localhost-domain1")); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } public void deleteCluster(String clusterName) { @@ -172,10 +198,10 @@ public void deleteCluster(String clusterName) { String instanceName = instance.get("name"); if (!"NOT_RUNNING".equalsIgnoreCase(status)) { response = post("domain/servers/server/" + instanceName + "/stop-instance"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } response = delete("domain/servers/server/" + instanceName + "/delete-instance"); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); } } } @@ -185,26 +211,26 @@ public void deleteCluster(String clusterName) { assertEquals(404, response.getStatus()); } - public Map deployApp (final File archive, final String contextRoot, final String name) { + public Map deployApp(final File archive, final String contextRoot, final String name) { Map app = Map.of( "id", archive, "contextroot", contextRoot, "name", name ); Response response = postWithUpload(URL_APPLICATION_DEPLOY, app); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); return getEntityValues(get(URL_APPLICATION_DEPLOY + "/" + app.get("name"))); } public void addAppRef(final String applicationName, final String targetName){ - Response cr = post("domain/servers/server/" + targetName + "/application-ref", + Response response = post("domain/servers/server/" + targetName + "/application-ref", Map.of("id", applicationName, "target", targetName)); - checkStatus(cr); + assertThat(response.getStatus(), equalTo(200)); } public Response undeployApp(String appName) { Response response = delete(URL_APPLICATION_DEPLOY + "/" + appName); - checkStatus(response); + assertThat(response.getStatus(), equalTo(200)); return response; } @@ -234,13 +260,6 @@ protected int generateRandomNumber(int max) { return Math.abs(r.nextInt(max - 1)) + 1; } - protected void checkStatus(Response response) { - assertAll("response status", - () -> assertThat(response.getStatus(), greaterThanOrEqualTo(200)), - () -> assertThat(response.getStatus(), lessThan(300)) - ); - } - protected String getResponseType() { return RESPONSE_TYPE; } @@ -325,7 +344,7 @@ protected Response put(String address) { protected Response postWithUpload(String address, Map payload) { FormDataMultiPart form = new FormDataMultiPart(); for (Map.Entry entry : payload.entrySet()) { - if ((entry.getValue() instanceof File)) { + if (entry.getValue() instanceof File) { form.getBodyParts(). add((new FileDataBodyPart(entry.getKey(), (File) entry.getValue()))); } else { @@ -357,16 +376,16 @@ protected Response delete(String address, Map payload) { * @return */ protected Map getEntityValues(Response response) { - Map map = new HashMap<>(); - String xml = response.readEntity(String.class); - Map responseMap = MarshallingUtils.buildMapFromDocument(xml); - Object obj = responseMap.get("extraProperties"); - if (obj != null) { - return (Map) ((Map) obj).get("entity"); - } else { - return map; + Map responseMap = MarshallingUtils.buildMapFromDocument(xml); + if (responseMap == null) { + return null; + } + Map obj = (Map) responseMap.get("extraProperties"); + if (obj == null) { + return null; } + return (Map) obj.get("entity"); } protected List getCommandResults(Response response) { @@ -394,6 +413,7 @@ protected List getCommandResults(Response response) { protected Map getChildResources(Response response) { Map responseMap = MarshallingUtils.buildMapFromDocument(response.readEntity(String.class)); + LOG.log(Level.INFO, "responseMap: \n{0}", responseMap); Map extraProperties = (Map) responseMap.get("extraProperties"); if (extraProperties != null) { return extraProperties.get("childResources"); @@ -453,4 +473,30 @@ protected static String getParameter(String paramName, String defaultValue) { return value; } + + + protected static File getEar(final String appName) { + final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class).addAsModule(getWar(appName), "simple.war"); + LOG.info(ear.toString(true)); + try { + File tempFile = File.createTempFile(appName, ".ear"); + ear.as(ZipExporter.class).exportTo(tempFile, true); + return tempFile; + } catch (IOException e) { + throw new IllegalStateException("Deployment failed - cannot load the input archive!", e); + } + } + + protected static File getWar(final String appName) { + final WebArchive war = ShrinkWrap.create(WebArchive.class).addPackage(HelloServlet.class.getPackage()); + LOG.info(war.toString(true)); + try { + File tempFile = File.createTempFile(appName, ".war"); + war.as(ZipExporter.class).exportTo(tempFile, true); + return tempFile; + } catch (IOException e) { + 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/SystemPropertiesTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java similarity index 93% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java index f29a0c283b0..a5e79f4b506 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/SystemPropertiesITest.java @@ -32,7 +32,7 @@ /** * @author jasonlee */ -public class SystemPropertiesTest extends RestTestBase { +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"; @@ -45,7 +45,7 @@ public void getSystemProperties() { Response response = get(URL_DAS_SYSTEM_PROPERTIES); assertEquals(200, response.getStatus()); List> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); - assertNotNull(systemProperties); // This may or may not be empty, depending on whether or not other tests failed + assertNotNull(systemProperties); } @Test @@ -60,7 +60,7 @@ public void createSystemProperties() { assertEquals(200, response.getStatus()); response = get(URL_DAS_SYSTEM_PROPERTIES); List> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); - assertNotNull(systemProperties); // This may or may not be empty, depending on whether or not other tests failed + assertNotNull(systemProperties); int testPropsFound = 0; for (Map systemProperty : systemProperties) { @@ -87,8 +87,9 @@ public void createPropertiesWithColons() { Response response = post(URL_DAS_SYSTEM_PROPERTIES, payload); assertEquals(200, response.getStatus()); response = get(URL_DAS_SYSTEM_PROPERTIES); - List> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); - assertNotNull(systemProperties); // This may or may not be empty, depending on whether or not other tests failed + List> systemProperties = getSystemProperties( + MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); + assertNotNull(systemProperties); int testPropsFound = 0; for (Map systemProperty : systemProperties) { @@ -100,7 +101,7 @@ public void createPropertiesWithColons() { assertEquals(1, testPropsFound); - response = delete(URL_DAS_SYSTEM_PROPERTIES+"/"+prop1); + response = delete(URL_DAS_SYSTEM_PROPERTIES + "/" + prop1); assertEquals(200, response.getStatus()); } @@ -150,7 +151,7 @@ private void createAndTestConfigProperty(final String propertyName, final String List> systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); Map sysProp = getSystemProperty(propertyName, systemProperties); assertNotNull(sysProp); - assertEquals(sysProp.get("value"), propertyValue); + assertEquals(propertyValue, sysProp.get("value")); } private void createAndTestClusterOverride(final String propertyName, final String defaultValue, final String propertyValue, final String clusterName) { @@ -191,8 +192,8 @@ private void createAndTestInstanceOverride(final String propertyName, final Stri systemProperties = getSystemProperties(MarshallingUtils.buildMapFromDocument(response.readEntity(String.class))); sysProp = getSystemProperty(propertyName, systemProperties); assertNotNull(sysProp); - assertEquals(sysProp.get("value"), propertyValue); - assertEquals(sysProp.get("defaultValue"), defaultValue); + assertEquals(propertyValue, sysProp.get("value")); + assertEquals(defaultValue, sysProp.get("defaultValue")); } private List> getSystemProperties(Map map) { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java similarity index 99% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java index 18b4fe75499..92a3619ba6a 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/TokenAuthenticationITest.java @@ -38,7 +38,7 @@ /** * @author Mitesh Meswani */ -public class TokenAuthenticationTest extends RestTestBase { +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"; diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigTest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java similarity index 95% rename from appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigTest.java rename to appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java index 875461b53d9..5016830e462 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigTest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/admin/rest/ZeroConfigITest.java @@ -21,7 +21,6 @@ import java.util.Map; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,7 +36,7 @@ * data. * @author jdlee */ -public class ZeroConfigTest extends RestTestBase { +public class ZeroConfigITest extends RestTestBase { public static final String BASE_SERVER_CONFIG_URL = "domain/configs/config/server-config"; /** * Currently (6/29/2012), the transaction-service element is missing from @@ -45,7 +44,6 @@ public class ZeroConfigTest extends RestTestBase { * zero-config is fully implemented and integrated. */ @Test - @Disabled public void testTransactionService() { final Response response = get(BASE_SERVER_CONFIG_URL + "/transaction-service"); assertEquals(200, response.getStatus()); 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 index c80f703f271..866c4a01d24 100644 --- 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 @@ -28,6 +28,6 @@ public class DomainLifecycleExtension extends StopDomainExtension implements Bef @Override public void beforeAll(ExtensionContext context) throws Exception { - NucleusTestUtils.nadmin(20000, "start-domain", "domain1"); + NucleusTestUtils.nadmin(20000, "start-domain", "--debug", "domain1"); } } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/webapp/HelloServlet.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/webapp/HelloServlet.java new file mode 100644 index 00000000000..7db815e229a --- /dev/null +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/nucleus/test/webapp/HelloServlet.java @@ -0,0 +1,38 @@ +/* + * 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.webapp; + +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +/** + * @author David Matejcek + */ +@WebServlet(urlPatterns = "/") +public class HelloServlet extends HttpServlet { + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + response.getOutputStream().print("Hello!"); + } + +} diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml index 707c4ac091c..e6feadccc19 100644 --- a/nucleus/parent/pom.xml +++ b/nucleus/parent/pom.xml @@ -490,6 +490,12 @@ ${jmh.version} test + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven-archive + 3.1.4 + test + commons-io