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:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() throws Exception {
    // Arrange/*from w  w w  . j a  v a  2s. c  o  m*/
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("notificationMessageReceiver", NotificationMessageReceiver.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();

    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);
    NotificationMessageReceiver notificationMessageReceiver = applicationContext
            .getBean(NotificationMessageReceiver.class);

    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "Hi!");
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();

    // Act
    queueMessageHandler.handleMessage(MessageBuilder.withPayload(payload)
            .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "testQueue")
            .build());

    // Assert
    assertEquals("Hi!", notificationMessageReceiver.getSubject());
    assertEquals("Hello World!", notificationMessageReceiver.getMessage());
}

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

@Test
public void testGetRemoteServiceInterface1() {
    final StaticApplicationContext appContext;
    final PreparedRemoteServiceConfigBuilder builder;

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

    builder = new PreparedRemoteServiceConfigBuilder();
    builder.setBeanFactory(appContext);/*from w  ww . j a  v a 2s. c o  m*/

    Assert.assertEquals(TestService1.class, builder.getRemoteServiceInterface("testService"));
}

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

@Test(expected = CwtRpcException.class)
public void testGetRemoteServiceInterface2() {
    final StaticApplicationContext appContext;
    final PreparedRemoteServiceConfigBuilder builder;

    appContext = new StaticApplicationContext();
    appContext.registerSingleton("testService", TestService10Impl.class);

    builder = new PreparedRemoteServiceConfigBuilder();
    builder.setBeanFactory(appContext);/*from ww w .  ja  va 2s.c  o  m*/

    builder.getRemoteServiceInterface("testService");
}

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

@Test(expected = NoSuchBeanDefinitionException.class)
public void testGetRemoteServiceInterface3() {
    final StaticApplicationContext appContext;
    final PreparedRemoteServiceConfigBuilder builder;

    appContext = new StaticApplicationContext();

    builder = new PreparedRemoteServiceConfigBuilder();
    builder.setBeanFactory(appContext);/*from   ww  w .jav a2 s.  c om*/

    builder.getRemoteServiceInterface("testService");
}

From source file:org.fusesource.camel.component.sap.SapIDocTestSupport.java

@Override
protected AbstractApplicationContext createApplicationContext() {
    return new StaticApplicationContext();
}

From source file:ome.client.utests.Preferences3Test.java

@Test
public void test_makeOurOwnDefault() throws Exception {
    // Others:/*from   w w w  .  jav  a  2s. c  om*/
    // new ManagedMap();
    // BeanWrapper bw = new BeanWrapperImpl( defaultMap );

    Map defaultMap = new HashMap();
    defaultMap.put("omero.user", "foo");
    ConstructorArgumentValues cav = new ConstructorArgumentValues();
    cav.addGenericArgumentValue(defaultMap);
    BeanDefinition def = new RootBeanDefinition(HashMap.class, cav, null);
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerBeanDefinition("map", def);
    ac.refresh();

    ConstructorArgumentValues testCav = new ConstructorArgumentValues();
    testCav.addGenericArgumentValue(new RuntimeBeanReference("map"));
    BeanDefinition testDef = new RootBeanDefinition(HashMap.class, testCav, null);
    StaticApplicationContext defaultTest = new StaticApplicationContext(ac);
    defaultTest.registerBeanDefinition("test", testDef);
    defaultTest.refresh();
    assertTrue("foo".equals(((Map) defaultTest.getBean("test")).get("omero.user")));

}

From source file:ome.client.utests.Preferences3Test.java

@Test
public void test_makeOurOwnRuntime() throws Exception {

    // use properties
    // if no Properties given, then is static (global)

    Map runtimeMap = new HashMap();
    runtimeMap.put("omero.user", "bar");
    ConstructorArgumentValues cav2 = new ConstructorArgumentValues();
    cav2.addGenericArgumentValue(runtimeMap);
    BeanDefinition def2 = new RootBeanDefinition(HashMap.class, cav2, null);
    StaticApplicationContext ac2 = new StaticApplicationContext();
    ac2.registerBeanDefinition("map", def2);
    ac2.refresh();//from w  w w  .j a va 2 s  .c  om

    ConstructorArgumentValues testCav2 = new ConstructorArgumentValues();
    testCav2.addGenericArgumentValue(new RuntimeBeanReference("map"));
    BeanDefinition testDef2 = new RootBeanDefinition(HashMap.class, testCav2, null);
    StaticApplicationContext defaultTest2 = new StaticApplicationContext(ac2);
    defaultTest2.registerBeanDefinition("test", testDef2);
    defaultTest2.refresh();
    assertTrue("bar".equals(((Map) defaultTest2.getBean("test")).get("omero.user")));

}

From source file:ome.client.utests.Preferences3Test.java

@Test(groups = "ticket:62")
@ExpectedExceptions(BeanInitializationException.class)
public void test_missingLoadProperties() {
    StaticApplicationContext ac = new StaticApplicationContext();
    PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer();
    ppc.setLocation(new ClassPathResource("DOES--NOT--EXIST"));

    ac.addBeanFactoryPostProcessor(ppc);
    ac.refresh();/*from w w  w. j  av a  2  s  . com*/
}

From source file:ome.client.utests.Preferences3Test.java

@Test(groups = "ticket:62")
public void test_missingLoadPropertiesIgnore() {
    StaticApplicationContext ac = new StaticApplicationContext();
    PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer();
    ppc.setLocation(new ClassPathResource("DOES--NOT--EXIST"));
    ppc.setIgnoreResourceNotFound(true);

    ac.addBeanFactoryPostProcessor(ppc);
    ac.refresh();//  w w  w . jav  a  2s  . c o  m

}

From source file:ome.client.utests.Preferences3Test.java

@Test(groups = "ticket:1058")
public void testOmeroUserIsProperlySetWithSpring2_5_5Manual() {

    Server s = new Server("localhost", 1099);
    Login l = new Login("me", "password");
    Properties p = s.asProperties();
    p.putAll(l.asProperties());/*from  ww w .  j ava  2 s . c  o  m*/

    // This is copied from OmeroContext. This is the parent context which
    // should contain the properties;
    Properties copy = new Properties(p);
    ConstructorArgumentValues ctorArg1 = new ConstructorArgumentValues();
    ctorArg1.addGenericArgumentValue(copy);
    BeanDefinition definition1 = new RootBeanDefinition(Properties.class, ctorArg1, null);
    StaticApplicationContext staticContext = new StaticApplicationContext();
    staticContext.registerBeanDefinition("properties", definition1);
    staticContext.refresh();

    // This is the child context and contains a definition of a
    // PlaceHolderConfigurer
    // as well as a user of
    StaticApplicationContext childContext = new StaticApplicationContext();

    MutablePropertyValues mpv2 = new MutablePropertyValues();
    mpv2.addPropertyValue("properties", new RuntimeBeanReference("properties"));
    mpv2.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_FALLBACK");
    mpv2.addPropertyValue("localOverride", "true");
    BeanDefinition definitionConfigurer = new RootBeanDefinition(PreferencesPlaceholderConfigurer.class, null,
            mpv2);
    childContext.registerBeanDefinition("propertiesPlaceholderConfigurer", definitionConfigurer);

    ConstructorArgumentValues cav2 = new ConstructorArgumentValues();
    cav2.addGenericArgumentValue("${omero.user}");
    BeanDefinition definitionTest = new RootBeanDefinition(String.class, cav2, null);
    childContext.registerBeanDefinition("test", definitionTest);

    childContext.setParent(staticContext);
    childContext.refresh();

    String test = (String) childContext.getBean("test");
    assertEquals(test, "me");

}