use of org.jdbi.v3.core.extension.ExtensionMethod in project dropwizard by dropwizard.
the class NamePrependingTemplateEngineTest method testPrependsCorrectName.
@Test
void testPrependsCorrectName() throws NoSuchMethodException {
final ExtensionMethod extensionMethod = new ExtensionMethod(MyDao.class, MyDao.class.getMethod("myDbCall"));
when(ctx.getExtensionMethod()).thenReturn(extensionMethod);
final String result = sut.render(TEMPLATE, ctx);
assertThat(result).isEqualTo("/* " + extensionMethod.getType().getSimpleName() + "." + extensionMethod.getMethod().getName() + " */ " + ORIGINAL_RENDERED);
}
use of org.jdbi.v3.core.extension.ExtensionMethod in project dropwizard by dropwizard.
the class NamePrependingTemplateEngine method render.
@Override
public String render(String template, StatementContext ctx) {
final ExtensionMethod extensionMethod = ctx.getExtensionMethod();
final String originalResult = originalEngine.render(template, ctx);
if (extensionMethod == null) {
return originalResult;
}
final StringBuilder query = new StringBuilder(originalResult.length() + 100);
query.append("/* ");
final String className = extensionMethod.getType().getSimpleName();
if (!className.isEmpty()) {
query.append(className).append('.');
}
query.append(extensionMethod.getMethod().getName());
query.append(" */ ");
query.append(originalResult);
return query.toString();
}
use of org.jdbi.v3.core.extension.ExtensionMethod in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testAnnotationOnClass.
@Test
public void testAnnotationOnClass() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Bar.class, Bar.class.getMethod("update")));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("com.codahale.metrics.jdbi3.strategies.TimedAnnotationNameStrategyTest$Bar.update");
}
use of org.jdbi.v3.core.extension.ExtensionMethod in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testNoAnnotations.
@Test
public void testNoAnnotations() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(Dummy.class, Dummy.class.getMethod("show")));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isNull();
}
use of org.jdbi.v3.core.extension.ExtensionMethod in project metrics by dropwizard.
the class TimedAnnotationNameStrategyTest method testAnnotationOnMethodAndClassWithCustomNames.
@Test
public void testAnnotationOnMethodAndClassWithCustomNames() throws Exception {
when(ctx.getExtensionMethod()).thenReturn(new ExtensionMethod(CustomBar.class, CustomBar.class.getMethod("find", String.class)));
assertThat(timedAnnotationNameStrategy.getStatementName(ctx)).isEqualTo("custom-bar.find-by-id");
}
Aggregations