Skip to content
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

Provide in-memory implementations of HttpServletResponse/Request #1976

Closed
dzikoysk opened this issue Aug 14, 2023 · 0 comments
Closed

Provide in-memory implementations of HttpServletResponse/Request #1976

dzikoysk opened this issue Aug 14, 2023 · 0 comments

Comments

@dzikoysk
Copy link
Member

dzikoysk commented Aug 14, 2023

A fully working implementation of req/res could be an option to all Javalin users that cannot simply start/stop whole instances and that use mocks these days.

The implementation should be relatively simple, most of our API goes through Context interface that implements most of the API with default functions.

We could provide something like:

// given: a request
val context = TestContextSpec()
  .body("abc")
  .header(HttpHeaders.AUTHORIZATION, "Basic xyz")

// when: endpoint is called
endpoint.handle(context.build())

// then: it's ok
assertThat(context.status()).isEqualTo(HttpStatus.OK)
tipsy added a commit that referenced this issue Dec 6, 2023
* [testing] `ContextMock` concept v1

* [testing] `ContextMock` concept v2 - Copy mock on cfg change

* [testing] `ContextMock` concept v3 - Handle request using a real JavalinServlet implementation

* [testing] Fix Javalin init order

* [testing] Create `Endpoint` API

* [testing] Replace multiple config methods with one `withMockConfig`

* [testing] Hide mocking from Endpoint

* [testing] Replace `Consumer<MockConfig>` with SAM-with-receiver interface

* [testing] Refactor mocked Body impl & tests

* [testing] Cleanup + docs

* [testing] Support sessions

* [testing] Compare state of mocked ctx (& res/res) with real ctx

* [testing] Fix test

* [testing] Cleanup names

* [testing] Delete javalin-context-mock related classes

* [testing] `javalin-util`/`javalin-context-mock` module with `ContextMock`

* [testing] Fix javalin-util pom.xml

* [testing] Add `javalin-context-mock` to `javalin-bundle`

* [testing] Duplicate `pom.properties` for `javalin-utils` and its submodules

* [testing] Support multipart files

* [testing] Bootstrap other session methods

* [testing] Test headers in the response

* Cleanup

* Cleanup

* Update javalin-utils/javalin-context-mock/src/main/java/io/javalin/mock/ContextMock.kt

Co-authored-by: David (javalin.io) <davidaase@hotmail.com>

* [testing] CR v1

* [testing] CR v2: replace pom.properties content with dummy comment

* [testing] CR v3: rename invokeMockConfigurerWithAsSamWithReceiver to invokeConfigWithConfigurerScope

---------

Co-authored-by: David (javalin.io) <davidaase@hotmail.com>
@tipsy tipsy closed this as completed Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants