Skip to content

Commit

Permalink
#23507 Fixed admin-tests
Browse files Browse the repository at this point in the history
- 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 <dmatej@seznam.cz>
  • Loading branch information
dmatej committed Apr 12, 2022
1 parent 72b6570 commit eb3c95f
Show file tree
Hide file tree
Showing 52 changed files with 812 additions and 855 deletions.
20 changes: 11 additions & 9 deletions appserver/tests/admin/admin-extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@
<version>7.0.0-SNAPSHOT</version>
</parent>
<artifactId>test-progress-admin-extension</artifactId>
<name>GlassFish Admin Tests - Progress Admin Extension</name>
<packaging>glassfish-jar</packaging>

<name>GlassFish Admin Tests - Progress Admin Extension</name>

<dependencies>
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>glassfish-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>common-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.admin</groupId>
<artifactId>config-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2</artifactId>
<artifactId>hk2-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-junitrunner</artifactId>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -31,7 +33,6 @@
import org.jvnet.hk2.annotations.Service;

/**
*
* @author mmares
*/
@Service(name = "progress-custom")
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -128,7 +124,7 @@ public long getMilis() {

@Override
public String toString() {
return origInteval;
return origInterval;
}

}
Expand All @@ -149,7 +145,7 @@ private int getStepCount() {
@Override
public void execute(AdminCommandContext context) {
ProgressStatus ps = context.getProgressStatus();
parsedIntervals = new ArrayList<Interval>(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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -73,8 +70,6 @@ public void execute(AdminCommandContext context) {
}

progressStatus.complete("Finished outer command");

System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}

private void doSomeLogic() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,5 +43,4 @@ public void execute(AdminCommandContext context) {
cmd.noTotalSteps = true;
cmd.execute(context);
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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
*/
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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.
*
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit eb3c95f

Please sign in to comment.