Search in sources :

Example 11 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class ScriptTemplateViewTests method customEngineAndRenderFunction.

@Test
public void customEngineAndRenderFunction() throws Exception {
    ScriptEngine engine = mock(InvocableScriptEngine.class);
    given(engine.get("key")).willReturn("value");
    this.view.setEngine(engine);
    this.view.setRenderFunction("render");
    this.view.setApplicationContext(this.wac);
    engine = this.view.getEngine();
    assertNotNull(engine);
    assertEquals("value", engine.get("key"));
    DirectFieldAccessor accessor = new DirectFieldAccessor(this.view);
    assertNull(accessor.getPropertyValue("renderObject"));
    assertEquals("render", accessor.getPropertyValue("renderFunction"));
    assertEquals(StandardCharsets.UTF_8, accessor.getPropertyValue("charset"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 12 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

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");
    assertNotNull(engine);
    assertEquals(TestTemplateEngine.class, engine.getClass());
}
Also used : MarkupTemplateEngine(groovy.text.markup.MarkupTemplateEngine) TemplateEngine(groovy.text.TemplateEngine) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 13 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class AbstractTyrusRequestUpgradeStrategy method createEndpoint.

private Object createEndpoint(ServerEndpointRegistration registration, ComponentProviderService provider, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException {
    DirectFieldAccessor accessor = new DirectFieldAccessor(engine);
    Object sessionListener = accessor.getPropertyValue("sessionListener");
    Object clusterContext = accessor.getPropertyValue("clusterContext");
    try {
        if (constructorWithBooleanArgument) {
            // Tyrus 1.11+
            return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null, Boolean.TRUE);
        } else {
            return constructor.newInstance(registration.getEndpoint(), registration, provider, container, "/", registration.getConfigurator(), sessionListener, clusterContext, null);
        }
    } catch (Exception ex) {
        throw new HandshakeFailureException("Failed to register " + registration, ex);
    }
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException) ServletException(javax.servlet.ServletException) DeploymentException(javax.websocket.DeploymentException) IOException(java.io.IOException) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException)

Example 14 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class KafkaAutoConfigurationTests method listenerProperties.

@Test
public void listenerProperties() {
    load("spring.kafka.template.default-topic=testTopic", "spring.kafka.listener.ack-mode=MANUAL", "spring.kafka.listener.ack-count=123", "spring.kafka.listener.ack-time=456", "spring.kafka.listener.concurrency=3", "spring.kafka.listener.poll-timeout=2000");
    DefaultKafkaProducerFactory<?, ?> producerFactory = this.context.getBean(DefaultKafkaProducerFactory.class);
    DefaultKafkaConsumerFactory<?, ?> consumerFactory = this.context.getBean(DefaultKafkaConsumerFactory.class);
    KafkaTemplate<?, ?> kafkaTemplate = this.context.getBean(KafkaTemplate.class);
    KafkaListenerContainerFactory<?> kafkaListenerContainerFactory = this.context.getBean(KafkaListenerContainerFactory.class);
    assertThat(new DirectFieldAccessor(kafkaTemplate).getPropertyValue("producerFactory")).isEqualTo(producerFactory);
    assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic");
    DirectFieldAccessor dfa = new DirectFieldAccessor(kafkaListenerContainerFactory);
    assertThat(dfa.getPropertyValue("consumerFactory")).isEqualTo(consumerFactory);
    assertThat(dfa.getPropertyValue("containerProperties.ackMode")).isEqualTo(AckMode.MANUAL);
    assertThat(dfa.getPropertyValue("containerProperties.ackCount")).isEqualTo(123);
    assertThat(dfa.getPropertyValue("containerProperties.ackTime")).isEqualTo(456L);
    assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3);
    assertThat(dfa.getPropertyValue("containerProperties.pollTimeout")).isEqualTo(2000L);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 15 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class JmsAutoConfigurationTests method testDefaultContainerFactoryNonJtaTransactionManager.

@Test
public void testDefaultContainerFactoryNonJtaTransactionManager() {
    this.context = createContext(TestConfiguration8.class, EnableJmsConfiguration.class);
    JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
    assertThat(jmsListenerContainerFactory.getClass()).isEqualTo(DefaultJmsListenerContainerFactory.class);
    DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
    assertThat(listenerContainer.isSessionTransacted()).isTrue();
    assertThat(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")).isNull();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)95 Test (org.junit.Test)79 List (java.util.List)25 Method (java.lang.reflect.Method)16 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)15 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)15 ScheduledTaskRegistrar (org.springframework.scheduling.config.ScheduledTaskRegistrar)15 IntervalTask (org.springframework.scheduling.config.IntervalTask)8 CronTask (org.springframework.scheduling.config.CronTask)7 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)5 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)4 DataSourceTransactionManagerAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration)4 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)4 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)4 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 JdbcOperationsSessionRepository (org.springframework.session.jdbc.JdbcOperationsSessionRepository)4 ViewResolver (org.springframework.web.servlet.ViewResolver)4