Skip to content

Commit

Permalink
extend test - sign document
Browse files Browse the repository at this point in the history
  • Loading branch information
kathrin-7978 committed Feb 4, 2025
1 parent 5585292 commit e8a2b54
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pdf-over-gui/src/test/java/gui/tests/AbstractSignatureUITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.config.ConfigurationManager;
import lombok.NonNull;
import org.apache.commons.io.FilenameUtils;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -26,7 +27,7 @@
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

public class AbstractSignatureUITest {

Expand All @@ -38,6 +39,7 @@ public class AbstractSignatureUITest {
private static final File inputFile = new File("src/test/resources/TestFile.pdf");
private static final String outputDir = inputFile.getAbsoluteFile().getParent();
private Profile currentProfile = Profile.SIGNATURBLOCK_SMALL;
private final String postFix = "_superSigned";

private static final Logger logger = LoggerFactory
.getLogger(AbstractSignatureUITest.class);
Expand Down Expand Up @@ -95,11 +97,22 @@ protected void setCredentials() {
ICondition widgetExists = new WidgetExitsCondition(str("mobileBKU.number"));
bot.waitUntil(widgetExists, 20000);
bot.textWithLabel(str("mobileBKU.number")).setText("TestUser-1902503362");
bot.textWithLabel(str("mobileBKU.password")).setText("123456789");
bot.button(str("common.Ok")).click();
}
catch (WidgetNotFoundException wnf) {
bot.button(str("common.Cancel")).click();
fail(wnf.getMessage());
}

File output = new File(getPathOutputFile());
ICondition outputExists = new FileExistsCondition(output);
bot.waitUntil(outputExists, 20000);

if(!output.exists()) {
bot.button(str("common.Cancel")).click();
}
assertTrue(output.exists(), "Received signed PDF");
}

private static void setProperty(@NonNull Properties props, @NonNull String key, @NonNull String value) { props.setProperty(key, value); }
Expand All @@ -108,7 +121,6 @@ private void setConfig() {
ConfigurationManager cm = new ConfigurationManager();
Point size = cm.getMainWindowSize();

String postFix = "_superSigned";
Map<String, String> testParams = Map.ofEntries(
Map.entry(Constants.CFG_BKU, cm.getDefaultBKUPersistent().name()),
Map.entry(Constants.CFG_KEYSTORE_PASSSTORETYPE, "memory"),
Expand All @@ -135,4 +147,20 @@ private void setConfig() {
}
}

/**
* Returns path of the signed document.
*/
private String getPathOutputFile() {
String fileNameSigned = inputFile
.getName()
.substring(0, inputFile.getName().lastIndexOf('.'))
.concat(postFix)
.concat(".pdf");
String pathOutputFile = FilenameUtils.separatorsToSystem(outputDir
.concat("/")
.concat(fileNameSigned));
assertNotNull(pathOutputFile);
return pathOutputFile;
}

}
25 changes: 25 additions & 0 deletions pdf-over-gui/src/test/java/gui/tests/FileExistsCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gui.tests;

import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;

import java.io.File;

public class FileExistsCondition extends DefaultCondition {

private final File file;

public FileExistsCondition(File file) {
this.file = file;
}

@Override
public boolean test() {
return file.exists();
}

@Override
public String getFailureMessage() {
return String.format("Could not create output file %s", file.getName());
}

}

0 comments on commit e8a2b54

Please sign in to comment.