Java 类org.springframework.context.annotation.AnnotationConfigApplicationContext 实例源码

项目:zipkin-collector-eventhub    文件:EventHubCollectorAutoConfigurationTest.java   
@Test
public void provideCollectorComponent_canSetStorageContainerName() {

    String storageContainerName = "pashmak";

    context = new AnnotationConfigApplicationContext();
    addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
    addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
    addEnvironment(context, "zipkin.collector.eventhub.storageContainerName:" + storageContainerName);
    context.register(PropertyPlaceholderAutoConfiguration.class,
            EventHubCollectorAutoConfiguration.class,
            InMemoryConfiguration.class);
    context.refresh();

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(storageContainerName, collector.getStorageContainerName());
}
项目:sponge    文件:SimpleCamelProducerTest.java   
@Test
public void testCamelProducer() throws Exception {
    // Starting Spring context.
    try (GenericApplicationContext context = new AnnotationConfigApplicationContext(ExampleConfiguration.class)) {
        context.start();

        // Sending Camel message.
        CamelContext camel = context.getBean(CamelContext.class);
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        // Waiting for the engine to process an event.
        Engine engine = context.getBean(Engine.class);
        await().atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());

        assertFalse(engine.isError());
        context.stop();
    }
}
项目:easypump    文件:Main.java   
public static void main (String [] args)
{
    @SuppressWarnings({ "resource"})
    AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    PumpEngine engine = (PumpEngine)context.getBean(PumpEngine.class);
    engine.setArgs(args);
    try {
        engine.startPump();
    } catch (Exception e) {         
        logger.error("Exception Occured while doing buy/sell transaction", e);          
    }       

    System.out.println("\n\n\nHope you will make a profit in this pump ;)");
    System.out.println("if you could make a proit using this app please conside doing some donation with 1$ or 2$ to BTC address 1PfnwEdmU3Ki9htakiv4tciPXzo49RRkai \nit will help us doing more features in the future");
}
项目:wecard-server    文件:NServer.java   
public void init() {
    //启动并设置Spring
    AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
    ctx.registerShutdownHook();
    NContext.setApplicationContext(ctx);

    //初始化房间管理器
    HomeManager homeManager = HomeManager.getInstance();
    homeManager.init();

    //初始化用户管理器
    PlayerManager playerManager = PlayerManager.getInstance();
    playerManager.init();

    //初始化Gateway
    ClientManager clientManager = ClientManager.getInstance();
    clientManager.init();

    //启动异步处理器
    AsyncProcessor asyncProcessor = AsyncProcessor.getInstance();
    asyncProcessor.start();

    //启动滴答服务
    TickerService tickerService = TickerService.getInstance();
    tickerService.start();
}
项目:azure-spring-boot    文件:MediaServicesAutoConfigurationTest.java   
private void createAndFailWithCause(String cause) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(MediaServicesAutoConfiguration.class);

        Exception exception = null;
        try {
            context.refresh();
        } catch (Exception e) {
            exception = e;
        }

        assertThat(exception).isNotNull();
        assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
        assertThat(exception.getCause().getCause().toString()).contains(cause);
    }
}
项目:incubator-servicecomb-java-chassis    文件:TestLastPropertyPlaceholderConfigurer.java   
@Test
public void test() {
  AnnotationConfigApplicationContext context =
      new AnnotationConfigApplicationContext(this.getClass().getPackage().getName());
  Bean bean = context.getBean(Bean.class);

  Assert.assertEquals("aValue", bean.resolver.resolveStringValue("${a}"));
  try {
    bean.resolver.resolveStringValue("${b}");
    Assert.fail("must throw exception");
  } catch (IllegalArgumentException e) {
    Assert.assertEquals("Could not resolve placeholder 'b' in string value \"${b}\"", e.getMessage());
  }

  context.close();
}
项目:Spring-5.0-Cookbook    文件:TestScopes.java   
public static void main(String[] args) {
     AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
       context.register(BeanConfig.class);

       System.out.println("application context loaded.");

       context.refresh();
       System.out.println("*********The empRec1 bean ***************");
       Employee empRec1A = (Employee) context.getBean("empRec1");
       System.out.println("instance A: " + empRec1A.hashCode());
       Employee empRec1B = (Employee) context.getBean("empRec1");
       System.out.println("instance B: " +empRec1B.hashCode());

       System.out.println("*********The empRec2 bean ***************");
       Employee empRec2A = (Employee) context.getBean("empRec2");
       System.out.println("instance A: " + empRec2A.hashCode());
       Employee empRec2B = (Employee) context.getBean("empRec2");
       System.out.println("instance B: " + empRec2B.hashCode());

       context.registerShutdownHook();
}
项目:zipkin-collector-eventhub    文件:EventHubCollectorAutoConfigurationTest.java   
@Test
public void provideCollectorComponent_canSetCheckpointBatchSize() {

    int checkpointBatchSize = 1000;

    context = new AnnotationConfigApplicationContext();
    addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
    addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
    addEnvironment(context, "zipkin.collector.eventhub.checkpoint-batch-size:" + checkpointBatchSize);
    context.register(PropertyPlaceholderAutoConfiguration.class,
            EventHubCollectorAutoConfiguration.class,
            InMemoryConfiguration.class);
    context.refresh();

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(checkpointBatchSize, collector.getCheckpointBatchSize());
}
项目:spring-session-data-mongodb    文件:ReactiveMongoWebSessionConfigurationTest.java   
@Test
public void enableSpringWebSessionConfiguresThings() {

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(GoodConfig.class);
    this.context.refresh();

    WebSessionManager webSessionManagerFoundByType = this.context.getBean(WebSessionManager.class);
    Object webSessionManagerFoundByName = this.context.getBean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME);

    assertThat(webSessionManagerFoundByType).isNotNull();
    assertThat(webSessionManagerFoundByName).isNotNull();
    assertThat(webSessionManagerFoundByType).isEqualTo(webSessionManagerFoundByName);

    assertThat(this.context.getBean(ReactiveSessionRepository.class)).isNotNull();
}
项目:dev-courses    文件:Main2.java   
public static void main(String[] args) {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    IToDoListDAO repository = context.getBean(IToDoListDAO.class);

       // fetch all ToDoLists
       System.out.println("ToDoLists found with findAll():");
       System.out.println("-------------------------------");
       for (ToDoList ToDoList : repository.findAll()) {
           System.out.println(ToDoList);
       }
       System.out.println();

    context.close();

}
项目:azure-spring-boot    文件:StorageAutoConfigurationTest.java   
@Test
public void createStorageAccountWithInvalidConnectionString() {
    System.setProperty(CONNECTION_STRING_PROPERTY, INVALID_CONNECTION_STRING);

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(StorageAutoConfiguration.class);
        context.refresh();

        CloudStorageAccount cloudStorageAccount = null;
        try {
            cloudStorageAccount = context.getBean(CloudStorageAccount.class);
        } catch (Exception e) {
            assertThat(e).isExactlyInstanceOf(BeanCreationException.class);
        }

        assertThat(cloudStorageAccount).isNull();
    }

    System.clearProperty(CONNECTION_STRING_PROPERTY);
}
项目:azure-spring-boot    文件:ServiceBusAutoConfigurationTest.java   
private void verifyBeanCreationException(String message, Class<?> beanClass) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        Exception exception = null;
        try {
            context.register(ServiceBusAutoConfiguration.class);
            context.refresh();
            context.getBean(beanClass);
        } catch (Exception e) {
            exception = e;
        }

        assertThat(exception).isNotNull();
        assertThat(exception.getMessage()).contains(message);
        assertThat(exception).isExactlyInstanceOf(BeanCreationException.class);
    }
}
项目:azure-spring-boot    文件:DocumentDBPropertiesTest.java   
@Test
public void canSetAllProperties() {
    PropertySettingUtil.setProperties();

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(Config.class);
        context.refresh();
        final DocumentDBProperties properties = context.getBean(DocumentDBProperties.class);

        assertThat(properties.getUri()).isEqualTo(PropertySettingUtil.URI);
        assertThat(properties.getKey()).isEqualTo(PropertySettingUtil.KEY);
        assertThat(properties.getConsistencyLevel()).isEqualTo(PropertySettingUtil.CONSISTENCY_LEVEL);
        assertThat(properties.isAllowTelemetry()).isEqualTo(PropertySettingUtil.ALLOW_TELEMETRY_TRUE);
    }

    PropertySettingUtil.unsetProperties();
}
项目:redirector    文件:WebServiceClientHelper.java   
public static HttpServer httpBuilder (String connectionUrl) {
    try {
        URL url = new URL(connectionUrl);

        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringAnnotationConfig.class);

        ResourceConfig resourceConfig = new ResourceConfig();
        resourceConfig.register(RequestContextFilter.class);
        resourceConfig.property("contextConfig", annotationConfigApplicationContext);
        resourceConfig.register(RestSupport.class);

        URI baseUri = URI.create(url.getProtocol() + "://" + url.getAuthority());
        return  GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    } catch (Exception e) {
        Assert.fail("Could'n parse configfile." + e.getMessage());
    }
    return null;
}
项目:db-queue    文件:SpringQueueCollectorTest.java   
@Test
public void should_fail_on_invalid_queue_definitions() throws Exception {
    try {
        new AnnotationConfigApplicationContext(InvalidContext.class);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("unable to collect queue beans:" + System.lineSeparator() +
                "duplicate bean: name=testProducer2, class=SpringQueueProducer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testConsumer2, class=SpringQueueConsumer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testTransformer2, class=SpringTaskPayloadTransformer, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=testShardRouter2, class=SpringQueueShardRouter, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springTaskLifecycleListener2, class=SpringTaskLifecycleListener, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springThreadLifecycleListener2, class=SpringThreadLifecycleListener, queueId=test_queue" + System.lineSeparator() +
                "duplicate bean: name=springQueueExternalExecutor2, class=SpringQueueExternalExecutor, queueId=test_queue"));
        return;
    }
    Assert.fail("context should not be constructed");
}
项目:zipkin-collector-eventhub    文件:EventHubCollectorAutoConfigurationTest.java   
@Test
public void provideCollectorComponent_canSetProcessorHostName() {

    String processorHostName = "pashmak";

    context = new AnnotationConfigApplicationContext();
    addEnvironment(context, "zipkin.collector.eventhub.storageConnectionString:" + dummyEventHubConnectionString);
    addEnvironment(context, "zipkin.collector.eventhub.eventHubConnectionString:" + dummyStorageConnectionString );
    addEnvironment(context, "zipkin.collector.eventhub.processorHostName:" + processorHostName);
    context.register(PropertyPlaceholderAutoConfiguration.class,
            EventHubCollectorAutoConfiguration.class,
            InMemoryConfiguration.class);
    context.refresh();

    EventHubCollector collector = context.getBean(EventHubCollector.class);
    assertNotNull(collector);
    assertEquals(processorHostName, collector.getProcessorHostName());
}
项目:JavaStudy    文件:Test.java   
@org.junit.Test
public void testCustomKeyGenerator(){
    ApplicationContext atc=new AnnotationConfigApplicationContext(RedisStartConfig.class);
    KeyGenerator obj = (KeyGenerator) atc.getBean("customKeyGenerator");
    PrinterUtils.printILog(obj);

}
项目:azure-spring-boot    文件:StorageAutoConfigurationTest.java   
@Test
public void createStorageAccountWithValidConnectionStringFormat() {
    System.setProperty(CONNECTION_STRING_PROPERTY, CONNECTION_STRING_WITH_VALID_FORMAT);

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(StorageAutoConfiguration.class);
        context.refresh();

        final CloudStorageAccount cloudStorageAccount = context.getBean(CloudStorageAccount.class);
        assertThat(cloudStorageAccount).isNotNull();
    }

    System.clearProperty(CONNECTION_STRING_PROPERTY);
}
项目:dubbocloud    文件:JavaConfigContainer.java   
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_JAVACONFIG;
    }
    context = new AnnotationConfigApplicationContext(configPath);
    context.start();
}
项目:tensorflow    文件:TwitterSentimentProcessorPropertiesTests.java   
@Test
public void vocabularyCanBeCustomized() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    EnvironmentTestUtils.addEnvironment(context, "tensorflow.twitter.vocabulary:/remote");
    context.register(Conf.class);
    context.refresh();
    TwitterSentimentProcessorProperties properties = context.getBean(TwitterSentimentProcessorProperties.class);
    assertThat(properties.getVocabulary(), equalTo(context.getResource("/remote")));
    context.close();
}
项目:hello-spring    文件:Main.java   
public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
                    ConditionConfig.class);
    ListService listService = context.getBean(ListService.class);
    System.err.println(context.getEnvironment().getProperty("os.name") + "系统下的列表命令为:"
                    + listService.showListCmd());
    context.close();
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:MySpringApplication.java   
public static void main(String[] args) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            MySpringApplication.class)) {
        MessageComponent messageComponent = context
                .getBean(MessageComponent.class);
        System.out.println(messageComponent.getMessage());
    }
}
项目:fo-veilarbjobbsokerkompetanse    文件:AbstractIntegrasjonsTest.java   
@SneakyThrows
public static void setupContext(Class<?>... classes) {
    DatabaseTestContext.setupContext(System.getProperty("database"));

    setProperty("no.nav.modig.security.sts.url", "111111");
    setProperty("no.nav.modig.security.systemuser.username", "username");
    setProperty("no.nav.modig.security.systemuser.password", "password");

    annotationConfigApplicationContext = new AnnotationConfigApplicationContext(classes);
    annotationConfigApplicationContext.start();
    platformTransactionManager = getBean(PlatformTransactionManager.class);

    MigrationUtils.createTables(getBean(DataSource.class));
}
项目:sponge    文件:SpringAutoStartupTest.java   
@Test
public void testSpringAutoStartupTrue() throws InterruptedException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfigAutoStartupTrue.class);
    ctx.start();

    try {
        Engine engine = ctx.getBean(Engine.class);

        assertTrue(engine.isRunning());
        assertFalse(engine.isError());
    } finally {
        ctx.close();
    }
}
项目:poi-visualizer    文件:POIVisualizer.java   
public static void main(String[] args) throws Exception {
    final String pckName = POIVisualizer.class.getPackage().getName();
    try (AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(pckName)) {
        POIVisualizer visualizer = ctx.getBean(POIVisualizer.class);
        visualizer.start();
    }

System.out.println("Exiting");
  }
项目:azure-spring-boot    文件:StoragePropertiesTest.java   
@Test
public void canSetProperties() {
    System.setProperty(CONNECTION_STRING_PROPERTY, CONNECTION_STRING);

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(Config.class);
        context.refresh();

        final StorageProperties properties = context.getBean(StorageProperties.class);
        assertThat(properties.getConnectionString()).isEqualTo(CONNECTION_STRING);
    }

    System.clearProperty(CONNECTION_STRING_PROPERTY);
}
项目:spring-security-oauth2-boot    文件:OAuth2AutoConfigurationTests.java   
@Test
public void testClientIsNotAuthCode() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(MinimalSecureNonWebApplication.class);
    TestPropertyValues.of("security.oauth2.client.clientId=client").applyTo(context);
    context.refresh();
    assertThat(countBeans(context, ClientCredentialsResourceDetails.class))
            .isEqualTo(1);
    context.close();
}
项目:Lagerta    文件:ReaderConfig.java   
public static AnnotationConfigApplicationContext create(ApplicationContext parent) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.setParent(parent);
    context.register(parent.getBean("reader-config", Class.class));
    context.refresh();
    return context;
}
项目:spring-session-data-mongodb    文件:ReactiveMongoWebSessionConfigurationTest.java   
@Test
public void overridingMongoSessionConverterWithBeanShouldWork() throws IllegalAccessException {

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(OverrideSessionConverterConfig.class);
    this.context.refresh();

    ReactiveMongoOperationsSessionRepository repository = this.context.getBean(ReactiveMongoOperationsSessionRepository.class);

    AbstractMongoSessionConverter converter = findMongoSessionConverter(repository);

    assertThat(converter)
        .extracting(AbstractMongoSessionConverter::getClass)
        .contains(JacksonMongoSessionConverter.class);
}
项目:mastering-junit5    文件:MySpringApplication.java   
public static void main(String[] args) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            MySpringApplication.class)) {
        MessageComponent messageComponent = context
                .getBean(MessageComponent.class);
        System.out.println(messageComponent.getMessage());
    }
}
项目:quickfixj-spring-boot-starter    文件:AbstractEndpointTests.java   
@Test
public void isEnabledFallbackToEnvironment() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    PropertySource<?> propertySource = new MapPropertySource("test", Collections
            .<String, Object>singletonMap(this.property + ".enabled", false));
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.register(this.configClass);
    this.context.refresh();
    assertThat(getEndpointBean().isEnabled()).isFalse();
}
项目:reactive.loanbroker.system    文件:LoanBrokerTests.java   
@Before
public void startServer(){
    if(!isServerStarted) {
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
        ac.register(TestingConfiguration.class);
        ac.refresh();

        ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(WebHttpHandlerBuilder.webHandler(new DispatcherHandler(ac)).build());
        HttpServer httpServer = HttpServer.create(PORT);
        httpServer.newHandler(adapter).block();
        isServerStarted = true;
    }
}
项目:SpringTutorial    文件:JavaConfigTestClient.java   
public static void main(String[] args) {

     AnnotationConfigApplicationContext ctx=new AnnotationConfigApplicationContext(CoreJavaConfig.class);

        Payment pmt=(Payment) ctx.getBean("dummypayment");
      pmt.pay();
      ctx.registerShutdownHook();
    }
项目:hekate    文件:SpringInjectionService.java   
@Override
public void configure(ConfigurationContext ctx) {
    // Application context for autowiring.
    AnnotationConfigApplicationContext autowireCtx = new AnnotationConfigApplicationContext() {
        @Override
        public String toString() {
            return SpringInjectionService.class.getSimpleName() + "Context";
        }
    };

    // Expose services for autowiring.
    ConfigurableListableBeanFactory factory = autowireCtx.getBeanFactory();

    uniqueServices(ctx).forEach(service -> {
        factory.registerResolvableDependency(service.getClass(), service);

        for (Class<?> type : service.getClass().getInterfaces()) {
            factory.registerResolvableDependency(type, service);
        }
    });

    autowireCtx.refresh();

    autowireCtx.setParent(parentCtx);

    autowire = autowireCtx.getAutowireCapableBeanFactory();
}
项目:hello-spring    文件:Main.java   
public static void main(String[] args) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ScopeConfig.class);
    DemoSingletonService s1 = context.getBean(DemoSingletonService.class);
    DemoSingletonService s2 = context.getBean(DemoSingletonService.class);
    DemoPrototypeService p1 = context.getBean(DemoPrototypeService.class);
    DemoPrototypeService p2 = context.getBean(DemoPrototypeService.class);

    System.out.println("s1与s2是否相等:" + s1.equals(s2));
    System.out.println("p1与p2是否相等:" + p1.equals(p2));

    context.close();
}
项目:spring-reactive-sample    文件:Application.java   
public static void main(String[] args) throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    PostRepository posts = new PostRepository();
    PostHandler postHandler = new PostHandler(posts);
    Routes routesBean = new Routes(postHandler);

    context.registerBean(PostRepository.class, () -> posts);
    context.registerBean(PostHandler.class, () -> postHandler);
    context.registerBean(Routes.class, () -> routesBean);
    context.registerBean(WebHandler.class, () -> RouterFunctions.toWebHandler(routesBean.routes(), HandlerStrategies.builder().build()));
    context.refresh();

    nettyContext(context).onClose().block();
}
项目:nixmash-blog    文件:BatchLauncher.java   
public static void main(String[] args) throws Exception {

        PropertySource commandLineProperties = new
                SimpleCommandLinePropertySource(args);

        AnnotationConfigApplicationContext context= new
                AnnotationConfigApplicationContext();

        context.getEnvironment().getPropertySources().addFirst(commandLineProperties);
        context.register(ApplicationConfiguration.class);
        context.refresh();
    }
项目:spring-reactive-sample    文件:AppIntializer.java   
@Override
protected ApplicationContext createApplicationContext() {
    Class<?>[] configClasses = getConfigClasses();
    Assert.notEmpty(configClasses, "No Spring configuration provided.");
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClasses);
    return context;
}
项目:azure-spring-boot    文件:ServiceBusPropertiesTest.java   
@Test
public void canSetQueueProperties() {
    System.setProperty(Constants.CONNECTION_STRING_PROPERTY, Constants.INVALID_CONNECTION_STRING);
    System.setProperty(Constants.QUEUE_NAME_PROPERTY, Constants.QUEUE_NAME);
    System.setProperty(Constants.QUEUE_RECEIVE_MODE_PROPERTY, Constants.QUEUE_RECEIVE_MODE.name());
    System.setProperty(Constants.TOPIC_NAME_PROPERTY, Constants.TOPIC_NAME);
    System.setProperty(Constants.SUBSCRIPTION_NAME_PROPERTY, Constants.SUBSCRIPTION_NAME);
    System.setProperty(Constants.SUBSCRIPTION_RECEIVE_MODE_PROPERTY, Constants.SUBSCRIPTION_RECEIVE_MODE.name());

    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(Config.class);
        context.refresh();
        final ServiceBusProperties properties = context.getBean(ServiceBusProperties.class);

        assertThat(properties.getConnectionString()).isEqualTo(Constants.INVALID_CONNECTION_STRING);
        assertThat(properties.getQueueName()).isEqualTo(Constants.QUEUE_NAME);
        assertThat(properties.getQueueReceiveMode()).isEqualTo(Constants.QUEUE_RECEIVE_MODE);
        assertThat(properties.getTopicName()).isEqualTo(Constants.TOPIC_NAME);
        assertThat(properties.getSubscriptionName()).isEqualTo(Constants.SUBSCRIPTION_NAME);
        assertThat(properties.getSubscriptionReceiveMode()).isEqualTo(Constants.SUBSCRIPTION_RECEIVE_MODE);
    }

    System.clearProperty(Constants.CONNECTION_STRING_PROPERTY);
    System.clearProperty(Constants.QUEUE_NAME_PROPERTY);
    System.clearProperty(Constants.QUEUE_RECEIVE_MODE_PROPERTY);
    System.clearProperty(Constants.TOPIC_NAME_PROPERTY);
    System.clearProperty(Constants.SUBSCRIPTION_NAME_PROPERTY);
    System.clearProperty(Constants.SUBSCRIPTION_RECEIVE_MODE_PROPERTY);
}
项目:spring-cloud-dashboard    文件:OnSecurityEnabledAndOAuth2EnabledTests.java   
@Test
public void both() throws Exception {
    AnnotationConfigApplicationContext context = load(Config.class,
        "security.basic.enabled:true", "security.oauth2");
    assertThat(context.containsBean("myBean"), equalTo(false));
    context.close();
}