Search in sources :

Example 1 with DirectFieldAccessor

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

the class GroovyMarkupViewResolverTests method viewClass.

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

Example 2 with DirectFieldAccessor

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

the class MappingJackson2JsonViewTests method validateResult.

private void validateResult() throws Exception {
    String json = response.getContentAsString();
    DirectFieldAccessor viewAccessor = new DirectFieldAccessor(view);
    String jsonPrefix = (String) viewAccessor.getPropertyValue("jsonPrefix");
    if (jsonPrefix != null) {
        json = json.substring(5);
    }
    Object jsResult = jsContext.evaluateString(jsScope, "(" + json + ")", "JSON Stream", 1, null);
    assertThat(jsResult).as("Json Result did not eval as valid JavaScript").isNotNull();
    MediaType mediaType = MediaType.parseMediaType(response.getContentType());
    assertThat(mediaType.isCompatibleWith(MediaType.APPLICATION_JSON)).isTrue();
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) MediaType(cn.taketoday.http.MediaType) ScriptableObject(org.mozilla.javascript.ScriptableObject)

Example 3 with DirectFieldAccessor

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

the class ScriptTemplateViewTests method engineSupplierWithSharedEngine.

// gh-23258
@Test
public void engineSupplierWithSharedEngine() {
    this.configurer.setEngineSupplier(() -> mock(InvocableScriptEngine.class));
    this.configurer.setRenderObject("Template");
    this.configurer.setRenderFunction("render");
    this.configurer.setSharedEngine(true);
    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).isTrue();
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.jupiter.api.Test)

Example 4 with DirectFieldAccessor

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

the class ScriptTemplateViewTests method detectScriptTemplateConfigWithEngineName.

@Test
public void detectScriptTemplateConfigWithEngineName() {
    this.configurer.setEngineName("nashorn");
    this.configurer.setRenderObject("Template");
    this.configurer.setRenderFunction("render");
    DirectFieldAccessor accessor = new DirectFieldAccessor(view);
    this.view.setApplicationContext(this.wac);
    assertThat(accessor.getPropertyValue("engineName")).isEqualTo("nashorn");
    assertThat(accessor.getPropertyValue("engine")).isNotNull();
    assertThat(accessor.getPropertyValue("renderObject")).isEqualTo("Template");
    assertThat(accessor.getPropertyValue("renderFunction")).isEqualTo("render");
    assertThat(accessor.getPropertyValue("contentType")).isEqualTo(MediaType.TEXT_HTML_VALUE);
    assertThat(accessor.getPropertyValue("charset")).isEqualTo(StandardCharsets.UTF_8);
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.Test)

Example 5 with DirectFieldAccessor

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

the class ScheduledTasksBeanDefinitionParserTests method checkScheduler.

@Test
public void checkScheduler() {
    Object schedulerBean = this.context.getBean("testScheduler");
    Object schedulerRef = new DirectFieldAccessor(this.registrar).getPropertyValue("taskScheduler");
    assertThat(schedulerRef).isEqualTo(schedulerBean);
}
Also used : DirectFieldAccessor(cn.taketoday.beans.DirectFieldAccessor) Test(org.junit.jupiter.api.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