Add unit tests for glassfish 4.1 instrumentation
MODIFY
dd-java-agent/instrumentation/glassfish-4.1/src/main/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentation.java
dd-java-agent/instrumentation/glassfish-4.1/src/main/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentation.java
@@ -46,7 +46,7 @@ public final class GlassfishInstrumentation extends Instrumenter.Default {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
- isMethod().and(named("addToBlackList")).and(takesArguments(0)),
+ isMethod().and(named("addToBlackList")).and(takesArguments(1)),
AvoidGlassFishBlacklistAdvice.class.getName());
}

ADD
dd-java-agent/instrumentation/glassfish-4.1/src/test/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentationTest.groovy
+package datadog.trace.instrumentation.glassfish4
+
+import datadog.trace.agent.test.AgentTestRunner
+import datadog.trace.agent.tooling.Constants
+import net.bytebuddy.matcher.NameMatcher
+
+class GlassfishInstrumentationTest extends AgentTestRunner {
+
+ def "test type matches the correct class loader"() {
+ setup:
+ def matchingType = new GlassfishInstrumentation().typeMatcher()
+
+ expect:
+ matchingType instanceof NameMatcher
+ matchingType.toString() == 'name(equals(com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader))'
+ }
+
+ def "test correct classes are added to the helpers"() {
+ setup:
+ def helpers = new GlassfishInstrumentation().helperClassNames()
+
+ expect:
+ Constants.class.getName() in helpers
+ }
+
+ def "test the advice is registered for the 'addToBlackList' method"() {
+ setup:
+ def transformers = new GlassfishInstrumentation().transformers()
+ def transformer = transformers.entrySet()[0]
+
+ expect:
+ transformer.key.toString() == '((isMethod() and name(equals(addToBlackList))) and hasParameter(ofSize(1)))'
+ }
+}

Add unit tests for glassfish 4.1 instrumentation