-
Notifications
You must be signed in to change notification settings - Fork 209
test: remove real Vaadin components from vaadin-spring-tests #24958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Artur-
wants to merge
1
commit into
main
Choose a base branch
from
no-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../test-spring-helpers/src/main/java/com/vaadin/flow/spring/test/LoanApplicationUpload.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Copyright 2000-2026 Vaadin Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package com.vaadin.flow.spring.test; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import com.vaadin.flow.component.HasComponents; | ||
| import com.vaadin.flow.component.html.H4; | ||
| import com.vaadin.flow.component.html.Image; | ||
| import com.vaadin.flow.component.html.Input; | ||
| import com.vaadin.flow.component.html.NativeButton; | ||
| import com.vaadin.flow.component.html.Paragraph; | ||
| import com.vaadin.flow.server.StreamRegistration; | ||
| import com.vaadin.flow.server.StreamResource; | ||
| import com.vaadin.flow.server.StreamResourceRegistry; | ||
| import com.vaadin.flow.server.VaadinSession; | ||
| import com.vaadin.flow.server.streams.UploadHandler; | ||
|
|
||
| /** | ||
| * The "upload your loan application" UI shared by the Spring Security test | ||
| * apps. It uses a native {@code <input type="file">} that posts the selected | ||
| * file as a raw XHR body with an {@code X-Filename} header to a session-scoped | ||
| * {@link UploadHandler} (the servlets are not {@code @MultipartConfig}), and on | ||
| * success shows a confirmation paragraph (id {@code uploadText}) and the | ||
| * uploaded image (id {@code uploadImage}). It pulls no Vaadin component npm | ||
| * packages. | ||
| */ | ||
| public final class LoanApplicationUpload { | ||
|
|
||
| private LoanApplicationUpload() { | ||
| } | ||
|
|
||
| /** | ||
| * Adds the loan application upload UI to the given view. | ||
| * | ||
| * @param view | ||
| * the view to add the upload components to | ||
| * @param uploaderName | ||
| * supplies the name shown in the confirmation text, evaluated | ||
| * when an upload succeeds | ||
| */ | ||
| public static void addTo(HasComponents view, | ||
| Supplier<String> uploaderName) { | ||
| ByteArrayOutputStream imageStream = new ByteArrayOutputStream(); | ||
| UploadHandler uploadHandler = event -> { | ||
| try (InputStream inputStream = event.getInputStream()) { | ||
| inputStream.transferTo(imageStream); | ||
| } catch (IOException ex) { | ||
| throw new UncheckedIOException(ex); | ||
| } | ||
| event.getUI().access(() -> { | ||
| Paragraph p = new Paragraph( | ||
| "Loan application uploaded by " + uploaderName.get()); | ||
| p.setId("uploadText"); | ||
| view.add(p); | ||
| Image image = new Image(new StreamResource("image.png", | ||
| () -> new ByteArrayInputStream( | ||
| imageStream.toByteArray())), | ||
| "image"); | ||
| image.setId("uploadImage"); | ||
| view.add(image); | ||
| }); | ||
| }; | ||
|
|
||
| StreamResourceRegistry resourceRegistry = VaadinSession.getCurrent() | ||
| .getResourceRegistry(); | ||
| StreamRegistration streamRegistration = resourceRegistry | ||
| .registerResource(uploadHandler); | ||
| String uploadUrl = resourceRegistry | ||
| .getTargetURI(streamRegistration.getResource()).toString(); | ||
|
|
||
| // The upload posts via fetch(), which does not piggyback Flow's UIDL | ||
| // sync. Click a hidden button after the response to force a server | ||
| // roundtrip that pulls down the queued DOM updates. | ||
| NativeButton uploadSync = new NativeButton("", event -> { | ||
| }); | ||
| uploadSync.getStyle().set("display", "none"); | ||
|
|
||
| Input uploadInput = new Input(); | ||
| uploadInput.setType("file"); | ||
| uploadInput.setId("uploadInput"); | ||
| uploadInput.getElement().executeJs( | ||
| """ | ||
| this.addEventListener('change', () => { | ||
| const file = this.files[0]; | ||
| if (!file) return; | ||
| fetch($0, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': file.type || 'application/octet-stream', | ||
| 'X-Filename': encodeURIComponent(file.name) | ||
| }, | ||
| body: file | ||
| }).then(() => $1.click()); | ||
| }); | ||
| """, | ||
| uploadUrl, uploadSync.getElement()); | ||
|
|
||
| view.add(new H4("Upload your loan application"), uploadInput, | ||
| uploadSync); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the dependencies were added to increase the startup class scanning effort. Removing all of them might somehow make the benchmark tests less effective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but the benchmark would need to be outside the flow project if it tests the full platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Actually, it already runs only as a nightly CI build, not during PR validation.