-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.x: Update streaming example so it starts and downloads last uploade…
…d file (#8515) * Update streaming example so it starts correctly and downloads last uploaded file * Add tests
- Loading branch information
Showing
6 changed files
with
128 additions
and
21 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
File renamed without changes.
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
93 changes: 93 additions & 0 deletions
93
...s/webserver/streaming/src/test/java/io/helidon/examples/webserver/streaming/MainTest.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,93 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. | ||
* | ||
* 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 io.helidon.examples.webserver.streaming; | ||
|
||
import io.helidon.http.Status; | ||
import io.helidon.webclient.http1.Http1Client; | ||
import io.helidon.webclient.http1.Http1ClientResponse; | ||
import io.helidon.webserver.http.HttpRouting; | ||
import io.helidon.webserver.testing.junit5.ServerTest; | ||
import io.helidon.webserver.testing.junit5.SetUpRoute; | ||
|
||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
@ServerTest | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class MainTest { | ||
|
||
private final Http1Client client; | ||
|
||
private final String TEST_DATA_1 = "Test Data 1"; | ||
private final String TEST_DATA_2 = "Test Data 2"; | ||
|
||
protected MainTest(Http1Client client) { | ||
this.client = client; | ||
} | ||
|
||
@SetUpRoute | ||
static void routing(HttpRouting.Builder builder) { | ||
Main.routing(builder); | ||
} | ||
|
||
@Test | ||
@Order(0) | ||
void testBadRequest() { | ||
try (Http1ClientResponse response = client.get("/download").request()) { | ||
assertThat(response.status(), is(Status.BAD_REQUEST_400)); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
void testUpload1() { | ||
try (Http1ClientResponse response = client.post("/upload").submit(TEST_DATA_1)) { | ||
assertThat(response.status(), is(Status.OK_200)); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void testDownload1() { | ||
try (Http1ClientResponse response = client.get("/download").request()) { | ||
assertThat(response.status(), is(Status.OK_200)); | ||
assertThat(response.as(String.class), is(TEST_DATA_1)); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
void testUpload2() { | ||
try (Http1ClientResponse response = client.post("/upload").submit(TEST_DATA_2)) { | ||
assertThat(response.status(), is(Status.OK_200)); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
void testDownload2() { | ||
try (Http1ClientResponse response = client.get("/download").request()) { | ||
assertThat(response.status(), is(Status.OK_200)); | ||
assertThat(response.as(String.class), is(TEST_DATA_2)); | ||
} | ||
} | ||
} |