Describe the bug
This is a follow-up to #3551, which I believe was closed without adequate consideration.
Expected behavior
If I have a Quarkus app with passing RestAssured
tests and @SubstrateTest
variants, I can add
quarkus.servlet.context-path=/something
and tests will still pass.
Actual behavior
All tests fail.
To Reproduce
I do not currently have a public demo app reproducing the issue, though I think it would be easy to make one based on the above description.
Configuration
See above.
Screenshots
N/A
Environment (please complete the following information):
uname -a
or ver
: Linux … 5.0.0-25-generic #26-Ubuntu SMP Thu Aug 1 12:04:58 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
java -version
:openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~19.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
quay.io/quarkus/centos-quarkus-maven:19.2.0
Additional context
https://github.com/quarkusio/quarkus/issues/3551#issuecomment-522217871 suggests a workaround of simply not running tests with any context path, though I find this unacceptable since there are parts of the application that I _know_ behave differently when a context path is specified and I need these to be tested.
It is possible to fix the JVM-mode tests by injecting
@ConfigProperty(name = "quarkus.servlet.context-path") String contextPath;
and prepending contextPath +
to any requested URIs (for example RequestSenderOptions.get(String, Object...)
), but this does not work in native mode as the field will be null. The workaround I have found is to prepend getContextPath() +
to requested URIs given
@ConfigProperty(name = "quarkus.servlet.context-path") String contextPath;
/** must match {@code application.properties#quarkus.servlet.context-path} */
private static final String CONTEXT_PATH = "/something";
protected final String getContextPath() {
if (contextPath != null) {
assertEquals(CONTEXT_PATH, contextPath);
} // else native mode
return CONTEXT_PATH;
}
which allows tests to pass in native mode, by copying the context path, yet ensures that tests will fail if the copy gets out of synch with the real value.
While I have not yet tried it, it may also work to inject a @TestHTTPResource URL
and parse out the URL.path
.
The purported resolution was a documentation update #3684 which is worded rather vaguely and includes no code samples, so it is hard to evaluate whether it describes adequate workarounds. The ideal resolution from my perspective would be that RestAssured
is somehow preconfigured by Quarkus to automatically prepend the context path to all requests, so that no other code changes need to be made when newly configuring a context path.
Hi @jglick. I'll take a look and see if we can do something better.
RestAssured
(and the TestHTTPResource
injections) should now be automatically configured when a custom servlet context path is used.
Most helpful comment
Hi @jglick. I'll take a look and see if we can do something better.