Example usage for org.springframework.context.annotation AnnotationConfigApplicationContext close

List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context.annotation AnnotationConfigApplicationContext close.

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java

@Test
public void ingestQueryCanBeCustomized() {
    String query = "insert into book (isbn, title, author) values (?, ?, ?)";
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "ingest-query:" + query);
    context.register(Conf.class);
    context.refresh();//from  ww w. j ava 2  s . co m
    CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class);
    assertThat(properties.getIngestQuery(), equalTo(query));
    context.close();
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateConditionsUnitTests.java

/**
 * Test to make sure that when a supported security is enabled the class fires.
 *
 * @throws Exception on any error//w  ww . j a  va2  s  .co m
 */
@Test
public void canEnableBeanWithAllJWTConditionsEnabled() throws Exception {
    final AnnotationConfigApplicationContext context = this.load(PingFederateJWTEnabledConfig.class,
            "genie.security.oauth2.enabled:true", "genie.security.oauth2.pingfederate.enabled:true",
            "genie.security.oauth2.pingfederate.jwt.enabled:true");
    Assert.assertTrue(context.containsBean("myBean"));
    context.close();
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateConditionsUnitTests.java

/**
 * Test to make sure that when a supported security is missing the class doesn't fire.
 *
 * @throws Exception on any error//w ww  . j  ava  2 s  .c o  m
 */
@Test
public void cantEnableBeanWithAnyJWTConditionsMissing() throws Exception {
    final AnnotationConfigApplicationContext context = this.load(PingFederateJWTEnabledConfig.class,
            "genie.security.oauth2.enabled:true", "genie.security.oauth2.pingfederate.enabled:true",
            "genie.security.oauth2.pingfederate.jwt.enabled:false");
    Assert.assertFalse(context.containsBean("myBean"));
    context.close();
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateConditionsUnitTests.java

/**
 * Test to make sure that when a supported security is enabled the class fires.
 *
 * @throws Exception on any error//from   w  ww.  j a  v a2  s. co  m
 */
@Test
public void canEnableBeanWithAllRemoteConditionsEnabled() throws Exception {
    final AnnotationConfigApplicationContext context = this.load(PingFederateRemoteEnabledConfig.class,
            "genie.security.oauth2.enabled:true", "genie.security.oauth2.pingfederate.enabled:true",
            "genie.security.oauth2.pingfederate.jwt.enabled:false");
    Assert.assertTrue(context.containsBean("myBean"));
    context.close();
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateConditionsUnitTests.java

/**
 * Test to make sure that when a supported security is missing the class doesn't fire.
 *
 * @throws Exception on any error/*  w  w  w .java  2 s.  c o  m*/
 */
@Test
public void cantEnableBeanWithAnyRemoteConditionsMissing() throws Exception {
    final AnnotationConfigApplicationContext context = this.load(PingFederateRemoteEnabledConfig.class,
            "genie.security.oauth2.enabled:true", "genie.security.oauth2.pingfederate.enabled:false",
            "genie.security.oauth2.pingfederate.jwt.enabled:false");
    Assert.assertFalse(context.containsBean("myBean"));
    context.close();
}

From source file:com.doctor.spring4.blog.code.WireObjectDependenciesOutsideSpring.java

/**
 * /*from  w ww  .j  a  va 2s .co  m*/
 * Using @Configurable, the catch though is that it requires AspectJ to work.
 * Spring essentially enhances the constructor of the class to inject in the dependencies along the lines of what is being explicitly done in the third approach above:
 * The following is also required to configure the Aspect responsible for @Configurable weaving:
 * <context:spring-configured/>
 * 
 * @see http://stackoverflow.com/questions/27744287/what-is-the-spring-java-config-equivalent-of-contextspring-configured
 */
@Ignore
@Test
public void test_() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            SpringConfig2.class);
    Person2 person = new Person2();
    assertNull(person.getContext());

    assertNotNull(person.getContext());
    Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);

    applicationContext.close();
}

From source file:nats.client.spring.JavaConfigAnnotationConfigTest.java

@Test
public void subscribeAnnotationNamedNatsBean() {
    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            NamedNatsAnnotationConfig.class);
    try {/* w w w.ja  v a2s . c  om*/
        final Nats nats = context.getBean(NATS_BEAN, Nats.class);
        final Nats wrongNats = context.getBean(WRONG_NATS_BEAN, Nats.class);
        wrongNats.publish("test", "Should not get processed");
        testNatsConfig(context, nats);
    } finally {
        context.close();
    }
}

From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java

@Test
public void queryTypeCanBeCustomized() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "query-type:" + CassandraMessageHandler.Type.UPDATE);
    context.register(Conf.class);
    context.refresh();/*w w w .  j  a v  a 2s  . c om*/
    CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class);
    assertThat(properties.getQueryType(), equalTo(CassandraMessageHandler.Type.UPDATE));
    context.close();
}

From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java

@Test
public void consistencyLevelCanBeCustomized() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "consistency-level:" + ConsistencyLevel.LOCAL_QUOROM);
    context.register(Conf.class);
    context.refresh();//from   w ww  .jav  a2  s.com
    CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class);
    assertThat(properties.getConsistencyLevel(), equalTo(ConsistencyLevel.LOCAL_QUOROM));
    context.close();
}

From source file:com.mine.cassandra.sink.CassandraSinkPropertiesTests.java

@Test
public void retryPolicyCanBeCustomized() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "retry-policy:" + RetryPolicy.DOWNGRADING_CONSISTENCY);
    context.register(Conf.class);
    context.refresh();//from  w  w w  .j a v  a  2s  .c  o  m
    CassandraSinkProperties properties = context.getBean(CassandraSinkProperties.class);
    assertThat(properties.getRetryPolicy(), equalTo(RetryPolicy.DOWNGRADING_CONSISTENCY));
    context.close();
}