Add test for OrmClientDecorator
This commit is contained in:
parent
093387bb01
commit
3334affc42
|
@ -5,9 +5,9 @@ import io.opentracing.Span;
|
|||
|
||||
public abstract class OrmClientDecorator extends DatabaseClientDecorator {
|
||||
|
||||
public abstract <ENTITY> String entityName(final ENTITY entity);
|
||||
public abstract String entityName(final Object entity);
|
||||
|
||||
public <ENTITY> Span onOperation(final Span span, final ENTITY entity) {
|
||||
public Span onOperation(final Span span, final Object entity) {
|
||||
|
||||
assert span != null;
|
||||
if (entity != null) {
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package datadog.trace.agent.decorator
|
||||
|
||||
import datadog.trace.api.DDTags
|
||||
import io.opentracing.Span
|
||||
|
||||
class OrmClientDecoratorTest extends DatabaseClientDecoratorTest {
|
||||
|
||||
def span = Mock(Span)
|
||||
|
||||
def "test onOperation #testName"() {
|
||||
setup:
|
||||
decorator = newDecorator({ e -> entityName })
|
||||
|
||||
when:
|
||||
decorator.onOperation(span, entity)
|
||||
|
||||
then:
|
||||
if (isSet) {
|
||||
1 * span.setTag(DDTags.RESOURCE_NAME, entityName)
|
||||
}
|
||||
0 * _
|
||||
|
||||
where:
|
||||
testName | entity | entityName || isSet
|
||||
"null entity" | null | "name" || false
|
||||
"null entityName" | "not null" | null || false
|
||||
"name set" | "not null" | "name" || true
|
||||
}
|
||||
|
||||
|
||||
def newDecorator(name) {
|
||||
return new OrmClientDecorator() {
|
||||
@Override
|
||||
String entityName(Object entity) {
|
||||
return name.call(entity)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String dbType() {
|
||||
return "test-db"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String dbUser(Object o) {
|
||||
return "test-user"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String dbInstance(Object o) {
|
||||
return "test-user"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String service() {
|
||||
return "test-service"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] instrumentationNames() {
|
||||
return ["test1"]
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String spanType() {
|
||||
return "test-type"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String component() {
|
||||
return "test-component"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue