-
Notifications
You must be signed in to change notification settings - Fork 45
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
Test BeanContainer assignability API methods #526
Conversation
assertFalse(getCurrentBeanContainer().isMatchingBean(reducedBeanTypes, Set.of(), Object.class, Set.of()), | ||
"Bean matched Object despite it not being in bean types"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure about this test.
Every bean has Object
as a bean type. Should Object
be implied if not passed in the beanTypes
set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every bean has
Object
as a bean type. ShouldObject
be implied if not passed in thebeanTypes
set?
Yes, that's always added.
I think there was even a TCK for @Typed
that asserted that Object
is added automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Lurking. Curious if this is generally true in the specification (to be clear, I know about https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#bean_types)? I see that certainly for @Typed
Object.class
is implied, but if I make a synthetic bean and explicitly do not include Object.class
in its Set<Type>
...? For example, https://jakarta.ee/specifications/cdi/4.0/apidocs/jakarta.cdi/jakarta/enterprise/inject/spi/configurator/beanattributesconfigurator#types(java.util.Set) says nothing about Object.class
being intrinsically added.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, https://jakarta.ee/specifications/cdi/4.0/apidocs/jakarta.cdi/jakarta/enterprise/inject/spi/configurator/beanattributesconfigurator#types(java.util.Set) says nothing about Object.class being intrinsically added.)
Yes, I am aware of that. However, event a synth bean is a bean and as therefore the first link you posted should still apply. At least in my opinion :)
And I think that's also what Weld does; not sure if there is a TCK for it though 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to clarify whether Object
is automatically added with a note on the relevant methods.
For this method, it sounds like we think Object
should be automatically added to the set of bean types so this test should change to assertTrue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a proposal: jakartaee/cdi#744 I went full on the precise mode, as that's just easiest frankly :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their own implementation of
Bean
which may not returnObject
fromgetTypes
.
That would be an invalid implementation of Bean
in my eyes, though the container can compensate for it. All the more reason for using the BeanConfigurator
API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a proposal
That looks good, thank you :-)
I've updated the test to match.
That would be an invalid implementation of
Bean
in my eyes
Yeah, I agree and it's not the only way you could have an invalid Bean
implementation either (e.g. returning a non-scope annotation from getScope()
). I guess we could be more specific about how and when these sorts of errors are handled.
I note that BeanConfigurator
is still vulnerable to some of the same issues. You could fail to pass Object
to types
as @ljnelson suggested, or pass a non-scope annotation to scope
and we don't currently document what should happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. Out of scope of this PR for sure, though :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all synthetic beans are beans, and if all beans have the bean type java.lang.Object, then all synthetic beans have the bean type java.lang.Object. That is a straightforward implication in my eyes.
I am of the same opinion.
The only possible downside is that someone might start asking "why don't we automatically scan for all superclasses and implemented interfaces?", and I wouldn't have a good answer :-)
Because you might want to simulate a scenario where @Typed
was used and some types might be omitted.
Yeah, I agree and it's not the only way you could have an invalid Bean implementation either (e.g. returning a non-scope annotation from getScope()). I guess we could be more specific about how and when these sorts of errors are handled.
Well, since you can define arbitrary things if you implement Bean
yourself, it would be rather extensive to nail it all down...
Also worth noting:
|
9d6ee82
to
8521084
Compare
Should be fairly easy to do in Weld, I'll make a branch next week so that we can test it. |
.../java/org/jboss/cdi/tck/tests/beanContainer/assignability/BeanObserverAssignabilityTest.java
Outdated
Show resolved
Hide resolved
Other assertions LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more notes besides the one code comment below:
- I promised you a Weld branch/pr, which is here -> WELD-2774 Implement BM methods for event/bean assignability weld/core#2906. It passes all tests in the PR's current state apart from the one which I believe is wrong.
- I am also pondering whether we should assert something about validity of input such as annotations not being CDI qualifiers or bean types being invalid. On one hand it would be nice, OTOH every invocation of this method will have to perform a solid amount of verification just because we assume users may not know what they are doing 🤷
...ain/java/org/jboss/cdi/tck/tests/beanContainer/assignability/BeanEventAssignabilityTest.java
Show resolved
Hide resolved
We talked about this internally, my personal opinion is a bit different in that it is typical for |
Yea, added my approval there but @Azquelt might want to take a look as well. We'll also want some TCK coverage for that - the qualifier validation should be an easy one. @Azquelt do you wish to look into these or should me or Ladislav take that? |
@manovotn I'm happy to look at it, I'll add it to this PR unless you'd rather merge this part first. I understood "legal bean types" to refer to just 2.1.2.1, which I think is only concerned with the type itself and not whether it's been discovered, trimmed or vetoed? I'm not entirely sure about what an unresolved type variable is (I have also commented on jakartaee/cdi#748), so I'll struggle to test that unless someone can provide an example of something that wouldn't be a valid event object under that rule. |
The audit file for existing tests says that this provision (or rather, the existing provision on which this one is modeled) is untestable. Maybe there's a way to test it, but I'd be fine with leaving that one uncovered. |
Yes that's exactly why I linked the tck file. I would also be fine leaving this untested. |
Feel free to add it here. I would rather merge once we release cdi api anyway.
Right, it's just a case where a user can pass in a set of types where some would normally be filtered as illegal for given bean |
I've added tests for the changes in jakartaee/cdi#748. The only one that didn't pass against @manovotn's branch was this one for having a type variable in the event type. I'd tried to test this in a similar way to FireEventTest.testTypeVariableEventTypeFails. |
Thanks, I'll check on it. |
...ain/java/org/jboss/cdi/tck/tests/beanContainer/assignability/BeanEventAssignabilityTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The Weld branch I linked earlier is also passing fine.
My implementation in ArC also passes. We should probably merge jakartaee/cdi#748 first and then update the audit files here, but I wouldn't really mind otherwise. Except we'll need a new CDI API release (Alpha2?) first, anyway. |
79f0969
to
8e948cc
Compare
I've rebased and updated the audit files based on jakartaee/cdi#748 now that it's merged. |
@Azquelt |
Tests for .isMatchingBean and .isMatchingEvent.
8e948cc
to
466f0f2
Compare
Rebased, squashed and copyright headers updated. |
Tests for .isMatchingBean and .isMatchingEvent.
Fixes #518