-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up unit test that tracks orphan-oss/ognl#125 - this test failing …
…is a sign that this bug may have been fixed. The bug causes OGNL to incorrectly identify a case of 2 varargs method that also has a no-args option as problematic in a particular condition (see the github issue for more detail). §Currently the only side-effect of this bug is to print an error message to application stderr in this case, e.g. ``` Two vararg methods with same score(0): "public javax.ws.rs.client.Invocation$Builder org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.request(javax.ws.rs.core.MediaType[])" and "public javax.ws.rs.client.Invocation$Builder org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.request(java.lang.String[])" please report! ```
- Loading branch information
1 parent
3d829a9
commit e589291
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
guice/common/src/test/java/com/peterphi/std/guice/common/ognl/OgnlIssue125Test.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,104 @@ | ||
package com.peterphi.std.guice.common.ognl; | ||
|
||
import ognl.AbstractMemberAccess; | ||
import ognl.Node; | ||
import ognl.Ognl; | ||
import ognl.OgnlContext; | ||
import org.junit.ComparisonFailure; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.lang.reflect.Member; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Unit test set up to track <a href="https://github.com/jkuhnert/ognl/issues/125">https://github.com/jkuhnert/ognl/issues/125</a>.<br | ||
* /> This unit test will pass <strong>until this bug is fixed</strong> | ||
*/ | ||
public class OgnlIssue125Test | ||
{ | ||
public interface TestInterface | ||
{ | ||
String request(); | ||
|
||
String request(String... args); | ||
|
||
String request(int... args); | ||
} | ||
|
||
public static class TestInterfaceImpl implements TestInterface | ||
{ | ||
@Override | ||
public String request() | ||
{ | ||
return "noargs"; | ||
} | ||
|
||
|
||
@Override | ||
public String request(final String... args) | ||
{ | ||
return "varargs string"; | ||
} | ||
|
||
|
||
@Override | ||
public String request(final int... args) | ||
{ | ||
return "varargs int"; | ||
} | ||
} | ||
|
||
public static class OgnlRoot | ||
{ | ||
public TestInterfaceImpl get() | ||
{ | ||
return new TestInterfaceImpl(); | ||
} | ||
} | ||
|
||
private static class OGNLPublicMemberAccess extends AbstractMemberAccess | ||
{ | ||
@Override | ||
public boolean isAccessible(final Map context, final Object target, final Member member, final String propertyName) | ||
{ | ||
return Modifier.isPublic(member.getModifiers()); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @throws Exception on setup failure | ||
* @throws ComparisonFailure if the bug is still present; if this test starts faiing it is a sign that the bug may be fixed - | ||
* remove the expected=ComparisonFailure! | ||
*/ | ||
@Test(expected = ComparisonFailure.class) | ||
public void testOgnl() throws Exception | ||
{ | ||
final PrintStream stderr = System.err; | ||
try | ||
{ | ||
final OgnlRoot obj = new OgnlRoot(); | ||
final Node ognl = (Node) Ognl.parseExpression("get().request()"); | ||
|
||
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
System.setErr(new PrintStream(buffer)); | ||
{ | ||
assertEquals("noargs", ognl.getValue(new OgnlContext(null, null, new OGNLPublicMemberAccess()), obj)); | ||
} | ||
System.err.flush(); | ||
|
||
// This fails currently due to OGNL issue #125 | ||
assertEquals("Expecting no stderr output from OGNL call", "", buffer.toString("UTF-8")); | ||
} | ||
finally | ||
{ | ||
// Restore stderr | ||
System.setErr(stderr); | ||
} | ||
} | ||
} |