389 lines
16 KiB
Java
389 lines
16 KiB
Java
package qualification;
|
|
|
|
import java.nio.file.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.*;
|
|
import javafx.application.Platform;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.scene.*;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.shape.SVGPath;
|
|
import javafx.stage.*;
|
|
import javax.imageio.ImageIO;
|
|
|
|
/** Acts on the actual controls in the interactive Archiver worker. */
|
|
public final class ManagementReadersTargetProbe {
|
|
public static void premain(String dir) {
|
|
if (System.getProperty("sun.java.command", "")
|
|
.startsWith("de.neitzel.fxdesigner.target.WorkerMain "))
|
|
Thread.ofPlatform().daemon().start(() -> Worker.run(Path.of(dir)));
|
|
}
|
|
|
|
private static final class Worker {
|
|
private static <T> T fx(Callable<T> action) throws Exception {
|
|
var task = new FutureTask<>(action);
|
|
Platform.runLater(task);
|
|
return task.get(10, TimeUnit.SECONDS);
|
|
}
|
|
|
|
private static void require(boolean value, String message) {
|
|
if (!value) throw new AssertionError(message);
|
|
}
|
|
|
|
private static void run(Path dir) {
|
|
try {
|
|
Stage stage = null;
|
|
while (stage == null) {
|
|
Thread.sleep(120);
|
|
try {
|
|
stage =
|
|
fx(
|
|
() ->
|
|
Window.getWindows().stream()
|
|
.filter(
|
|
w ->
|
|
w instanceof Stage s
|
|
&& s.isShowing()
|
|
&& s.getOpacity() > 0
|
|
&& s.getTitle() != null
|
|
&& s.getTitle().startsWith("Neitzel preview"))
|
|
.map(Stage.class::cast)
|
|
.findFirst()
|
|
.orElse(null));
|
|
} catch (IllegalStateException starting) {
|
|
}
|
|
}
|
|
Stage shown = stage;
|
|
var attempt = Files.readString(dir.resolve("management-case"));
|
|
boolean management = attempt.startsWith("accounts-") || attempt.startsWith("trash-");
|
|
var root =
|
|
fx(
|
|
() -> {
|
|
shown.setWidth(management ? 900 : 920);
|
|
shown.setHeight(management ? 600 : 135);
|
|
var r = shown.getScene().getRoot();
|
|
r.applyCss();
|
|
r.layout();
|
|
return r;
|
|
});
|
|
String result =
|
|
fx(
|
|
() ->
|
|
switch (attempt) {
|
|
case "accounts-idle", "accounts-busy", "accounts-idle-edited" ->
|
|
accounts(root, attempt, dir);
|
|
case "trash-full", "trash-empty", "trash-full-edited" ->
|
|
trash(root, attempt, dir);
|
|
default -> reader(root, attempt, dir);
|
|
});
|
|
if (attempt.equals("accounts-idle")) {
|
|
fx(
|
|
() -> {
|
|
root.applyCss();
|
|
root.layout();
|
|
var display = (javafx.scene.text.Text) root.lookup("#details").lookup(".text");
|
|
require(
|
|
display.getText().contains("mail.example.invalid"),
|
|
"Account endpoint clipped: " + display.getText());
|
|
image(root, dir.resolve("management-accounts.png"));
|
|
return null;
|
|
});
|
|
}
|
|
if (attempt.equals("slides")) {
|
|
verifyPlayback(root);
|
|
result += " · automatischer Bildwechsel und Stillstand nach Pause";
|
|
}
|
|
Files.writeString(dir.resolve("result-" + attempt), result);
|
|
} catch (Throwable failure) {
|
|
var trace = new java.io.StringWriter();
|
|
failure.printStackTrace(new java.io.PrintWriter(trace));
|
|
try {
|
|
Files.writeString(dir.resolve("target-error.txt"), trace.toString());
|
|
} catch (Exception ignored) {
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void verifyPlayback(Node root) throws Exception {
|
|
// Begin on the last slide so one advance also exercises automatic wraparound.
|
|
fx(
|
|
() -> {
|
|
button(root, "next").fire();
|
|
button(root, "next").fire();
|
|
button(root, "playback").fire();
|
|
return null;
|
|
});
|
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(12);
|
|
while (!fx(() -> label(root, "reader-sample").startsWith("1 / 3"))) {
|
|
if (System.nanoTime() > deadline) throw new AssertionError("No automatic advance");
|
|
Thread.sleep(80);
|
|
}
|
|
fx(
|
|
() -> {
|
|
button(root, "playback").fire();
|
|
return null;
|
|
});
|
|
Thread.sleep(4500);
|
|
require(
|
|
fx(
|
|
() ->
|
|
label(root, "reader-sample").startsWith("1 / 3")
|
|
&& button(root, "playback").getAccessibleText().equals("Abspielen")),
|
|
"Advanced during pause");
|
|
}
|
|
|
|
private static Button button(Node root, String id) {
|
|
return (Button) Objects.requireNonNull(root.lookup("#" + id), id);
|
|
}
|
|
|
|
private static String label(Node root, String id) {
|
|
return ((Label) root.lookup("#" + id)).getText();
|
|
}
|
|
|
|
private static void enabled(Node root, String id, boolean expected) {
|
|
require(!button(root, id).isDisabled() == expected, id + " enabled=" + expected);
|
|
}
|
|
|
|
private static String accounts(Node root, String attempt, Path dir) throws Exception {
|
|
var list = (ListView<?>) root.lookup("#accounts");
|
|
require(
|
|
list.getItems().stream().map(Object::toString).toList().equals(List.of("Privat", "Büro")),
|
|
"Accounts");
|
|
if (attempt.endsWith("busy")) {
|
|
require(list.isDisabled() && label(root, "status").contains("läuft"), "Busy list/status");
|
|
for (var id :
|
|
List.of(
|
|
"create",
|
|
"configure",
|
|
"activate",
|
|
"fetch",
|
|
"verify",
|
|
"release",
|
|
"revoke",
|
|
"expire",
|
|
"close")) {
|
|
enabled(root, id, false);
|
|
button(root, id).fire();
|
|
}
|
|
require(label(root, "status").contains("läuft"), "Busy action ran");
|
|
return "Abruf läuft · alle neun Commands und Kontenauswahl gesperrt";
|
|
}
|
|
require(label(root, "details").contains("kein Serverprofil"), "Local details");
|
|
enabled(root, "configure", true);
|
|
enabled(root, "fetch", false);
|
|
list.getSelectionModel().select(1);
|
|
require(
|
|
label(root, "details").contains("mail.example.invalid")
|
|
&& label(root, "details").contains("30 Tage"),
|
|
"Office details");
|
|
if (attempt.endsWith("edited")) {
|
|
button(root, "configure").fire();
|
|
require(
|
|
label(root, "status").equals("Beispielaktion · CREATE · Büro"), "Remapped configure");
|
|
return "configure → create nach Wiederöffnen am Konto Büro ausgelöst";
|
|
}
|
|
button(root, "configure").fire();
|
|
require(label(root, "status").contains("CONFIGURE · Büro"), "Configure office");
|
|
button(root, "fetch").fire();
|
|
require(label(root, "status").contains("CONFIGURE · Büro"), "Disabled fetch executed");
|
|
for (var action :
|
|
List.of(
|
|
"activate", "fetch", "verify", "release", "expire", "revoke", "create", "close")) {
|
|
enabled(root, action, true);
|
|
button(root, action).fire();
|
|
require(
|
|
label(root, "status").contains(action.toUpperCase(Locale.ROOT) + " · Büro"), action);
|
|
}
|
|
enabled(root, "expire", false);
|
|
return "Privat ohne Serverprofil, Büro mit IMAP · Aktivierung, Abruf, Prüflauf, Freigabe,"
|
|
+ " Löschlauf und Widerruf geprüft";
|
|
}
|
|
|
|
private static String trash(Node root, String attempt, Path dir) throws Exception {
|
|
var items = (TableView<?>) root.lookup("#trash-items");
|
|
var files = (TableView<?>) root.lookup("#trash-files");
|
|
if (attempt.endsWith("empty")) {
|
|
require(
|
|
items.getItems().isEmpty()
|
|
&& files.getItems().isEmpty()
|
|
&& label(root, "summary").equals("0 Einträge · 0 Dateien"),
|
|
"Empty trash");
|
|
enabled(root, "trash-delete", false);
|
|
enabled(root, "trash-empty", false);
|
|
return "Leerer Papierkorb · beide Commands gesperrt";
|
|
}
|
|
require(label(root, "summary").equals("2 Einträge · 3 Dateien"), "Initial summary");
|
|
items.getSelectionModel().clearSelection();
|
|
require(files.getItems().isEmpty(), "Files without selection");
|
|
enabled(root, "trash-delete", false);
|
|
enabled(root, "trash-empty", true);
|
|
items.getSelectionModel().select(0);
|
|
require(
|
|
files.getItems().size() == 2
|
|
&& files.getItems().getFirst().toString().contains("Rechnung.pdf")
|
|
&& files.getItems().getLast().toString().contains("Lieferschein.md"),
|
|
"Folder file list");
|
|
enabled(root, "trash-delete", true);
|
|
items.getSelectionModel().select(1);
|
|
require(
|
|
files.getItems().size() == 3
|
|
&& files.getItems().getLast().toString().contains("Notiz.txt"),
|
|
"Multiple file list");
|
|
if (attempt.endsWith("edited")) {
|
|
button(root, "trash-delete").fire();
|
|
require(
|
|
label(root, "example-trash-action").equals("Wiederherstellen · Belege, Notiz.txt"),
|
|
"Restore selection");
|
|
require(
|
|
items.getItems().isEmpty() && files.getItems().isEmpty(), "Restored items retained");
|
|
return "delete → restoreSelection nach Wiederöffnen · Belege und Notiz.txt"
|
|
+ " wiederhergestellt";
|
|
}
|
|
image(root, dir.resolve("management-trash.png"));
|
|
items.getSelectionModel().clearAndSelect(1);
|
|
button(root, "trash-delete").fire();
|
|
require(
|
|
label(root, "example-trash-action").equals("Löschen · Notiz.txt")
|
|
&& label(root, "summary").equals("1 Einträge · 2 Dateien"),
|
|
"Delete selection");
|
|
button(root, "trash-empty").fire();
|
|
require(
|
|
label(root, "example-trash-action").equals("Leeren · Belege")
|
|
&& items.getItems().isEmpty()
|
|
&& files.getItems().isEmpty()
|
|
&& label(root, "summary").equals("0 Einträge · 0 Dateien"),
|
|
"Empty action");
|
|
enabled(root, "trash-empty", false);
|
|
enabled(root, "trash-delete", false);
|
|
return "0/1/2 ausgewählte Einträge · Dateilisten und Summary geprüft · Notiz gelöscht und"
|
|
+ " Ordner geleert";
|
|
}
|
|
|
|
private static String reader(Node root, String attempt, Path dir) throws Exception {
|
|
if (attempt.equals("attachment")) {
|
|
var pick = (ComboBox<?>) root.lookup("#example-attachments");
|
|
for (var id : List.of("open-attachment", "save-attachment")) enabled(root, id, false);
|
|
pick.getSelectionModel().selectFirst();
|
|
for (var id : List.of("open-attachment", "save-attachment")) {
|
|
enabled(root, id, true);
|
|
button(root, id).fire();
|
|
String verb = id.startsWith("open") ? "Geöffnet" : "Gespeichert";
|
|
require(
|
|
label(root, "attachment-result")
|
|
.equals(verb + " · Lieferschein.txt · LS-018 · Drei Archivkartons"),
|
|
id);
|
|
}
|
|
image(root, dir.resolve("reader-attachment.png"));
|
|
pick.getSelectionModel().clearSelection();
|
|
for (var id : List.of("open-attachment", "save-attachment")) enabled(root, id, false);
|
|
return "Ohne Auswahl gesperrt · Lieferschein.txt geöffnet und Sitzungskopie mit gleichem"
|
|
+ " Inhalt gespeichert";
|
|
}
|
|
var suffix =
|
|
switch (attempt) {
|
|
case "pdf" -> "-page";
|
|
case "epub" -> "-chapter";
|
|
case "images" -> "-image";
|
|
default -> "";
|
|
};
|
|
var back = button(root, "previous" + suffix);
|
|
var next = button(root, "next" + suffix);
|
|
var state = attempt.equals("images") ? "image-position" : "reader-sample";
|
|
var names =
|
|
switch (attempt) {
|
|
case "pdf" -> List.of("Deckblatt", "Rechnungspositionen", "Zahlungsziel");
|
|
case "epub" -> List.of("Ankunft", "Im Archiv", "Heimweg");
|
|
default -> List.of("Eingang.jpg", "Regal.jpg", "Ausgang.jpg");
|
|
};
|
|
for (int i = 0; i < 3; i++) {
|
|
require(
|
|
back.isDisabled() == (i == 0) && next.isDisabled() == (i == 2), "Boundaries at " + i);
|
|
require(label(root, state).equals((i + 1) + " / 3 · " + names.get(i)), label(root, state));
|
|
if (i == 2) break;
|
|
next.fire();
|
|
}
|
|
next.fire();
|
|
for (int i = 2; i >= 0; i--) {
|
|
require(
|
|
label(root, state).startsWith((i + 1) + " / 3") && back.isDisabled() == (i == 0),
|
|
"Return " + i);
|
|
back.fire();
|
|
}
|
|
switch (attempt) {
|
|
case "images" -> {
|
|
var svg = (SVGPath) back.getGraphic().lookup("SVGPath");
|
|
require(
|
|
"Bild zurück".equals(back.getAccessibleText())
|
|
&& "Bild zurück".equals(back.getTooltip().getText())
|
|
&& svg.getContent().startsWith("M1 8 Q8"),
|
|
"Saved accessible text / VIEW graphic");
|
|
image(root, dir.resolve("reader-icon.png"));
|
|
}
|
|
case "pdf" -> {
|
|
var page = (TextField) root.lookup("#page-number");
|
|
page.setText("3");
|
|
page.fireEvent(new ActionEvent());
|
|
require(
|
|
next.isDisabled()
|
|
&& page.getText().equals("3")
|
|
&& label(root, state).contains("Zahlungsziel"),
|
|
"Page entry");
|
|
page.setText("99");
|
|
page.fireEvent(new ActionEvent());
|
|
require(page.getText().equals("3"), "Out-of-range page");
|
|
((ChoiceBox<?>) root.lookup("#page-zoom")).getSelectionModel().select(3);
|
|
require(
|
|
((Label) root.lookup("#reader-sample")).getFont().getSize() == 24, "150 % page zoom");
|
|
}
|
|
case "epub" -> {
|
|
((ChoiceBox<?>) root.lookup("#chapters")).getSelectionModel().select(1);
|
|
require(label(root, state).contains("Im Archiv"), "Chapter choice");
|
|
var sample = (Label) root.lookup("#reader-sample");
|
|
button(root, "larger").fire();
|
|
require(sample.getFont().getSize() == 20, "Larger font");
|
|
button(root, "smaller").fire();
|
|
require(sample.getFont().getSize() == 18, "Smaller font");
|
|
}
|
|
case "slides" -> {
|
|
var play = button(root, "playback");
|
|
var playPath = ((SVGPath) play.getGraphic().lookup("SVGPath")).getContent();
|
|
require("Abspielen".equals(play.getAccessibleText()), "Play action");
|
|
play.fire();
|
|
require(
|
|
"Pause".equals(play.getAccessibleText())
|
|
&& !playPath.equals(((SVGPath) play.getGraphic().lookup("SVGPath")).getContent()),
|
|
"Pause action");
|
|
play.fire();
|
|
require(
|
|
"Abspielen".equals(play.getAccessibleText())
|
|
&& playPath.equals(((SVGPath) play.getGraphic().lookup("SVGPath")).getContent()),
|
|
"Restored Play");
|
|
}
|
|
}
|
|
if (!attempt.equals("images")) image(root, dir.resolve("reader-" + attempt + ".png"));
|
|
return switch (attempt) {
|
|
case "images" ->
|
|
"1 → 2 → 3 → 2 → 1 · Bildnamen, Grenzsperren, gespeichertes VIEW-Symbol und"
|
|
+ " Beschreibung geprüft";
|
|
case "pdf" -> "Seitennavigation und Grenzsperren · Eingabe Seite 3 · Zoom 150 %";
|
|
case "epub" ->
|
|
"Kapitelnavigation und Grenzsperren · Kapitel Im Archiv · Schrift 18 → 20 → 18";
|
|
default ->
|
|
"Bildnavigation und Grenzsperren · Abspielen → Pause → Abspielen mit wechselnder"
|
|
+ " Grafik";
|
|
};
|
|
}
|
|
|
|
private static void image(Node node, Path path) throws Exception {
|
|
var img = node.snapshot(null, null);
|
|
int w = (int) img.getWidth(), h = (int) img.getHeight();
|
|
var out = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
|
int[] pixels = new int[w * h];
|
|
img.getPixelReader()
|
|
.getPixels(0, 0, w, h, javafx.scene.image.PixelFormat.getIntArgbInstance(), pixels, 0, w);
|
|
out.setRGB(0, 0, w, h, pixels, 0, w);
|
|
ImageIO.write(out, "png", path.toFile());
|
|
}
|
|
}
|
|
}
|