Add unit tests for glassfish 4.1 instrumentation

This commit is contained in:
Luca Abbati 2019-05-28 15:06:43 +02:00
parent 470a20dbce
commit f62e1dedeb
No known key found for this signature in database
GPG Key ID: C901DDA2FFE14529
2 changed files with 35 additions and 1 deletions

View File

@ -46,7 +46,7 @@ public final class GlassfishInstrumentation extends Instrumenter.Default {
@Override @Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap( return singletonMap(
isMethod().and(named("addToBlackList")).and(takesArguments(0)), isMethod().and(named("addToBlackList")).and(takesArguments(1)),
AvoidGlassFishBlacklistAdvice.class.getName()); AvoidGlassFishBlacklistAdvice.class.getName());
} }

View File

@ -0,0 +1,34 @@
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)))'
}
}