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 #7

Merged
merged 3 commits into from
Nov 25, 2023

Conversation

mbland
Copy link
Owner

@mbland mbland commented Nov 25, 2023

This is a redo of #3 and #6. #4 didn't help, and I'm holding off on merging #5.

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.

@mbland mbland force-pushed the test-matchers-and-other-tweaks branch from d0cd79e to b987997 Compare November 25, 2023 23:18
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 mbland force-pushed the test-matchers-and-other-tweaks branch from b987997 to 2719139 Compare November 25, 2023 23:22
@mbland
Copy link
Owner Author

mbland commented Nov 25, 2023

My Run Tests config is still hosed, because it's running twice on one PR. But merging anyway for now.

@mbland mbland closed this Nov 25, 2023
@mbland
Copy link
Owner Author

mbland commented Nov 25, 2023

Whoops...

@mbland mbland reopened this Nov 25, 2023
@mbland mbland merged commit 5ddd486 into main Nov 25, 2023
4 of 6 checks passed
@mbland mbland deleted the test-matchers-and-other-tweaks branch November 25, 2023 23:25
mbland added a commit that referenced this pull request Nov 25, 2023
PR #7 triggered the Run Tests action again, but did so multiple times.

I want all pushes to `main` to trigger builds, as well as updates to
pull requests, but not pushes to other branches. And I want each action
to run only once per PR.

This is an attempt to get the right thing to happen based on advice
from:

- https://stackoverflow.com/a/65096459
- https://github.com/orgs/community/discussions/26276#discussioncomment-3251140
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