-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fixed issue 733 Getting wrong path when trying to use logic forwardTo #734
Conversation
@adolfoweloy, thank you to help us with your pull request. Your solution is very nice, but only coverage cases that proxy generated class uses There is a class called So instead of extract the name using a regex, you can only change the line 68 of From: What you think about? Thank you. |
A better place to do this fix is right here: instead of |
I think it's really a better solution. @Override
@SuppressWarnings("unchecked")
public <T> T redirectTo(T controller) {
return (T) redirectTo(CDIProxies.extractRawTypeIfPossible(controller.getClass()));
}
@Override
@SuppressWarnings("unchecked")
public <T> T forwardTo(T controller) {
return (T) forwardTo(CDIProxies.extractRawTypeIfPossible(controller.getClass()));
}
@Override
@SuppressWarnings("unchecked")
public <T> T of(T controller) {
return (T) of(CDIProxies.extractRawTypeIfPossible(controller.getClass()));
} I've just ran maven tests and and my app and that's ok |
Yes, your code looks nice. Can you commit this changes? So when you commit and push this changes, will appers here in this pull request. |
Sorry @garcia-jj |
There are way to add a text case for this code? |
It would be cool to add a test case. you can try to use the proxifier to generate a proxy for a Controller and pass it to the method. |
The class under test would be DefaultResult using a mocked Controller proxified by proxifier? |
You would add tests like these: which don't use mocked controllers |
I've added some tests like @lucascs suggested. |
|
||
result.redirectTo(randomProxy); | ||
|
||
verify(logicResult).redirectTo(CDIProxies.extractRawTypeIfPossible(randomProxy.getClass())); |
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.
actually you should verify this:
verify(logicResult).redirectTo(RandomController.class);
That's what you want.
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.
Hello @lucascs.
I'm trying to figure out how to effectively test it but having no success :(
When verifying as you suggested, tests are failing. So I realize that I can't invoke redirectTo or forwardTo using a proxified controller through proxifier.proxify(RandomController.class).
When debugging an application executing at Wildfly8, I saw that our controller is an instance of something similar to ExampleController$Proxy$__$$_Weld****. And such an instance is created by invoking beanManager.getContext inside InstantiateObserver.
Do you think it's better to keep talking about it at caelum-vraptor-dev google group? Because I'm having doubts about the source code ;)
Thanks
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.
That's because CDIProxies.unproxifyIfPossible
is prepared to unproxify CDI proxies. In your test, you are using javassist to generate the proxy. Is it possible to build this proxy with Weld api? Or you can create a mock of TargetInstanceProxy
.
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.
Another possible solution would be to inject CDIProxies as a dependency and mock it in your test. But than extractRawTypeIfPossible
should become an instance method. What do you think?
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.
My point was just to change this line from:
verify(logicResult).redirectTo(CDIProxies.extractRawTypeIfPossible(randomProxy.getClass()));
to
verify(logicResult).redirectTo(RandomController.class);
does the test break if you do this?
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 breaks because randomProxy
is not a CDI proxy, so the extractRawTypeIfPossible
will return the proxyed class (something like RandomController$..javassist..etcetc
), and not the unproxied RandomController.class
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.
I've fixed it on this PR #740. After merging it I'll release a new VR version. ok?
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.
Thanks Turini. I saw the fix and that sounds nice for me.
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.
You're welcome :) I didn't suggest the fix here because we need this PR merged to release RC2, so I've provided a fast fix instead. Thanks a lot for your contribution.
I guys. This pull request causes a
After some minutes I see that we forgot to add a cast to I'll send a pull request after some tests in my app. |
Fixing #734 that causes a StackOverflow when we use Result.redirectTo
The getFilteredControllerBaseName method was created to filter baseName that may be using proxified controller base name. Without this filter, extractControllerFromName wouldn't be able to extract Controller suffix.