Search in sources :

Example 1 with ExtensionMethod

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);
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.jupiter.api.Test)

Example 2 with ExtensionMethod

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();
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod)

Example 3 with ExtensionMethod

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");
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.Test)

Example 4 with ExtensionMethod

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();
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.Test)

Example 5 with ExtensionMethod

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");
}
Also used : ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Test(org.junit.Test)

Aggregations

ExtensionMethod (org.jdbi.v3.core.extension.ExtensionMethod)14 Test (org.junit.Test)9 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)2 Timed (com.codahale.metrics.annotation.Timed)1 Method (java.lang.reflect.Method)1 Callable (java.util.concurrent.Callable)1 HandleSupplier (org.jdbi.v3.core.extension.HandleSupplier)1 Before (org.junit.Before)1 Test (org.junit.jupiter.api.Test)1