-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use correct view when using eagerServerLoad (#14036)
* fix: Use correct view when using eagerServerLoad Returns 404 for non-existant views Helps with #13421
- Loading branch information
1 parent
46755ee
commit a504891
Showing
8 changed files
with
289 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.vaadin</groupId> | ||
<artifactId>flow-tests</artifactId> | ||
<version>23.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>flow-test-eager-bootstrap</artifactId> | ||
<name>Flow eager bootstrap (includes UIDL in first request) test</name> | ||
<packaging>war</packaging> | ||
<properties> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
<vaadin.eagerServerLoad>true</vaadin.eagerServerLoad> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.vaadin</groupId> | ||
<artifactId>flow-test-resources</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.vaadin</groupId> | ||
<artifactId>vaadin-dev-server</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.vaadin</groupId> | ||
<artifactId>flow-maven-plugin</artifactId> | ||
<configuration> | ||
<productionMode>false</productionMode> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
<version>${jetty.version}</version> | ||
<executions> | ||
<!-- start and stop jetty (running our app) when running | ||
integration tests --> | ||
<execution> | ||
<id>start-jetty</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>stop-jetty</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
27 changes: 27 additions & 0 deletions
27
flow-tests/test-eager-bootstrap/src/main/java/com/vaadin/flow/eagerbootstrap/HelloView.java
This file contains 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,27 @@ | ||
/* | ||
* Copyright 2000-2022 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.eagerbootstrap; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("hello") | ||
public class HelloView extends Div { | ||
public HelloView() { | ||
setId("view"); | ||
setText("This is the Hello view"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
flow-tests/test-eager-bootstrap/src/main/java/com/vaadin/flow/eagerbootstrap/RootView.java
This file contains 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,27 @@ | ||
/* | ||
* Copyright 2000-2022 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.eagerbootstrap; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("") | ||
public class RootView extends Div { | ||
public RootView() { | ||
setId("view"); | ||
setText("This is the root view"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
flow-tests/test-eager-bootstrap/src/test/java/com/vaadin/flow/servlet/BasicViewsIT.java
This file contains 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,48 @@ | ||
/* | ||
* Copyright 2000-2022 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.servlet; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class BasicViewsIT extends ChromeBrowserTest { | ||
|
||
@Test | ||
public void rootViewShown() throws Exception { | ||
getDriver().get(getRootURL() + "/"); | ||
Assert.assertEquals("This is the root view", | ||
$("*").id("view").getText()); | ||
} | ||
|
||
@Test | ||
public void helloViewShown() throws Exception { | ||
getDriver().get(getRootURL() + "/hello"); | ||
Assert.assertEquals("This is the Hello view", | ||
$("*").id("view").getText()); | ||
} | ||
|
||
@Test | ||
public void invalidViewShowsNotFound() throws Exception { | ||
getDriver().get(getRootURL() + "/nonexistant"); | ||
|
||
Assert.assertTrue(getDriver().getPageSource() | ||
.contains("Could not navigate to 'nonexistant'")); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
flow-tests/test-eager-bootstrap/src/test/java/com/vaadin/flow/servlet/LowLevelFetchIT.java
This file contains 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,91 @@ | ||
/* | ||
* Copyright 2000-2022 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.servlet; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.testutil.ChromeBrowserTest; | ||
|
||
public class LowLevelFetchIT extends ChromeBrowserTest { | ||
|
||
public static class OtherResponseCodeException extends IOException { | ||
|
||
private int responseCode; | ||
|
||
public OtherResponseCodeException(int responseCode) { | ||
this.responseCode = responseCode; | ||
} | ||
|
||
public int getResponseCode() { | ||
return responseCode; | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void rootViewContainsRootUIDL() throws Exception { | ||
open(); // This is only to wait for the dev server... | ||
String source = getUrl(getRootURL() + "/"); | ||
Assert.assertTrue(source.contains( | ||
"\"key\":\"text\",\"feat\":7,\"value\":\"This is the root view\"")); | ||
} | ||
|
||
private String getUrl(String urlString) throws IOException { | ||
URL url = new URL(urlString); | ||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
conn.connect(); | ||
|
||
if (conn.getResponseCode() != 200) { | ||
throw new OtherResponseCodeException(conn.getResponseCode()); | ||
} | ||
|
||
return IOUtils.toString(conn.getInputStream(), StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void helloViewContainsHelloViewUidl() throws Exception { | ||
open(); // This is only to wait for the dev server... | ||
String source = getUrl(getRootURL() + "/hello"); | ||
Assert.assertTrue(source.contains( | ||
"\"key\":\"text\",\"feat\":7,\"value\":\"This is the Hello view\"")); | ||
} | ||
|
||
@Test | ||
public void notFoundViewReturns404() throws Exception { | ||
open(); // This is only to wait for the dev server... | ||
try { | ||
getUrl(getRootURL() + "/notfound"); | ||
} catch (OtherResponseCodeException e) { | ||
Assert.assertEquals(404, e.getResponseCode()); | ||
return; | ||
} | ||
Assert.fail("Should have thrown OtherResponseCodeException"); | ||
} | ||
|
||
@Override | ||
protected String getTestPath() { | ||
return ""; | ||
} | ||
|
||
} |