Search in sources :

Example 66 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomainAndIdentity.

@Test
public void testRegistrationWithDifferentDomainAndIdentity() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("domain", "test-domain");
    properties.put("ensureUniqueRuntimeObjectNames", true);
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class, null, new MutablePropertyValues(properties)));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("test-domain", "endpoint1", true, this.context))).isNotNull();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 67 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method applicationFailedEventCleansUpLoggingSystem.

@Test
public void applicationFailedEventCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ApplicationFailedEvent(this.springApplication, new String[0], new GenericApplicationContext(), new Exception()));
    assertThat(loggingSystem.cleanedUp).isTrue();
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 68 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method closingChildContextDoesNotCleanUpLoggingSystem.

@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    GenericApplicationContext childContext = new GenericApplicationContext();
    childContext.setParent(this.context);
    multicastEvent(new ContextClosedEvent(childContext));
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
    childContext.close();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 69 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class SimpleMessageListenerContainerTests method testContextRefreshedEventStartsTheConnectionByDefault.

@Test
public void testContextRefreshedEventStartsTheConnectionByDefault() throws Exception {
    MessageConsumer messageConsumer = mock(MessageConsumer.class);
    Session session = mock(Session.class);
    // Queue gets created in order to create MessageConsumer for that Destination...
    given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
    // and then the MessageConsumer gets created...
    // no MessageSelector...
    given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer);
    Connection connection = mock(Connection.class);
    // session gets created in order to register MessageListener...
    given(connection.createSession(this.container.isSessionTransacted(), this.container.getSessionAcknowledgeMode())).willReturn(session);
    // and the connection is start()ed after the listener is registered...
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willReturn(connection);
    this.container.setConnectionFactory(connectionFactory);
    this.container.setDestinationName(DESTINATION_NAME);
    this.container.setMessageListener(new TestMessageListener());
    this.container.afterPropertiesSet();
    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
    context.refresh();
    verify(connection).setExceptionListener(this.container);
    verify(connection).start();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ConnectionFactory(javax.jms.ConnectionFactory) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Connection(javax.jms.Connection) Session(javax.jms.Session) Test(org.junit.Test)

Example 70 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class HeaderMethodArgumentResolverTests method resolveOptionalHeaderAsEmpty.

@Test
public void resolveOptionalHeaderAsEmpty() throws Exception {
    GenericApplicationContext cxt = new GenericApplicationContext();
    cxt.refresh();
    HeaderMethodArgumentResolver resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());
    Message<String> message = MessageBuilder.withPayload("foo").build();
    Object result = resolver.resolveArgument(paramOptional, message);
    assertEquals(Optional.empty(), result);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.Test)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)245 Test (org.junit.Test)190 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)80 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)38 BeanCreationException (org.springframework.beans.factory.BeanCreationException)26 ClassPathResource (org.springframework.core.io.ClassPathResource)19 TestBean (org.springframework.tests.sample.beans.TestBean)17 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)15 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)12 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeansException (org.springframework.beans.BeansException)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 HashMap (java.util.HashMap)7 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Before (org.junit.Before)6 Properties (java.util.Properties)5 EntityManager (javax.persistence.EntityManager)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5