From d85be43de79f1a2be2983701e85409c5d289e6e4 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 12:52:21 +0200 Subject: [PATCH 01/12] Bump version. --- version.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.gradle.kts b/version.gradle.kts index 35fc512a2..ad63c02c6 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -29,5 +29,5 @@ val spineTimeVersion: String by extra("1.7.1") val spineCoreVersion: String by extra("1.7.1") val spineVersion: String by extra(spineCoreVersion) -val versionToPublish: String by extra("1.7.2") +val versionToPublish: String by extra("1.7.3") val versionToPublishJs: String by extra(versionToPublish) From d0683e6bef0452741dbc17822da56fd93705c286 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 12:53:36 +0200 Subject: [PATCH 02/12] Do publish `testutil-web`. --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 62f09efab..c129f3193 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -68,7 +68,7 @@ plugins { } extra["credentialsPropertyFile"] = PublishingRepos.cloudRepo.credentials -extra["projectsToPublish"] = listOf("web", "firebase-web") +extra["projectsToPublish"] = listOf("web", "firebase-web", "testutil-web") allprojects { apply { From 1f7bd4ae56ff0877870a6f19da6b8c2905079baa Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:28:35 +0200 Subject: [PATCH 03/12] Allow building the request using `Builder`. --- .../java/io/spine/web/given/KnownRequest.java | 100 +++++++++++++++++- 1 file changed, 95 insertions(+), 5 deletions(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index ed0a60fe0..21961ae13 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -36,6 +36,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.Enumeration; +import java.util.Map; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterators.asEnumeration; @@ -58,11 +59,13 @@ public final class KnownRequest implements MockedRequest { private final ImmutableMap headers; private final byte[] content; private final MediaType type; + private final String uri; - private KnownRequest(ImmutableMap headers, byte[] content, MediaType type) { - this.headers = headers; - this.content = content; - this.type = type; + private KnownRequest(Builder builder) { + this.headers = builder.headers; + this.content = builder.content; + this.type = builder.type; + this.uri = builder.uri; } /** @@ -106,7 +109,11 @@ public static KnownRequest create(byte[] content, checkNotNull(content); checkNotNull(type); checkNotNull(headers); - return new KnownRequest(headers, content, type); + return newBuilder() + .withBinaryContent(content) + .withType(type) + .withHeaders(headers) + .build(); } private static ImmutableMap contentTypeHeader(MediaType type) { @@ -156,4 +163,87 @@ public BufferedReader getReader() { ) ); } + + /** + * Creates an empty request. + */ + public static KnownRequest empty() { + return newBuilder().build(); + } + + /** + * Creates a new request builder. + */ + public static Builder newBuilder() { + return new Builder(); + } + + /** + * The request builder. + */ + public static class Builder { + + private ImmutableMap headers = ImmutableMap.of(); + private MediaType type = MediaType.ANY_TYPE; + private byte[] content = "".getBytes(StandardCharsets.UTF_8); + private String uri = ""; + + /** + * Prevents instantiation outside of the class. + * + * @see #newBuilder() + */ + private Builder() { + } + + /** + * Sets the request content. + */ + public Builder withContent(String content) { + checkNotNull(content); + this.content = content.getBytes(StandardCharsets.UTF_8); + return this; + } + + /** + * Sets the request content bytes. + */ + public Builder withBinaryContent(byte[] content) { + checkNotNull(content); + this.content = content.clone(); + return this; + } + + /** + * Sets the request headers. + */ + public Builder withHeaders(Map headers) { + checkNotNull(headers); + this.headers = ImmutableMap.copyOf(headers); + return this; + } + + /** + * Sets the request media type. + */ + public Builder withType(MediaType type) { + this.type = checkNotNull(type); + return this; + } + + /** + * Sets the request URI. + */ + public Builder withUri(String uri) { + this.uri = checkNotNull(uri); + return this; + } + + /** + * Creates a request out of this builder. + */ + public KnownRequest build() { + return new KnownRequest(this); + } + } } From bfb6b3d4a9db0786fb83290000a0ebbc1e399f0e Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:28:55 +0200 Subject: [PATCH 04/12] Do return the `uri`. --- .../src/main/java/io/spine/web/given/KnownRequest.java | 8 +++++++- .../test/java/io/spine/web/given/KnownRequestTest.java | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index 21961ae13..4aa4bca8a 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.MediaType; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.io.BufferedReader; @@ -151,7 +152,7 @@ public long getContentLengthLong() { } @Override - public @Nullable String getContentType() { + public @NonNull String getContentType() { return type.toString(); } @@ -164,6 +165,11 @@ public BufferedReader getReader() { ); } + @Override + public @NonNull String getRequestURI() { + return uri; + } + /** * Creates an empty request. */ diff --git a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java index 495edc561..6001f64ec 100644 --- a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java +++ b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java @@ -73,5 +73,7 @@ void returnSetValues() throws IOException { assertThat(request.getReader() .readLine()) .isEqualTo(text); + assertThat(request.getRequestURI()) + .isEmpty(); } } From 8a71f34aaf08e1c859c0c5e3f0b06790fcebac94 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:37:35 +0200 Subject: [PATCH 05/12] Drop extra `create` static method. --- .../java/io/spine/web/given/KnownRequest.java | 30 ++----------------- .../io/spine/web/given/KnownRequestTest.java | 7 ++++- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index 4aa4bca8a..0d45821d6 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -84,36 +84,10 @@ public static KnownRequest create(String content) { public static KnownRequest create(String content, MediaType type) { checkNotNull(content); checkNotNull(type); - return create(content, type, contentTypeHeader(type)); - } - - /** - * Creates a new mocked request with specified {@code content}, {@code type} - * and {@code headers}. - */ - public static KnownRequest create(String content, - MediaType type, - ImmutableMap headers) { - checkNotNull(content); - checkNotNull(type); - checkNotNull(headers); - return create(content.getBytes(StandardCharsets.UTF_8), type, headers); - } - - /** - * Creates a new mocked request with specified {@code content}, {@code type} - * and {@code headers}. - */ - public static KnownRequest create(byte[] content, - MediaType type, - ImmutableMap headers) { - checkNotNull(content); - checkNotNull(type); - checkNotNull(headers); return newBuilder() - .withBinaryContent(content) + .withContent(content) .withType(type) - .withHeaders(headers) + .withHeaders(contentTypeHeader(type)) .build(); } diff --git a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java index 6001f64ec..ea15833e2 100644 --- a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java +++ b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java @@ -55,7 +55,12 @@ void returnSetValues() throws IOException { String headerName = "custom"; String headerValue = "header"; ImmutableMap headers = ImmutableMap.of(headerName, headerValue); - KnownRequest request = KnownRequest.create(text, type, headers); + KnownRequest request = KnownRequest + .newBuilder() + .withContent(text) + .withType(type) + .withHeaders(headers) + .build(); assertThat(request.getContentLength()) .isEqualTo(text.length()); assertThat(request.getContentLengthLong()) From 2beb1703bb76c5dedd26370408baddd03184ded5 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:39:45 +0200 Subject: [PATCH 06/12] Reorganize API. --- .../java/io/spine/web/given/KnownRequest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index 0d45821d6..79211a5c1 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -69,6 +69,20 @@ private KnownRequest(Builder builder) { this.uri = builder.uri; } + /** + * Creates an empty request. + */ + public static KnownRequest empty() { + return newBuilder().build(); + } + + /** + * Creates a new request builder. + */ + public static Builder newBuilder() { + return new Builder(); + } + /** * Creates a new mocked request with specified {@code content} and default * {@linkplain MediaType#ANY_TYPE any} type. @@ -144,20 +158,6 @@ public BufferedReader getReader() { return uri; } - /** - * Creates an empty request. - */ - public static KnownRequest empty() { - return newBuilder().build(); - } - - /** - * Creates a new request builder. - */ - public static Builder newBuilder() { - return new Builder(); - } - /** * The request builder. */ From 741d961c0cc92310b345cc2150c9e05c5ed143e9 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:40:01 +0200 Subject: [PATCH 07/12] Ensure `null` are prohibited in the builder. --- .../src/test/java/io/spine/web/given/KnownRequestTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java index ea15833e2..5e41437e2 100644 --- a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java +++ b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java @@ -37,13 +37,14 @@ import static com.google.common.truth.Truth.assertThat; @DisplayName("`KnownRequest` should") -class KnownRequestTest { +final class KnownRequestTest { @Test @DisplayName("not tolerate `null`s") void notTolerateNull() { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicStaticMethods(KnownRequest.class); + tester.testAllPublicInstanceMethods(KnownRequest.newBuilder()); } @Test From 74c0fbcd7d8ec8e8caa0d0070426cc38f63c182c Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:40:11 +0200 Subject: [PATCH 08/12] Bump versions. --- client-js/package.json | 2 +- integration-tests/js-tests/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client-js/package.json b/client-js/package.json index 2ce549972..b39505a41 100644 --- a/client-js/package.json +++ b/client-js/package.json @@ -1,6 +1,6 @@ { "name": "spine-web", - "version": "1.7.2", + "version": "1.7.3", "license": "Apache-2.0", "description": "A JS client for interacting with Spine applications.", "homepage": "https://spine.io", diff --git a/integration-tests/js-tests/package.json b/integration-tests/js-tests/package.json index eeb004584..a7405dbbc 100644 --- a/integration-tests/js-tests/package.json +++ b/integration-tests/js-tests/package.json @@ -1,6 +1,6 @@ { "name": "client-js-tests", - "version": "1.7.2", + "version": "1.7.3", "license": "Apache-2.0", "description": "Tests of a `spine-web` JS library against the Spine-based application.", "scripts": { From 1fd9a30f4f18ae103fb4b355fcd8b765e1e25417 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:40:21 +0200 Subject: [PATCH 09/12] Update reports. --- license-report.md | 32 ++++++++++++++++---------------- pom.xml | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/license-report.md b/license-report.md index c43adbab2..ef4643bb1 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine:spine-client-js:1.7.2` +# Dependencies of `io.spine:spine-client-js:1.7.3` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -367,10 +367,10 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:22:46 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Mar 04 13:36:38 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -#NPM dependencies of `spine-web@1.7.2` +#NPM dependencies of `spine-web@1.7.3` ## `Production` dependencies: @@ -389,7 +389,7 @@ This report was generated on **Mon Feb 01 17:22:46 EET 2021** using [Gradle-Lice 1. **rxjs@6.5.5** * Licenses: Apache-2.0 * Repository: [https://github.com/reactivex/rxjs](https://github.com/reactivex/rxjs) -1. **spine-web@1.7.2** +1. **spine-web@1.7.3** * Licenses: Apache-2.0 * Repository: [https://github.com/SpineEventEngine/web](https://github.com/SpineEventEngine/web) 1. **tslib@1.14.1** @@ -2449,7 +2449,7 @@ This report was generated on **Mon Feb 01 17:22:46 EET 2021** using [Gradle-Lice 1. **spdx-satisfies@4.0.1** * Licenses: MIT * Repository: [https://github.com/kemitchell/spdx-satisfies.js](https://github.com/kemitchell/spdx-satisfies.js) -1. **spine-web@1.7.2** +1. **spine-web@1.7.3** * Licenses: Apache-2.0 * Repository: [https://github.com/SpineEventEngine/web](https://github.com/SpineEventEngine/web) 1. **split-string@3.1.0** @@ -2757,12 +2757,12 @@ This report was generated on **Mon Feb 01 17:22:46 EET 2021** using [Gradle-Lice * Repository: [https://github.com/yargs/yargs](https://github.com/yargs/yargs) -This report was generated on **Mon Feb 01 2021 17:22:49 GMT+0200 (Eastern European Standard Time)** using [NPM License Checker](https://github.com/davglass/license-checker) library. +This report was generated on **Thu Mar 04 2021 13:36:42 GMT+0200 (Eastern European Standard Time)** using [NPM License Checker](https://github.com/davglass/license-checker) library. -# Dependencies of `io.spine.gcloud:spine-firebase-web:1.7.2` +# Dependencies of `io.spine.gcloud:spine-firebase-web:1.7.3` ## Runtime 1. **Group:** com.fasterxml.jackson.core **Name:** jackson-annotations **Version:** 2.9.10 @@ -3548,12 +3548,12 @@ This report was generated on **Mon Feb 01 2021 17:22:49 GMT+0200 (Eastern Europe The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:22:57 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Mar 04 13:36:50 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:spine-js-tests:1.7.2` +# Dependencies of `io.spine:spine-js-tests:1.7.3` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -3942,12 +3942,12 @@ This report was generated on **Mon Feb 01 17:22:57 EET 2021** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:23:04 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Mar 04 13:37:42 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:spine-test-app:1.7.2` +# Dependencies of `io.spine:spine-test-app:1.7.3` ## Runtime 1. **Group:** com.fasterxml.jackson.core **Name:** jackson-annotations **Version:** 2.9.10 @@ -5520,12 +5520,12 @@ This report was generated on **Mon Feb 01 17:23:04 EET 2021** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:23:08 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Mar 04 13:37:48 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:spine-testutil-web:1.7.2` +# Dependencies of `io.spine:spine-testutil-web:1.7.3` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -5983,12 +5983,12 @@ This report was generated on **Mon Feb 01 17:23:08 EET 2021** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:23:09 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). +This report was generated on **Thu Mar 04 13:37:52 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). -# Dependencies of `io.spine:spine-web:1.7.2` +# Dependencies of `io.spine:spine-web:1.7.3` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -6485,4 +6485,4 @@ This report was generated on **Mon Feb 01 17:23:09 EET 2021** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Mon Feb 01 17:23:12 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file +This report was generated on **Thu Mar 04 13:37:58 EET 2021** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE). \ No newline at end of file diff --git a/pom.xml b/pom.xml index 320b23aa3..7d3c23d4e 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject. io.spine spine-web -1.7.2 +1.7.3 2015 From 36a06fd4eebce1785230984b66386666b9417685 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:44:28 +0200 Subject: [PATCH 10/12] Improve the Builder top-level javadoc. --- testutil-web/src/main/java/io/spine/web/given/KnownRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index 79211a5c1..751be2b9a 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -159,7 +159,7 @@ public BufferedReader getReader() { } /** - * The request builder. + * A builder for producing {@code KnownRequest} instances. */ public static class Builder { From 01329f87b33cba34fbb26fb80a6eef603a2e779a Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:44:56 +0200 Subject: [PATCH 11/12] Do not enumerate the fields as we may add more. --- testutil-web/src/main/java/io/spine/web/given/KnownRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java index 751be2b9a..50b214f42 100644 --- a/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java +++ b/testutil-web/src/main/java/io/spine/web/given/KnownRequest.java @@ -45,7 +45,7 @@ import static java.util.Collections.emptyIterator; /** - * A mocked servlet request with pre-defined {@code content}, {@code type} and {@code headers}. + * A mocked servlet request with pre-defined content. * * @implNote The request is effectively immutable and does not pay attention to any * modification attempts. Such a mocked implementation may be used for tests where From d931ee735435a0f8b53def71d59d0f4d28d2ad80 Mon Sep 17 00:00:00 2001 From: Yuri Sergiichuk Date: Thu, 4 Mar 2021 13:50:07 +0200 Subject: [PATCH 12/12] Add a test case for `empty` defaults. --- .../io/spine/web/given/KnownRequestTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java index 5e41437e2..7ca214646 100644 --- a/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java +++ b/testutil-web/src/test/java/io/spine/web/given/KnownRequestTest.java @@ -27,6 +27,7 @@ package io.spine.web.given; import com.google.common.collect.ImmutableMap; +import com.google.common.io.CharStreams; import com.google.common.net.MediaType; import com.google.common.testing.NullPointerTester; import org.junit.jupiter.api.DisplayName; @@ -49,9 +50,11 @@ void notTolerateNull() { @Test @DisplayName("return set values") - @SuppressWarnings("JdkObsolete") // we're force to follow the contract + @SuppressWarnings("JdkObsolete") + // we're force to follow the contract void returnSetValues() throws IOException { String text = "some text"; + String uri = "/perform/action"; MediaType type = MediaType.PLAIN_TEXT_UTF_8; String headerName = "custom"; String headerValue = "header"; @@ -61,6 +64,7 @@ void returnSetValues() throws IOException { .withContent(text) .withType(type) .withHeaders(headers) + .withUri(uri) .build(); assertThat(request.getContentLength()) .isEqualTo(text.length()); @@ -79,6 +83,22 @@ void returnSetValues() throws IOException { assertThat(request.getReader() .readLine()) .isEqualTo(text); + assertThat(request.getRequestURI()) + .isEqualTo(uri); + } + + @Test + @DisplayName("create empty request") + void empty() throws IOException { + KnownRequest request = KnownRequest.empty(); + assertThat(request.getContentLength()) + .isEqualTo(0); + assertThat(request.getContentLengthLong()) + .isEqualTo(0); + assertThat(request.getContentType()) + .isEqualTo(MediaType.ANY_TYPE.toString()); + assertThat(CharStreams.toString(request.getReader())) + .isEmpty(); assertThat(request.getRequestURI()) .isEmpty(); }