Class UploadFileListTester<T extends UploadFileList>
- Type Parameters:
T- the component type.
- All Implemented Interfaces:
Clickable<T>
The file list shows the files of the UploadManager it is linked to:
the files the user picked with an UploadButton or dropped on an
UploadDropZone linked to the same manager. The tester reads that list
and simulates the buttons on its entries. As in the browser, the file list is
not usable while it is not linked to a manager or while the manager is
disabled.
Entries are reached by file name or by position. As in the browser, nothing
prevents the user from adding the same file, or another file with the same
name, more than once: every one becomes an entry of its own, is uploaded on
its own and counts towards UploadManager.setMaxFiles(int). When
several entries share a name, removeFile(String) removes the most
recently added one, which is the first one the list shows, and
startUpload(String) starts the most recently added one that still
waits to be started. To act on a specific entry, use removeFile(int)
and startUpload(int) with its position in getFiles().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetFiles()Gets the files the file list shows, in the order the browser shows them: the most recently added file first.Returns what happened to each file the user last picked with anUploadButton, dropped on anUploadDropZoneor started from this list, in the order the files were given.booleanisUsable()Validate that component can be interacted with and should be visible in the UI.protected voidnotUsableReasons(Consumer<String> collector) Provides messages explaining why the component is actually not usable.voidremoveFile(int index) Simulates the user clicking the remove button of the file at the given position of the list, which reaches one entry when several share a name.voidremoveFile(File file) Simulates the user clicking the remove button of a file in the list.voidremoveFile(String fileName) Simulates the user clicking the remove button of a file in the list.voidstartUpload(int index) Simulates the user clicking the start button of the file at the given position of the list, which waits becauseauto uploadis turned off, uploading it.voidstartUpload(File file) Simulates the user clicking the start button of a file that waits in the list becauseauto uploadis turned off, uploading it.voidstartUpload(String fileName) Simulates the user clicking the start button of a file that waits in the list becauseauto uploadis turned off, uploading it.Methods inherited from class com.vaadin.browserless.ComponentTester
blur, canSetValueAsUser, clearAsUser, clickClearButtonAsUser, ensureComponentIsUsable, ensureComponentIsUsable, ensureComponentIsUsableOrDetach, ensureVisible, ensureVisible, find, findAllByQuery, findByQuery, fireDomEvent, fireDomEvent, fireDomEvent, focus, getComponent, getField, getField, getMethod, getMethod, isComponentReadOnly, isFocused, isUsable, notUsableReasons, roundTrip, setModal, setPropertyAsUser, setValueAsUser, setValueAsUserMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.browserless.Clickable
click, click, click, middleClick, middleClick, rightClick, rightClick
-
Constructor Details
-
UploadFileListTester
Wrap given component for testing.- Parameters:
component- target component
-
-
Method Details
-
getFiles
Gets the files the file list shows, in the order the browser shows them: the most recently added file first.A file is
UploadTester.UploadStatus.UPLOADEDonce the upload handler has consumed it,UploadTester.UploadStatus.FAILEDorUploadTester.UploadStatus.REJECTEDwhen its transfer failed or the server refused it, andUploadTester.UploadStatus.PENDINGwhile it waits to be started because auto upload is turned off.- Returns:
- the files in the file list, or an empty list if the file list is not linked to an upload manager
-
getLastUploadStatus
Returns what happened to each file the user last picked with anUploadButton, dropped on anUploadDropZoneor started from this list, in the order the files were given.A file is
UploadTester.UploadStatus.UPLOADEDonce the upload handler has consumed it,UploadTester.UploadStatus.FAILEDwhen the handler threw, andUploadTester.UploadStatus.PENDINGwhile it waits forstartUpload(String)because auto upload is turned off.Unlike
getFiles(), this also reports the files the manager refused, which never enter the list: they areUploadTester.UploadStatus.REJECTEDwith the client-side error code as the error message:tooManyFiles,fileIsTooBigorincorrectFileType. A file Flow's server-side accepted type validation refused isREJECTEDas well.- Returns:
- the outcome of the last upload, one entry per file, or an empty list if nothing has been uploaded yet or the file list is not linked to a manager
-
removeFile
Simulates the user clicking the remove button of a file in the list.A
UploadManager.FileRemovedEventis fired and the file stops counting towardsUploadManager.setMaxFiles(int).When several entries have the given name, the most recently added one is removed.
- Parameters:
fileName- name of the file to remove, as given when it was uploaded- Throws:
IllegalArgumentException- if the file is not in the file listIllegalStateException- if the component is not usable
-
removeFile
Simulates the user clicking the remove button of a file in the list.A
UploadManager.FileRemovedEventis fired and the file stops counting towardsUploadManager.setMaxFiles(int).When several entries have the name of the given file, the most recently added one is removed.
- Parameters:
file- the file to remove- Throws:
IllegalArgumentException- if the file is not in the file listIllegalStateException- if the component is not usable
-
removeFile
public void removeFile(int index) Simulates the user clicking the remove button of the file at the given position of the list, which reaches one entry when several share a name.A
UploadManager.FileRemovedEventis fired and the file stops counting towardsUploadManager.setMaxFiles(int).- Parameters:
index- the position of the file in the list, in the ordergetFiles()returns them: the most recently added file first- Throws:
IllegalArgumentException- if there is no file at the positionIllegalStateException- if the component is not usable
-
startUpload
Simulates the user clicking the start button of a file that waits in the list becauseauto uploadis turned off, uploading it.When several waiting entries have the given name, the most recently added one is started.
- Parameters:
fileName- name of the file to start, as given when it was added- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalArgumentException- if no such file waits in the file listIllegalStateException- if the component is not usable
-
startUpload
Simulates the user clicking the start button of a file that waits in the list becauseauto uploadis turned off, uploading it.When several waiting entries have the name of the given file, the most recently added one is started.
- Parameters:
file- the file to start- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalArgumentException- if no such file waits in the file listIllegalStateException- if the component is not usable
-
startUpload
public void startUpload(int index) Simulates the user clicking the start button of the file at the given position of the list, which waits becauseauto uploadis turned off, uploading it. This reaches one entry when several share a name.- Parameters:
index- the position of the file in the list, in the ordergetFiles()returns them: the most recently added file first- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalArgumentException- if there is no file at the position, or it does not wait to be uploadedIllegalStateException- if the component is not usable
-
isUsable
public boolean isUsable()Description copied from class:ComponentTesterValidate that component can be interacted with and should be visible in the UI. Subclasses overriding this method should also overrideComponentTester.notUsableReasons(Consumer)to provide additional details to the potential exception thrown byComponentTester.ensureComponentIsUsable().- Overrides:
isUsablein classComponentTester<T extends UploadFileList>- Returns:
trueif component can be interacted with by the user- See Also:
-
notUsableReasons
Description copied from class:ComponentTesterProvides messages explaining why the component is actually not usable. Subclasses overridingComponentTester.isUsable()should also override this method to provide additional details to the potential exception throw byComponentTester.ensureComponentIsUsable().- Overrides:
notUsableReasonsin classComponentTester<T extends UploadFileList>- See Also:
-