Skip to content

Commit f62e1de

Browse files
committed
Add unit tests for glassfish 4.1 instrumentation
1 parent 470a20d commit f62e1de

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

dd-java-agent/instrumentation/glassfish-4.1/src/main/java/datadog/trace/instrumentation/glassfish4/GlassfishInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ElementMatcher<? super TypeDescription> typeMatcher() {
4646
@Override
4747
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
4848
return singletonMap(
49-
isMethod().and(named("addToBlackList")).and(takesArguments(0)),
49+
isMethod().and(named("addToBlackList")).and(takesArguments(1)),
5050
AvoidGlassFishBlacklistAdvice.class.getName());
5151
}
5252

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package datadog.trace.instrumentation.glassfish4
2+
3+
import datadog.trace.agent.test.AgentTestRunner
4+
import datadog.trace.agent.tooling.Constants
5+
import net.bytebuddy.matcher.NameMatcher
6+
7+
class GlassfishInstrumentationTest extends AgentTestRunner {
8+
9+
def "test type matches the correct class loader"() {
10+
setup:
11+
def matchingType = new GlassfishInstrumentation().typeMatcher()
12+
13+
expect:
14+
matchingType instanceof NameMatcher
15+
matchingType.toString() == 'name(equals(com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader))'
16+
}
17+
18+
def "test correct classes are added to the helpers"() {
19+
setup:
20+
def helpers = new GlassfishInstrumentation().helperClassNames()
21+
22+
expect:
23+
Constants.class.getName() in helpers
24+
}
25+
26+
def "test the advice is registered for the 'addToBlackList' method"() {
27+
setup:
28+
def transformers = new GlassfishInstrumentation().transformers()
29+
def transformer = transformers.entrySet()[0]
30+
31+
expect:
32+
transformer.key.toString() == '((isMethod() and name(equals(addToBlackList))) and hasParameter(ofSize(1)))'
33+
}
34+
}

0 commit comments

Comments
 (0)