Class UploadButtonTester<T extends UploadButton>
- Type Parameters:
T- the component type.
- All Implemented Interfaces:
Clickable<T>
Uploading through the button simulates the user picking files in the file
dialog the button opens. The files are handed to the UploadManager
the button is linked to, which checks them against its
maxFiles,
maxFileSize and accepted file
types the same way the browser does: a file failing one of them fires a
UploadManager.FileRejectedEvent and never reaches the upload handler.
A refused file is no more of an error here than in the browser, so uploading
does not throw for it. Use getLastUploadStatus() to see what became
of each file, or ensureUploaded() to fail the test unless every file
went through.
The manager keeps the files in a file list shared by every component linked
to it, and maxFiles is checked against that list. As in the browser,
the button is not usable while it is not linked to a manager, while the
manager is disabled, or once the file list holds maxFiles files.
Remove files with UploadFileListTester.removeFile(String) or
UploadManager.clearFileList() to make room.
When auto upload is turned off,
accepted files wait in the file list until they are started with
UploadFileListTester.startUpload(String).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks that the last upload through theUploadManagerthe button is linked to delivered every one of its files, and fails otherwise.voidChecks that at least one file of the last upload through theUploadManagerthe button is linked to failed or was rejected, and fails otherwise.Returns what happened to each file the user last selected, dropped or started through theUploadManagerthe button is linked to, 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.voidSimulates the user picking the given file in the file dialog.voidSimulates the user picking a file with the given name, content type and contents in the file dialog.voiduploadAborted(File file) Simulates the user picking the given file in the file dialog and then aborting its upload.voiduploadAborted(String fileName, String contentType) Simulates the user picking a file with the given name and content type in the file dialog and then aborting its upload.voidSimulates the user picking several files at once in the file dialog.voiduploadAll(Collection<File> files) Simulates the user picking several files at once in the file dialog.voiduploadFailed(File file) Simulates the user picking the given file in the file dialog and its upload then failing.voiduploadFailed(String fileName, String contentType) Simulates the user picking a file with the given name and content type in the file dialog and its upload then failing.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
-
UploadButtonTester
Wrap given component for testing.- Parameters:
component- target component
-
-
Method Details
-
upload
Simulates the user picking the given file in the file dialog.The content type is detected from the file name.
- Parameters:
file- the file to upload- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalStateException- if the component is not usable
-
upload
Simulates the user picking a file with the given name, content type and contents in the file dialog.- Parameters:
fileName- name of the file to uploadcontentType- content type of the file to uploadcontents- file contents as an array of bytes- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalStateException- if the component is not usable
-
uploadAll
Simulates the user picking several files at once in the file dialog.The content types are detected from the file names.
- Parameters:
files- the files to upload- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalArgumentException- if no file is givenIllegalStateException- if the component is not usable
-
uploadAll
Simulates the user picking several files at once in the file dialog.The content types are detected from the file names.
- Parameters:
files- the files to upload- Throws:
UncheckedIOException- if the upload handler fails to handle the file contentsIllegalArgumentException- if no file is givenIllegalStateException- if the component is not usable
-
uploadAborted
Simulates the user picking the given file in the file dialog and then aborting its upload.As in the browser, the aborted file is dropped from the file list and a
UploadManager.FileRemovedEventis fired, freeing a slot whenUploadManager.setMaxFiles(int)is in use.The file is added and its transfer started in one go, whether or not
auto uploadis turned off. The content type is detected from the file name, and the file is not read.- Parameters:
file- the file to upload- Throws:
IllegalStateException- if the component is not usable
-
uploadAborted
Simulates the user picking a file with the given name and content type in the file dialog and then aborting its upload.As in the browser, the aborted file is dropped from the file list and a
UploadManager.FileRemovedEventis fired, freeing a slot whenUploadManager.setMaxFiles(int)is in use.The file is added and its transfer started in one go, whether or not
auto uploadis turned off.- Parameters:
fileName- name of the file to uploadcontentType- content type of the file to upload- Throws:
IllegalStateException- if the component is not usable
-
uploadFailed
Simulates the user picking the given file in the file dialog and its upload then failing.As in the browser, a file whose upload failed stays in the file list.
The file is added and its transfer started in one go, whether or not
auto uploadis turned off. The content type is detected from the file name, and the file is not read.- Parameters:
file- the file to upload- Throws:
IllegalStateException- if the component is not usable
-
uploadFailed
Simulates the user picking a file with the given name and content type in the file dialog and its upload then failing.As in the browser, a file whose upload failed stays in the file list.
The file is added and its transfer started in one go, whether or not
auto uploadis turned off.- Parameters:
fileName- name of the file to uploadcontentType- content type of the file to upload- Throws:
IllegalStateException- if the component is not usable
-
getLastUploadStatus
Returns what happened to each file the user last selected, dropped or started through theUploadManagerthe button is linked to, in the order the files were given.Files are reported as
UploadTester.UploadStatus.UPLOADEDonce the upload handler has consumed them, asUploadTester.UploadStatus.REJECTEDwhen the manager or Flow's server-side accepted type validation refused them, asUploadTester.UploadStatus.FAILEDwhen the handler threw, and asUploadTester.UploadStatus.PENDINGwhile they wait in the file list for auto upload being turned off. The error message of a file the manager refused is the client-side error code:tooManyFiles,fileIsTooBigorincorrectFileType.- Returns:
- the outcome of the last upload, one entry per file, or an empty list if nothing has been uploaded yet or the button is not linked to a manager
-
ensureUploaded
public void ensureUploaded()Checks that the last upload through theUploadManagerthe button is linked to delivered every one of its files, and fails otherwise.- Throws:
IllegalStateException- if no upload has been simulated, or if any file of the last upload was not uploaded- See Also:
-
ensureUploadFailed
public void ensureUploadFailed()Checks that at least one file of the last upload through theUploadManagerthe button is linked to failed or was rejected, and fails otherwise.Counterpart of
ensureUploaded()for a test about the failure case, such as an upload handler that throws or a file the manager refuses. UsegetLastUploadStatus()to check which file failed and why.A file left
UploadTester.UploadStatus.PENDINGdoes not count as failed: it was neither delivered nor refused, such as a file waiting because auto upload is turned off.- Throws:
IllegalStateException- if no upload has been simulated, or if no file of the last upload failed or was rejected- See Also:
-
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 UploadButton>- 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 UploadButton>- See Also:
-