Example usage for org.springframework.context.support StaticApplicationContext StaticApplicationContext

List of usage examples for org.springframework.context.support StaticApplicationContext StaticApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.support StaticApplicationContext StaticApplicationContext.

Prototype

public StaticApplicationContext() throws BeansException 

Source Link

Document

Create a new StaticApplicationContext.

Usage

From source file:ch.rasc.wampspring.method.WampAnnotationMethodMessageHandlerTest.java

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(this.clientOutboundChannel.send(any(WampMessage.class))).thenReturn(true);

    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    MethodParameterConverter paramConverter = new MethodParameterConverter(new ObjectMapper(),
            conversionService);/*from w w w  .  j  av a  2 s.  c  o m*/
    this.messageHandler = new WampAnnotationMethodMessageHandler(this.clientInboundChannel,
            this.clientOutboundChannel, this.eventMessenger, conversionService, paramConverter,
            new AntPathMatcher(), WampMessageSelectors.ACCEPT_ALL);

    @SuppressWarnings("resource")
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerPrototype("annotatedTestService", AnnotatedTestService.class);
    applicationContext.refresh();
    this.messageHandler.setApplicationContext(applicationContext);
    this.messageHandler.afterPropertiesSet();

    this.messageHandler.start();
}

From source file:com.github.pjungermann.config.validation.ConfigValidatorTest.java

@BeforeClass
public static void setUpApplicationContext() {
    applicationContext = new StaticApplicationContext();

    registerSingleton(/*from w w  w .j a v a 2s . c om*/
            // config factories + converters
            DefaultKeyBuilder.class, ConfigObjectConfigFactory.class, ConfigObjectConverter.class,
            IniConfigFactory.class, IniConverter.class, JsonConfigFactory.class, JsonConverter.class,
            PropertiesConfigFactory.class, PropertiesConverter.class, YamlConfigFactory.class,
            YamlConverter.class,
            // config factory selector
            DefaultConfigFactorySelector.class,
            // type converter
            AsTypeConverter.class,
            // constraints
            MatchesConstraintFactory.class, MaxSizeConstraintFactory.class, NullableConstraintFactory.class,
            RangeConstraintFactory.class, SizeConstraintFactory.class);

    autowireByConstructor(
            // constraint registry
            ConstraintRegistry.class,
            // config and specification loader
            DefaultConfigLoader.class, GroovyDSLSpecificationReader.class,
            DefaultConfigSpecificationLoader.class,
            // validator
            ConfigValidator.class);

    applicationContext.refresh();
}

From source file:io.nuun.plugin.spring.SpringPluginTest.java

@Test
public void canHandle_should_return_true_for_bean_factory_classes() {
    InternalDependencyInjectionProvider provider = new InternalDependencyInjectionProvider();
    ApplicationContext application = new StaticApplicationContext();
    assertThat(provider.canHandle(application.getAutowireCapableBeanFactory().getClass())).isTrue();
}

From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_methodAnnotatedWithMessageMappingAnnotation_methodInvokedForIncomingMessage()
        throws Exception {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();/*from  w  w w  .ja  va2  s .  com*/

    MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
    messageHandler.handleMessage(MessageBuilder.withPayload("testContent")
            .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "receive").build());

    IncomingMessageHandler messageListener = applicationContext.getBean(IncomingMessageHandler.class);
    assertEquals("testContent", messageListener.getLastReceivedMessage());
}

From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfigTest.java

@Test
public void testAfterPropertiesSet3() {
    final StaticApplicationContext appContext;
    final AutowiredRemoteServiceGroupConfig config;

    appContext = new StaticApplicationContext();
    appContext.registerSingleton("testService1", TestService1Impl.class);

    config = new AutowiredRemoteServiceGroupConfig();
    config.setBasePackages(Arrays.asList(new String[] { "de.itsvs.cwtrpc.controller.config2." }));
    config.setApplicationContext(appContext);
    config.afterPropertiesSet();/*from   ww w.jav  a  2 s.  c o m*/

    Assert.assertTrue(config.getChildGroupConfigs().isEmpty());
    Assert.assertEquals(0, config.getServiceConfigs().size());
}

From source file:org.terasoluna.gfw.web.codelist.CodeListInterceptorTest.java

/**
 * [preHandle] Case of CodeList is zero.
 * <p>//from w w w.  j  a v a2 s  . c o  m
 * [Expected Result]
 * <ol>
 * <li>do nothing.(don't occur error.)</li>
 * </ol>
 * </p>
 * @throws Exception
 */
@Test
public void testPreHandle_zero() throws Exception {

    // do setup.
    testTarget.setApplicationContext(new StaticApplicationContext());
    testTarget.afterPropertiesSet();

    // do test.
    boolean actualReturnValue = testTarget.preHandle(mockRequest, mockResponse, null);

    // do assert.
    assertThat(mockRequest.getAttributeNames().hasMoreElements(), is(false));
    assertThat(actualReturnValue, is(true));

}

From source file:org.springframework.samples.portfolio.web.standalone.StandalonePortfolioControllerTests.java

@Before
public void setup() {

    this.portfolioService = new PortfolioServiceImpl();
    this.tradeService = new TestTradeService();
    PortfolioController controller = new PortfolioController(this.portfolioService, this.tradeService);

    this.clientOutboundChannel = new TestMessageChannel();

    this.annotationMethodMessageHandler = new TestSimpAnnotationMethodMessageHandler(new TestMessageChannel(),
            clientOutboundChannel, new SimpMessagingTemplate(new TestMessageChannel()));

    this.annotationMethodMessageHandler.registerHandler(controller);
    this.annotationMethodMessageHandler.setDestinationPrefixes(Arrays.asList("/app"));
    this.annotationMethodMessageHandler.setMessageConverter(new MappingJackson2MessageConverter());
    this.annotationMethodMessageHandler.setApplicationContext(new StaticApplicationContext());
    this.annotationMethodMessageHandler.afterPropertiesSet();
}

From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_methodWithCustomObjectAsParameter_parameterIsConverted() throws Exception {
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("incomingMessageHandler",
            IncomingMessageHandlerWithCustomParameter.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();/*from w w  w . j  a v  a2s.c o m*/

    MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);
    DummyKeyValueHolder messagePayload = new DummyKeyValueHolder("myKey", "A value");
    MappingJackson2MessageConverter jsonMapper = new MappingJackson2MessageConverter();
    Message<?> message = jsonMapper.toMessage(messagePayload,
            new MessageHeaders(Collections.<String, Object>singletonMap(
                    QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "testQueue")));
    messageHandler.handleMessage(message);

    IncomingMessageHandlerWithCustomParameter messageListener = applicationContext
            .getBean(IncomingMessageHandlerWithCustomParameter.class);
    assertNotNull(messageListener.getLastReceivedMessage());
    assertEquals("myKey", messageListener.getLastReceivedMessage().getKey());
    assertEquals("A value", messageListener.getLastReceivedMessage().getValue());
}

From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfigTest.java

@Test
public void testAfterPropertiesSet4() {
    final StaticApplicationContext appContext;
    final AutowiredRemoteServiceGroupConfig config;

    appContext = new StaticApplicationContext();
    appContext.registerSingleton("testService1", TestService1Impl.class);

    config = new AutowiredRemoteServiceGroupConfig();
    config.setBasePackages(Arrays.asList(
            new String[] { "de.itsvs.cwtrpc.controller.config2.", "de.itsvs.cwtrpc.controller.config." }));
    config.setApplicationContext(appContext);
    config.afterPropertiesSet();/*w ww.ja v  a 2 s  . com*/

    Assert.assertTrue(config.getChildGroupConfigs().isEmpty());
    Assert.assertEquals(1, config.getServiceConfigs().size());
}

From source file:at.ac.univie.isc.asio.nest.D2rqNestAssemblerTest.java

@Test
public void should_create_singleton_assembler_if_no_optional_listeners_present() throws Exception {
    final StaticApplicationContext parent = new StaticApplicationContext();
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.getBeanFactory().registerSingleton("factory", new SpringContextFactory(parent));
    context.register(D2rqNestAssembler.class);
    context.refresh();//w  ww .jav a 2  s. c om
    final D2rqNestAssembler actual = context.getBean(D2rqNestAssembler.class);
    assertThat(actual, notNullValue());
}