Java Code Examples for org.testfx.util.WaitForAsyncUtils#waitForAsyncFx()

The following examples show how to use org.testfx.util.WaitForAsyncUtils#waitForAsyncFx() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeOptionsPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void restoreStateFrom() {
    ComboBox<KeyStringValueItem<OutlinePolicy>> outline = lookup("#outlineCombo").queryComboBox();
    ComboBox<KeyStringValueItem<AcroFormPolicy>> forms = lookup("#acroFormsCombo").queryComboBox();
    ComboBox<KeyStringValueItem<AcroFormPolicy>> toc = lookup("#tocCombo").queryComboBox();
    CheckBox blankIfOdd = lookup("#blankIfOddCheck").queryAs(CheckBox.class);
    CheckBox footer = lookup("#footerCheck").queryAs(CheckBox.class);
    CheckBox normalize = lookup("#normalizeCheck").queryAs(CheckBox.class);
    Map<String, String> data = new HashMap<>();
    data.put("outline", OutlinePolicy.ONE_ENTRY_EACH_DOC.toString());
    data.put("acroForms", AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS.toString());
    data.put("blankIfOdd", Boolean.FALSE.toString());
    data.put("footer", Boolean.TRUE.toString());
    data.put("normalize", Boolean.TRUE.toString());
    data.put("toc", ToCPolicy.DOC_TITLES.toString());
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.restoreStateFrom(data));
    assertEquals(OutlinePolicy.ONE_ENTRY_EACH_DOC, outline.getSelectionModel().getSelectedItem().getKey());
    assertEquals(AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS,
            forms.getSelectionModel().getSelectedItem().getKey());
    assertEquals(ToCPolicy.DOC_TITLES, toc.getSelectionModel().getSelectedItem().getKey());
    assertFalse(blankIfOdd.isSelected());
    assertTrue(footer.isSelected());
    assertTrue(normalize.isSelected());
}
 
Example 2
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
@Category(NoHeadless.class)
public void onSaveWorkspaceEncryptedPwdStored() {
    new DefaultUserContext().setBooleanPreference(BooleanUserPreference.SAVE_PWD_IN_WORKSPACE, true);
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.REQUESTED);
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.LOADING);
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.ENCRYPTED);
    });
    WaitForAsyncUtils.waitForFxEvents();
    clickOn(".glyph-icon");
    write("pwd").clickOn(DefaultI18nContext.getInstance().i18n("Unlock"));
    Map<String, String> data = new HashMap<>();
    victim.saveStateTo(data);
    assertEquals(EncryptionUtils.encrypt("pwd"), data.get("victiminput.password.enc0"));
}
 
Example 3
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
private PdfDocumentDescriptor populate() throws Exception {
    File file = folder.newFile("temp.pdf");
    File file2 = folder.newFile("®¯°±²³要选择需要转换的文.pdf");
    File file3 = folder.newFile("temp3.pdf");
    File file4 = folder.newFile("temp4.pdf");
    PdfLoadRequestEvent loadEvent = new PdfLoadRequestEvent(MODULE);
    PdfDocumentDescriptor ret = PdfDocumentDescriptor.newDescriptorNoPassword(file);
    loadEvent.add(ret);
    loadEvent.add(PdfDocumentDescriptor.newDescriptorNoPassword(file2));
    loadEvent.add(PdfDocumentDescriptor.newDescriptorNoPassword(file3));
    loadEvent.add(PdfDocumentDescriptor.newDescriptorNoPassword(file4));
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        eventStudio().broadcast(loadEvent, MODULE);
    });
    return ret;
}
 
Example 4
Source File: SelectionTableWithoutMoveTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private PdfDocumentDescriptor populate() throws Exception {
    File file = folder.newFile("temp.pdf");
    PdfLoadRequestEvent loadEvent = new PdfLoadRequestEvent(MODULE);
    PdfDocumentDescriptor ret = PdfDocumentDescriptor.newDescriptorNoPassword(file);
    loadEvent.add(ret);
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> eventStudio().broadcast(loadEvent, MODULE));
    return ret;
}
 
Example 5
Source File: OpenButtonTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void directoryDestination() {
    DirectoryTaskOutput output = mock(DirectoryTaskOutput.class);
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.dispatch(output));
    verify(output).getDestination();
    Text icon = lookup(".glyph-icon").queryAs(Text.class);
    assertEquals(MaterialDesignIcon.FOLDER_OUTLINE.unicode(), icon.getText());
}
 
Example 6
Source File: KeywordsTabTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void showRequest() {
    KeywordsTab victim = new KeywordsTab();
    Labeled keywords = (Labeled) ((ScrollPane) victim.getContent()).getContent().lookup(".info-property-value");
    assertNotNull(keywords);
    ChangeListener<? super String> listener = mock(ChangeListener.class);
    keywords.textProperty().addListener(listener);
    PdfDocumentDescriptor descriptor = PdfDocumentDescriptor.newDescriptorNoPassword(mock(File.class));
    descriptor.putInformation(PdfMetadataFields.KEYWORDS, "test");
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.requestShow(new ShowPdfDescriptorRequest(descriptor)));
    verify(listener, timeout(2000).times(1)).changed(any(ObservableValue.class), anyString(), eq("test"));
}
 
Example 7
Source File: AboutDashboardPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void clickCopy() {
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        Clipboard.getSystemClipboard().clear();
        assertTrue(isBlank(Clipboard.getSystemClipboard().getString()));
    });

    clickOn("#copyEnvDetails");
    WaitForAsyncUtils.waitForAsyncFx(2000,
            () -> assertTrue(Clipboard.getSystemClipboard().getString().contains("PDFsam")));
}
 
Example 8
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void removeRelease() {
    Optional<SelectionTableRowData> item = victim.getItems().stream()
            .filter(i -> "temp.pdf".equals(i.descriptor().getFileName())).findFirst();
    assertTrue(item.isPresent());
    clickOn("temp.pdf");
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        eventStudio().broadcast(new RemoveSelectedEvent(), MODULE);
    });
    assertFalse(item.get().descriptor().hasReferences());
}
 
Example 9
Source File: RotateOptionsPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void restoreStateFrom() {
    ComboBox<KeyStringValueItem<PredefinedSetOfPages>> rotationType = lookup("#rotationType").queryComboBox();
    ComboBox<KeyStringValueItem<Rotation>> rotation = lookup("#rotation").queryComboBox();
    Map<String, String> data = new HashMap<>();
    data.put("rotation", Rotation.DEGREES_270.toString());
    data.put("rotationType", PredefinedSetOfPages.EVEN_PAGES.toString());
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.restoreStateFrom(data));
    assertEquals(Rotation.DEGREES_270, rotation.getSelectionModel().getSelectedItem().getKey());
    assertEquals(PredefinedSetOfPages.EVEN_PAGES, rotationType.getSelectionModel().getSelectedItem().getKey());
}
 
Example 10
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void restoreStateFromPwdBackwardCompatible() {
    eventStudio().clear();
    Listener<PdfLoadRequestEvent> listener = mock(Listener.class);
    eventStudio().add(PdfLoadRequestEvent.class, listener);
    Map<String, String> data = new HashMap<>();
    data.put("victiminput.size", "1");
    data.put("victiminput.0", "chuck.pdf");
    data.put("victiminput.password.0", "pwd");
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.restoreStateFrom(data));
    assertEquals(1, victim.getItems().size());
    SelectionTableRowData first = victim.getItems().get(0);
    assertEquals("pwd", first.descriptor().getPassword());
}
 
Example 11
Source File: LogPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
@Category(NoHeadless.class)
public void copy() {
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        Clipboard.getSystemClipboard().clear();
        assertTrue(isBlank(Clipboard.getSystemClipboard().getString()));
    });
    clickOn("A message").rightClickOn("A message").clickOn("#copyLogMenuItem");
    WaitForAsyncUtils.waitForAsyncFx(2000,
            () -> assertTrue(Clipboard.getSystemClipboard().getString().contains("A message")));
}
 
Example 12
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void clear() {
    clickOn("temp.pdf");
    assertEquals(1, victim.getSelectionModel().getSelectedIndices().size());
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        eventStudio().broadcast(new ClearModuleEvent(), MODULE);
    });
    assertTrue(victim.getSelectionModel().getSelectedIndices().isEmpty());
}
 
Example 13
Source File: SingleSelectionPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
private void moveToEncrytedState(SingleSelectionPane victim) throws Exception {
    typePathAndValidate();
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        victim.getPdfDocumentDescriptor().moveStatusTo(PdfDescriptorLoadingStatus.REQUESTED);
        victim.getPdfDocumentDescriptor().moveStatusTo(PdfDescriptorLoadingStatus.LOADING);
        victim.getPdfDocumentDescriptor().moveStatusTo(PdfDescriptorLoadingStatus.ENCRYPTED);
    });
}
 
Example 14
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
@Category(NoHeadless.class)
public void clearInvalidatesDuplicatedItems() {
    Optional<SelectionTableRowData> item = victim.getItems().stream()
            .filter(i -> "temp.pdf".equals(i.descriptor().getFileName())).findFirst();
    rightClickOn("temp.pdf");
    clickOn(DefaultI18nContext.getInstance().i18n("Duplicate"));
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        eventStudio().broadcast(new ClearModuleEvent(), MODULE);
    });
    assertFalse(item.get().descriptor().hasReferences());
}
 
Example 15
Source File: BookmarksLevelComboBoxTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void restoreStateBackwardCompatible() {
    victim.setValidBookmarkLevels(new TreeSet<>(Arrays.asList(40, 50)));
    Map<String, String> data = new HashMap<>();
    data.put("levelCombo.max", "3");
    data.put("levelCombo.selected", "2");
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.restoreStateFrom(data));
    assertEquals("2", victim.getValue());
    assertThat(victim.getItems(), hasItems("1", "2", "3"));
}
 
Example 16
Source File: BookmarksLevelComboBoxTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void reset() {
    victim.setValidBookmarkLevels(validLevels);
    clickOn(victim).type(KeyCode.DIGIT3).push(KeyCode.ENTER);
    assertEquals("3", victim.getValue());
    assertThat(victim.getItems(), hasItems("2", "3", "4", "5", "6", "7", "10"));
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.resetView());
    assertEquals(null, victim.getValue());
    assertTrue(victim.getItems().isEmpty());
}
 
Example 17
Source File: SelectionTableTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void clickWithErrorsShowsLogStage() {
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> {
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.REQUESTED);
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.LOADING);
        firstItem.moveStatusTo(PdfDescriptorLoadingStatus.WITH_ERRORS);
    });
    WaitForAsyncUtils.waitForFxEvents();
    Listener<ShowStageRequest> listener = mock(Listener.class);
    eventStudio().add(ShowStageRequest.class, listener, "LogStage");
    clickOn(".glyph-icon");
    verify(listener).onEvent(any());
}
 
Example 18
Source File: BookmarksLevelComboBoxTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void saveStateEmptySelection() {
    victim.setValidBookmarkLevels(validLevels);
    Map<String, String> data = new HashMap<>();
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.saveStateTo(data));
    assertEquals("", data.get("levelCombo.selected"));
}
 
Example 19
Source File: BrowsableDirectoryFieldUITest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void setGraphic() {
    Label graphic = new Label("Chuck");
    BrowsableDirectoryField victim = lookup(".victim-no-blank").queryAs(BrowsableDirectoryField.class);
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.setGraphic(graphic));
    assertTrue(lookup("Chuck").tryQuery().isPresent());
}
 
Example 20
Source File: MergeOptionsPaneTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void reset() {
    ComboBox<KeyStringValueItem<OutlinePolicy>> outline = lookup("#outlineCombo").queryComboBox();
    ComboBox<KeyStringValueItem<AcroFormPolicy>> forms = lookup("#acroFormsCombo").queryComboBox();
    ComboBox<KeyStringValueItem<ToCPolicy>> toc = lookup("#tocCombo").queryComboBox();
    CheckBox blankIfOdd = lookup("#blankIfOddCheck").queryAs(CheckBox.class);
    CheckBox footer = lookup("#footerCheck").queryAs(CheckBox.class);
    CheckBox normalize = lookup("#normalizeCheck").queryAs(CheckBox.class);
    Map<String, String> data = new HashMap<>();
    data.put("outline", OutlinePolicy.ONE_ENTRY_EACH_DOC.toString());
    data.put("acroForms", AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS.toString());
    data.put("blankIfOdd", Boolean.TRUE.toString());
    data.put("footer", Boolean.TRUE.toString());
    data.put("normalize", Boolean.TRUE.toString());
    data.put("toc", ToCPolicy.DOC_TITLES.toString());
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.restoreStateFrom(data));
    assertEquals(OutlinePolicy.ONE_ENTRY_EACH_DOC, outline.getSelectionModel().getSelectedItem().getKey());
    assertEquals(AcroFormPolicy.MERGE_RENAMING_EXISTING_FIELDS,
            forms.getSelectionModel().getSelectedItem().getKey());
    assertEquals(ToCPolicy.DOC_TITLES, toc.getSelectionModel().getSelectedItem().getKey());
    assertTrue(blankIfOdd.isSelected());
    assertTrue(footer.isSelected());
    assertTrue(normalize.isSelected());
    WaitForAsyncUtils.waitForAsyncFx(2000, () -> victim.resetView());
    assertEquals(OutlinePolicy.RETAIN, outline.getSelectionModel().getSelectedItem().getKey());
    assertEquals(AcroFormPolicy.MERGE, forms.getSelectionModel().getSelectedItem().getKey());
    assertEquals(ToCPolicy.NONE, toc.getSelectionModel().getSelectedItem().getKey());
    assertFalse(blankIfOdd.isSelected());
    assertFalse(footer.isSelected());
    assertFalse(normalize.isSelected());
}