Search in sources :

Example 6 with DirectFieldAccessor

use of cn.taketoday.beans.DirectFieldAccessor in project today-infrastructure by TAKETODAY.

the class ScriptTemplateViewTests method engineSupplierWithNonSharedEngine.

// gh-23258
@Test
public void engineSupplierWithNonSharedEngine() {
    this.configurer.setEngineSupplier(() -> mock(InvocableScriptEngine.class));
    this.configurer.setRenderObject("Template");
    this.configurer.setRenderFunction("render");
    this.configurer.setSharedEngine(false);
    DirectFieldAccessor accessor = new DirectFieldAccessor(view);
    this.view.setApplicationContext(this.wac);
    ScriptEngine engine1 = this.view.getEngine();
    ScriptEngine engine2 = this.view.getEngine();
    assertThat(engine1).isNotNull();
    assertThat(engine2).isNotNull();
    assertThat(accessor.getPropertyValue("renderObject")).isEqualTo("Template");
    assertThat(accessor.getPropertyValue("renderFunction")).isEqualTo("render");
    assertThat(accessor.getPropertyValue("sharedEngine")).asInstanceOf(BOOLEAN).isFalse();
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.jupiter.api.Test)

Example 7 with DirectFieldAccessor

use of cn.taketoday.beans.DirectFieldAccessor in project today-infrastructure by TAKETODAY.

the class GroovyMarkupViewTests method customTemplateEngine.

@Test
public void customTemplateEngine() throws Exception {
    GroovyMarkupView view = new GroovyMarkupView();
    view.setTemplateEngine(new TestTemplateEngine());
    view.setApplicationContext(this.webAppContext);
    DirectFieldAccessor accessor = new DirectFieldAccessor(view);
    TemplateEngine engine = (TemplateEngine) accessor.getPropertyValue("engine");
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(TestTemplateEngine.class);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.Test)

Example 8 with DirectFieldAccessor

use of cn.taketoday.beans.DirectFieldAccessor in project today-infrastructure by TAKETODAY.

the class GroovyMarkupViewTests method detectTemplateEngine.

@Test
public void detectTemplateEngine() throws Exception {
    GroovyMarkupView view = new GroovyMarkupView();
    view.setTemplateEngine(new TestTemplateEngine());
    view.setApplicationContext(this.webAppContext);
    DirectFieldAccessor accessor = new DirectFieldAccessor(view);
    TemplateEngine engine = (TemplateEngine) accessor.getPropertyValue("engine");
    assertThat(engine).isNotNull();
    assertThat(engine.getClass()).isEqualTo(TestTemplateEngine.class);
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.Test)

Example 9 with DirectFieldAccessor

use of cn.taketoday.beans.DirectFieldAccessor in project today-infrastructure by TAKETODAY.

the class ScriptTemplateViewResolverTests method viewClass.

@Test
public void viewClass() throws Exception {
    ScriptTemplateViewResolver resolver = new ScriptTemplateViewResolver();
    assertThat(resolver.requiredViewClass()).isEqualTo(ScriptTemplateView.class);
    DirectFieldAccessor viewAccessor = new DirectFieldAccessor(resolver);
    Class<?> viewClass = (Class<?>) viewAccessor.getPropertyValue("viewClass");
    assertThat(viewClass).isEqualTo(ScriptTemplateView.class);
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.Test)

Example 10 with DirectFieldAccessor

use of cn.taketoday.beans.DirectFieldAccessor in project today-infrastructure by TAKETODAY.

the class BinaryExceptionClassifierTests method testClassifySubclassMatchInCauseFalse.

@Test
public void testClassifySubclassMatchInCauseFalse() {
    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
    map.put(IllegalStateException.class, true);
    map.put(BarException.class, false);
    BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(map, true);
    binaryExceptionClassifier.setTraverseCauses(true);
    assertTrue(binaryExceptionClassifier.classify(new RuntimeException(new FooException("Foo", new BarException()))));
    assertTrue(((Map<?, ?>) new DirectFieldAccessor(binaryExceptionClassifier).getPropertyValue("classified")).containsKey(FooException.class));
}
Also used : HashMap(java.util.HashMap) DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

DirectFieldAccessor (cn.taketoday.beans.DirectFieldAccessor)46 Test (org.junit.jupiter.api.Test)34 ScriptEngine (javax.script.ScriptEngine)6 Test (org.junit.Test)6 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)4 ThreadPoolTaskScheduler (cn.taketoday.scheduling.concurrent.ThreadPoolTaskScheduler)4 TemplateEngine (groovy.text.TemplateEngine)4 MarkupTemplateEngine (groovy.text.markup.MarkupTemplateEngine)4 Method (java.lang.reflect.Method)4 Map (java.util.Map)4 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)4 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)3 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)3 Advisor (cn.taketoday.aop.Advisor)2 Advised (cn.taketoday.aop.framework.Advised)2 LifecycleProcessor (cn.taketoday.context.LifecycleProcessor)2 StaticApplicationContext (cn.taketoday.context.support.StaticApplicationContext)2 MediaType (cn.taketoday.http.MediaType)2 ExponentialBackOffPolicy (cn.taketoday.retry.backoff.ExponentialBackOffPolicy)2 SimpleRetryPolicy (cn.taketoday.retry.policy.SimpleRetryPolicy)2