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
WELD-2712 Write more detailed tests for self-interception and allow p… #2722
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
.../test/java/org/jboss/weld/tests/resolution/circular/self/modifiers/SelfInjectingImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2022, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.weld.tests.resolution.circular.self.modifiers; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class SelfInjectingImpl implements SomeInterface { | ||
|
||
@Inject | ||
SelfInjectingImpl self; | ||
|
||
@Override | ||
public Integer selfInvokePublicMethodPublicParamsPublicReturnType(Integer foo) { | ||
return self._selfInvokePublicMethodPublicParamsPublicReturnType(foo); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokePublicMethodProtectedParamsPublicReturnType(Integer foo) { | ||
return self._selfInvokePublicMethodProtectedParamsPublicReturnType(new ProtectedType(foo)); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokePublicMethodPublicParamsProtectedReturnType(Integer foo) { | ||
return self._selfInvokePublicMethodPublicParamsProtectedReturnType(foo).getVal(); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokePublicMethodProtectedParamsProtectedReturnType(Integer foo) { | ||
return self._selfInvokePublicMethodProtectedParamsProtectedReturnType(new ProtectedType(foo)).getVal(); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokeProtectedMethodProtectedParamsProtectedReturnType(Integer foo) { | ||
return self._selfInvokeProtectedMethodProtectedParamsProtectedReturnType(new ProtectedType(foo)).getVal(); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokeProtectedMethodPublicParamsProtectedReturnType(Integer foo) { | ||
return self._selfInvokeProtectedMethodPublicParamsProtectedReturnType(foo).getVal(); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokeProtectedMethodProtectedParamsPublicReturnType(Integer foo) { | ||
return self._selfInvokeProtectedMethodProtectedParamsPublicReturnType(new ProtectedType(foo)); | ||
} | ||
|
||
@Override | ||
public Integer selfInvokeProtectedMethodPublicParamsPublicReturnType(Integer foo) { | ||
return self._selfInvokeProtectedMethodPublicParamsPublicReturnType(foo); | ||
} | ||
|
||
@SelfIntercept | ||
public Integer _selfInvokePublicMethodPublicParamsPublicReturnType(Integer foo) { | ||
return foo; | ||
} | ||
|
||
@SelfIntercept | ||
public Integer _selfInvokePublicMethodProtectedParamsPublicReturnType(ProtectedType foo) { | ||
return foo.getVal(); | ||
} | ||
|
||
@SelfIntercept | ||
public ProtectedType _selfInvokePublicMethodPublicParamsProtectedReturnType(Integer foo) { | ||
return new ProtectedType(foo); | ||
} | ||
|
||
@SelfIntercept | ||
public ProtectedType _selfInvokePublicMethodProtectedParamsProtectedReturnType(ProtectedType foo) { | ||
return foo; | ||
} | ||
|
||
@SelfIntercept | ||
protected ProtectedType _selfInvokeProtectedMethodProtectedParamsProtectedReturnType(ProtectedType foo) { | ||
return foo; | ||
} | ||
|
||
@SelfIntercept | ||
protected ProtectedType _selfInvokeProtectedMethodPublicParamsProtectedReturnType(Integer foo) { | ||
return new ProtectedType(foo); | ||
} | ||
|
||
@SelfIntercept | ||
protected Integer _selfInvokeProtectedMethodProtectedParamsPublicReturnType(ProtectedType foo) { | ||
return foo.getVal(); | ||
} | ||
|
||
@SelfIntercept | ||
protected Integer _selfInvokeProtectedMethodPublicParamsPublicReturnType(Integer foo) { | ||
return foo; | ||
} | ||
|
||
|
||
/** | ||
* Used as either a protected return type or a protected param type | ||
*/ | ||
protected class ProtectedType { | ||
|
||
Integer val; | ||
|
||
ProtectedType(Integer value) { | ||
this.val = value; | ||
} | ||
|
||
public Integer getVal() { | ||
return val; | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
.../src/test/java/org/jboss/weld/tests/resolution/circular/self/modifiers/SelfIntercept.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.weld.tests.resolution.circular.self.modifiers; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
@InterceptorBinding | ||
@Target( {METHOD, TYPE} ) | ||
@Retention( RUNTIME ) | ||
public @interface SelfIntercept { | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
.../org/jboss/weld/tests/resolution/circular/self/modifiers/SelfInterceptionComplexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2022, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.weld.tests.resolution.circular.self.modifiers; | ||
|
||
import jakarta.inject.Inject; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.BeanArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Tests self-interception when invoking method via client proxy. | ||
* Tests are for public/protected method and public/protected return type and parameter all of which should work. | ||
* No other modifiers are working for self-interception at the time of writing. | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class SelfInterceptionComplexTest { | ||
|
||
@Inject | ||
SomeInterface selfInjectingImpl; | ||
|
||
@Deployment | ||
public static JavaArchive createDeployment() { | ||
return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(SelfInterceptionComplexTest.class)) | ||
.addPackage(SelfInterceptionComplexTest.class.getPackage()); | ||
} | ||
|
||
@Test | ||
public void selfInvokePublicMethodPublicParamsPublicReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokePublicMethodPublicParamsPublicReturnType(10); | ||
Assert.assertEquals("_selfInvokePublicMethodPublicParamsPublicReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokePublicMethodProtectedParamsPublicReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokePublicMethodProtectedParamsPublicReturnType(10); | ||
Assert.assertEquals("_selfInvokePublicMethodProtectedParamsPublicReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokePublicMethodPublicParamsProtectedReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokePublicMethodPublicParamsProtectedReturnType(10); | ||
Assert.assertEquals("_selfInvokePublicMethodPublicParamsProtectedReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokePublicMethodProtectedParamsProtectedReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokePublicMethodProtectedParamsProtectedReturnType(10); | ||
Assert.assertEquals("_selfInvokePublicMethodProtectedParamsProtectedReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokeProtectedMethodProtectedParamsProtectedReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokeProtectedMethodProtectedParamsProtectedReturnType(10); | ||
Assert.assertEquals("_selfInvokeProtectedMethodProtectedParamsProtectedReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokeProtectedMethodPublicParamsProtectedReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokeProtectedMethodPublicParamsProtectedReturnType(10); | ||
Assert.assertEquals("_selfInvokeProtectedMethodPublicParamsProtectedReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokeProtectedMethodProtectedParamsPublicReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokeProtectedMethodProtectedParamsPublicReturnType(10); | ||
Assert.assertEquals("_selfInvokeProtectedMethodProtectedParamsPublicReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
|
||
@Test | ||
public void selfInvokeProtectedMethodPublicParamsPublicReturnTypeTest() { | ||
SelfInterceptor.nullifyCache(); | ||
Assert.assertTrue(SelfInterceptor.INTERCEPTED_METHOD_NAME == null); | ||
selfInjectingImpl.selfInvokeProtectedMethodPublicParamsPublicReturnType(10); | ||
Assert.assertEquals("_selfInvokeProtectedMethodPublicParamsPublicReturnType", SelfInterceptor.INTERCEPTED_METHOD_NAME); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rc/test/java/org/jboss/weld/tests/resolution/circular/self/modifiers/SelfInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2022, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.weld.tests.resolution.circular.self.modifiers; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@SelfIntercept | ||
@Priority(1) | ||
public class SelfInterceptor { | ||
|
||
public static String INTERCEPTED_METHOD_NAME = null; | ||
|
||
public static void nullifyCache() { | ||
INTERCEPTED_METHOD_NAME = null; | ||
} | ||
|
||
@AroundInvoke | ||
public Object intercept(InvocationContext ctx) throws Exception { | ||
INTERCEPTED_METHOD_NAME = ctx.getMethod().getName(); | ||
return ctx.proceed(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../src/test/java/org/jboss/weld/tests/resolution/circular/self/modifiers/SomeInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2022, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.weld.tests.resolution.circular.self.modifiers; | ||
|
||
public interface SomeInterface { | ||
|
||
// public method, all variations | ||
Integer selfInvokePublicMethodPublicParamsPublicReturnType(Integer foo); | ||
Integer selfInvokePublicMethodProtectedParamsPublicReturnType(Integer foo); | ||
Integer selfInvokePublicMethodPublicParamsProtectedReturnType(Integer foo); | ||
Integer selfInvokePublicMethodProtectedParamsProtectedReturnType(Integer foo); | ||
|
||
// protected method, all variations | ||
Integer selfInvokeProtectedMethodProtectedParamsProtectedReturnType(Integer foo); | ||
Integer selfInvokeProtectedMethodPublicParamsProtectedReturnType(Integer foo); | ||
Integer selfInvokeProtectedMethodProtectedParamsPublicReturnType(Integer foo); | ||
Integer selfInvokeProtectedMethodPublicParamsPublicReturnType(Integer foo); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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's not a constant so why the uppercase letters? Just nitpicking ;-)
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.
TBF, I don't remember :-D