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

Hoist up Node Gradle plugin, set TestTomcat baseDir, add hasContentType matcher, HTTP status consts #6

Closed
wants to merge 3 commits into from

Conversation

mbland
Copy link
Owner

@mbland mbland commented Nov 25, 2023

This is a redo of #3, which I couldn't get to trigger any GitHub Actions, even after merging #4.

Combining several small touch up changes in one:

Hoist Node Gradle plugin up to settings.gradle.kts

settings.gradle.kts seems a better place to specify the versions of Gradle plugins than in the project specific build.gradle.kts files.

Set TestTomcat baseDir explicitly

This is in preparation for possibly launching a TestTomcat per test method, instead of per test fixture/suite.

I found out that trying to dynamically create a baseDir for each instance led to the first instance's baseDir reappearing. I haven't been able to see clearly how this is happening, but it seems that:

  1. The baseDir isn't strictly necessary in our case, since we're not running JSPs.
  2. Using the same build/test-tomcat baseDir for all instances and having each instance delete it when finished isn't breaking anything.

Add hasContentType matcher, HTTP status consts

This matcher removes a lot of boilerplate from checking the Content-Type of a HttpResponse. It's based on the Hamcrest API with the help of these tutorials:

This could be generalized to handle any header. However, I want to keep it straightforward for now, as a good basic example of how to write a custom matcher.

Also took the opportunity to replace bare HTTP status codes (200, et. al.) with constants defined on jakarta.servlet.http.HttpServletResponse.

settings.gradle.kts seems a better place to specify the versions of
Gradle plugins than in the project specific build.gradle.kts files.
This is in preparation for possibly launching a TestTomcat per test
method, instead of per test fixture/suite.

I found out that trying to dynamically create a baseDir for each
instance led to the first instance's baseDir reappearing. I haven't been
able to see clearly how this is happening, but it seems that:

1. The baseDir isn't strictly necessary in our case, since we're not
   running JSPs.
2. Using the same build/test-tomcat baseDir for all instances and having
   each instance delete it when finished isn't breaking anything.
This matcher removes a lot of boilerplate from checking the Content-Type
of a HttpResponse. It's based on the Hamcrest API with the help of these
tutorials:

- https://hamcrest.org/JavaHamcrest/tutorial
- https://www.baeldung.com/hamcrest-custom-matchers

This could be generalized to handle any header.  However, I want to keep
it straightforward for now, as a good basic example of how to write a
custom matcher.

Also took the opportunity to replace bare HTTP status codes (200, et.
al.) with constants defined on jakarta.servlet.http.HttpServletResponse.
@mbland
Copy link
Owner Author

mbland commented Nov 25, 2023

Nope, still not working. Let me see if a new branch will help. If all else fails, we'll see if #5 helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant