Java 类org.springframework.context.support.StaticApplicationContext 实例源码

项目:summer-mqtt    文件:AutomaticReconnectTest.java   
@Test
public void testGoodConnection() throws MqttException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
        null);
    service.setApplicationEventPublisher(applicationContext);
    service.setInboundMessageChannel(inboundMessageChannel);
    service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
        MqttQualityOfService.QOS_0);
    service.getMqttConnectOptions().setCleanSession(true);
    Assert.assertTrue(service.start());
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Assert.assertEquals(1, clientConnectedCount.get());
    Assert.assertEquals(0, clientDisconnectedCount.get());
    Assert.assertEquals(0, clientLostConnectionCount.get());
    Assert.assertEquals(0, clientFailedConnectionCount.get());
    service.stop();
    service.close();
    applicationContext.close();
}
项目:summer-mqtt    文件:ConnectionStatusTest.java   
@Test
public void testWithDefaultStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(0, messageDeliveredCount.get());
    Assert.assertEquals(0, messagePublishedCount.get());
    service.stop();
    service.close();
}
项目:summer-mqtt    文件:ConnectionStatusTest.java   
@Test
public void testWithNullStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.getMqttClientConfiguration().setMqttClientConnectionStatusPublisher(null);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(0, messageDeliveredCount.get());
    Assert.assertEquals(0, messagePublishedCount.get());
    service.stop();
    service.close();
}
项目:summer-mqtt    文件:ConnectionStatusTest.java   
@Test
public void testWithCustomStatusPublisher() throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getBrokerUri(), BrokerHelper.getClientId(),
        MqttClientConnectionType.PUBSUB, null);
    service.setApplicationEventPublisher(applicationContext);
    service.getMqttClientConfiguration().setMqttClientConnectionStatusPublisher(this);
    service.start();
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Thread.sleep(1100);
    Assert.assertEquals(1, messageDeliveredCount.get());
    Assert.assertEquals(1, messagePublishedCount.get());
    service.stop();
    Thread.sleep(1100);
    Assert.assertEquals(2, messageDeliveredCount.get());
    Assert.assertEquals(2, messagePublishedCount.get());
    service.close();
}
项目:spring4-understanding    文件:AsyncAnnotationBeanPostProcessorTests.java   
@Test
public void taskExecutorByBeanType() {
    StaticApplicationContext context = new StaticApplicationContext();

    BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
    context.registerBeanDefinition("postProcessor", processorDefinition);

    BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
    executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
    context.registerBeanDefinition("myExecutor", executorDefinition);

    BeanDefinition targetDefinition =
            new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
    context.registerBeanDefinition("target", targetDefinition);

    context.refresh();

    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertTrue(asyncThread.getName().startsWith("testExecutor"));
    context.close();
}
项目:spring-boot-concourse    文件:RequestMappingEndpointTests.java   
@Test
public void beanMethodMappings() {
    StaticApplicationContext context = new StaticApplicationContext();
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(
            Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
    this.endpoint.setApplicationContext(context);
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked")
    Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
            .next();
    assertThat(handler.containsKey("method")).isTrue();
}
项目:spring4-understanding    文件:GroovyClassLoadingTests.java   
@Test
@SuppressWarnings("resource")
public void classLoading() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();

    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> class1 = gcl.parseClass("class TestBean { def myMethod() { \"foo\" } }");
    Class<?> class2 = gcl.parseClass("class TestBean { def myMethod() { \"bar\" } }");

    context.registerBeanDefinition("testBean", new RootBeanDefinition(class1));
    Object testBean1 = context.getBean("testBean");
    Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
    Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
    assertEquals("foo", result1);

    context.removeBeanDefinition("testBean");
    context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
    Object testBean2 = context.getBean("testBean");
    Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
    Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
    assertEquals("bar", result2);
}
项目:spring4-understanding    文件:ApplicationContextEventTests.java   
@Test
public void simpleApplicationEventMulticasterWithTaskExecutor() {
    @SuppressWarnings("unchecked")
    ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
    ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());

    SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
    smc.setTaskExecutor(new Executor() {
        @Override
        public void execute(Runnable command) {
            command.run();
            command.run();
        }
    });
    smc.addApplicationListener(listener);

    smc.multicastEvent(evt);
    verify(listener, times(2)).onApplicationEvent(evt);
}
项目:spring4-understanding    文件:ApplicationContextEventTests.java   
@Test
public void simpleApplicationEventMulticasterWithException() {
    @SuppressWarnings("unchecked")
    ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
    ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());

    SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
    smc.addApplicationListener(listener);

    RuntimeException thrown = new RuntimeException();
    willThrow(thrown).given(listener).onApplicationEvent(evt);
    try {
        smc.multicastEvent(evt);
        fail("Should have thrown RuntimeException");
    }
    catch (RuntimeException ex) {
        assertSame(thrown, ex);
    }
}
项目:spring4-understanding    文件:ApplicationContextEventTests.java   
@Test
public void listenersInApplicationContextWithPayloadEvents() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("listener", new RootBeanDefinition(MyPayloadListener.class));
    context.refresh();

    MyPayloadListener listener = context.getBean("listener", MyPayloadListener.class);
    context.publishEvent("event1");
    context.publishEvent("event2");
    context.publishEvent("event3");
    context.publishEvent("event4");
    assertTrue(listener.seenPayloads.contains("event1"));
    assertTrue(listener.seenPayloads.contains("event2"));
    assertTrue(listener.seenPayloads.contains("event3"));
    assertTrue(listener.seenPayloads.contains("event4"));

    AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
    assertEquals(2, multicaster.retrieverCache.size());

    context.close();
}
项目:spring4-understanding    文件:ApplicationContextEventTests.java   
@Test
public void listenersInApplicationContextWithNestedChild() {
    StaticApplicationContext context = new StaticApplicationContext();
    RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
    nestedChild.getPropertyValues().add("parent", context);
    nestedChild.setInitMethodName("refresh");
    context.registerBeanDefinition("nestedChild", nestedChild);
    RootBeanDefinition listener1Def = new RootBeanDefinition(MyOrderedListener1.class);
    listener1Def.setDependsOn("nestedChild");
    context.registerBeanDefinition("listener1", listener1Def);
    context.refresh();

    MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
    MyEvent event1 = new MyEvent(context);
    context.publishEvent(event1);
    assertTrue(listener1.seenEvents.contains(event1));

    SimpleApplicationEventMulticaster multicaster = context.getBean(
            AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
            SimpleApplicationEventMulticaster.class);
    assertFalse(multicaster.getApplicationListeners().isEmpty());

    context.close();
    assertTrue(multicaster.getApplicationListeners().isEmpty());
}
项目:spring4-understanding    文件:ApplicationContextEventTests.java   
@Test
public void nonSingletonListenerInApplicationContext() {
    StaticApplicationContext context = new StaticApplicationContext();
    RootBeanDefinition listener = new RootBeanDefinition(MyNonSingletonListener.class);
    listener.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    context.registerBeanDefinition("listener", listener);
    context.refresh();

    MyEvent event1 = new MyEvent(context);
    context.publishEvent(event1);
    MyOtherEvent event2 = new MyOtherEvent(context);
    context.publishEvent(event2);
    MyEvent event3 = new MyEvent(context);
    context.publishEvent(event3);
    MyOtherEvent event4 = new MyOtherEvent(context);
    context.publishEvent(event4);
    assertTrue(MyNonSingletonListener.seenEvents.contains(event1));
    assertTrue(MyNonSingletonListener.seenEvents.contains(event2));
    assertTrue(MyNonSingletonListener.seenEvents.contains(event3));
    assertTrue(MyNonSingletonListener.seenEvents.contains(event4));
    MyNonSingletonListener.seenEvents.clear();

    context.close();
}
项目:spring4-understanding    文件:LifecycleEventTests.java   
@Test
public void contextStoppedEvent() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerSingleton("lifecycle", LifecycleTestBean.class);
    context.registerSingleton("listener", LifecycleListener.class);
    context.refresh();
    LifecycleTestBean lifecycleBean = (LifecycleTestBean) context.getBean("lifecycle");
    LifecycleListener listener = (LifecycleListener) context.getBean("listener");
    assertFalse(lifecycleBean.isRunning());
    context.start();
    assertTrue(lifecycleBean.isRunning());
    assertEquals(0, listener.getStoppedCount());
    context.stop();
    assertFalse(lifecycleBean.isRunning());
    assertEquals(1, listener.getStoppedCount());
    assertSame(context, listener.getApplicationContext());
}
项目:spring4-understanding    文件:QualifierAnnotationTests.java   
@Test
public void testQualifiedByParentValue() {
    StaticApplicationContext parent = new StaticApplicationContext();
    GenericBeanDefinition parentLarry = new GenericBeanDefinition();
    parentLarry.setBeanClass(Person.class);
    parentLarry.getPropertyValues().add("name", "ParentLarry");
    parentLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "parentLarry"));
    parent.registerBeanDefinition("someLarry", parentLarry);
    GenericBeanDefinition otherLarry = new GenericBeanDefinition();
    otherLarry.setBeanClass(Person.class);
    otherLarry.getPropertyValues().add("name", "OtherLarry");
    otherLarry.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "otherLarry"));
    parent.registerBeanDefinition("someOtherLarry", otherLarry);
    parent.refresh();

    StaticApplicationContext context = new StaticApplicationContext(parent);
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    context.registerSingleton("testBean", QualifiedByParentValueTestBean.class);
    context.refresh();
    QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
    Person person = testBean.getLarry();
    assertEquals("ParentLarry", person.getName());
}
项目:spring4-understanding    文件:QualifierAnnotationTests.java   
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(CONFIG_LOCATION);
    QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
            context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
    resolver.addQualifierType(MultipleAttributeQualifier.class);
    context.registerSingleton("testBean", MultiQualifierClient.class);
    context.refresh();

    MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");

    assertNotNull( testBean.factoryTheta);
    assertNotNull( testBean.implTheta);
}
项目:spring4-understanding    文件:AutoProxyCreatorTests.java   
@Test
public void testAutoProxyCreatorWithFactoryBean() {
    StaticApplicationContext sac = new StaticApplicationContext();
    sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
    sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class);
    sac.refresh();

    TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
    tapc.testInterceptor.nrOfInvocations = 0;

    FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
    assertTrue(AopUtils.isCglibProxy(factory));

    TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
    assertTrue(AopUtils.isCglibProxy(tb));
    assertEquals(2, tapc.testInterceptor.nrOfInvocations);
    tb.getAge();
    assertEquals(3, tapc.testInterceptor.nrOfInvocations);
}
项目:spring4-understanding    文件:AutoProxyCreatorTests.java   
@Test
public void testAutoProxyCreatorWithFactoryBeanAndPrototype() {
    StaticApplicationContext sac = new StaticApplicationContext();
    sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("singleton", "false");
    sac.registerSingleton("prototypeFactoryToBeProxied", DummyFactory.class, pvs);

    sac.refresh();

    TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
    tapc.testInterceptor.nrOfInvocations = 0;

    FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
    assertTrue(AopUtils.isCglibProxy(prototypeFactory));
    TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
    assertTrue(AopUtils.isCglibProxy(tb));

    assertEquals(2, tapc.testInterceptor.nrOfInvocations);
    tb.getAge();
    assertEquals(3, tapc.testInterceptor.nrOfInvocations);
}
项目:spring4-understanding    文件:XsltViewResolverTests.java   
@Test
public void resolveView() throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();

    String prefix = ClassUtils.classPackageAsResourcePath(getClass());
    String suffix = ".xsl";
    String viewName = "products";

    XsltViewResolver viewResolver = new XsltViewResolver();
    viewResolver.setPrefix(prefix);
    viewResolver.setSuffix(suffix);
    viewResolver.setApplicationContext(ctx);

    XsltView view = (XsltView) viewResolver.resolveViewName(viewName, Locale.ENGLISH);
    assertNotNull("View should not be null", view);
    assertEquals("Incorrect URL", prefix + viewName + suffix, view.getUrl());
}
项目:spring-boot-concourse    文件:RequestMappingEndpointTests.java   
@Test
public void concreteMethodMappings() {
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(
            Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    this.endpoint.setMethodMappings(
            Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping));
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked")
    Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
            .next();
    assertThat(handler.containsKey("method")).isTrue();
}
项目:spring4-understanding    文件:JasperReportViewResolverTests.java   
@Test
public void resolveView() throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();

    String prefix = "org/springframework/ui/jasperreports/";
    String suffix = ".jasper";
    String viewName = "DataSourceReport";

    JasperReportsViewResolver viewResolver = new JasperReportsViewResolver();
    viewResolver.setViewClass(JasperReportsHtmlView.class);
    viewResolver.setPrefix(prefix);
    viewResolver.setSuffix(suffix);
    viewResolver.setApplicationContext(ctx);

    AbstractJasperReportsView view = (AbstractJasperReportsView) viewResolver.resolveViewName(viewName,
        Locale.ENGLISH);
    assertNotNull("View should not be null", view);
    assertEquals("Incorrect URL", prefix + viewName + suffix, view.getUrl());
}
项目:spring4-understanding    文件:JasperReportViewResolverTests.java   
private void doViewNamesTest(String... viewNames) throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();

    String prefix = "org/springframework/ui/jasperreports/";
    String suffix = ".jasper";
    String viewName = "DataSourceReport";

    JasperReportsViewResolver viewResolver = new JasperReportsViewResolver();
    viewResolver.setViewClass(JasperReportsHtmlView.class);
    viewResolver.setPrefix(prefix);
    viewResolver.setSuffix(suffix);
    viewResolver.setViewNames(viewNames);
    viewResolver.setApplicationContext(ctx);

    AbstractJasperReportsView view = (AbstractJasperReportsView) viewResolver.resolveViewName(viewName,
        Locale.ENGLISH);
    assertNotNull("View should not be null", view);
    assertEquals("Incorrect URL", prefix + viewName + suffix, view.getUrl());
    assertNull(viewResolver.resolveViewName("foo", Locale.ENGLISH));
}
项目:spring4-understanding    文件:SimpleUrlHandlerMappingTests.java   
@Test
public void testNewlineInRequest() throws Exception {
    SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
    handlerMapping.setUrlDecode(false);
    Object controller = new Object();
    Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
    urlMap.put("/*/baz", controller);
    handlerMapping.setUrlMap(urlMap);
    handlerMapping.setApplicationContext(new StaticApplicationContext());

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo%0a%0dbar/baz");

    HandlerExecutionChain hec = handlerMapping.getHandler(request);
    assertNotNull(hec);
    assertSame(controller, hec.getHandler());
}
项目:spring4-understanding    文件:HandlerMethodMappingTests.java   
@Test
public void detectHandlerMethodsInAncestorContexts() {
    StaticApplicationContext cxt = new StaticApplicationContext();
    cxt.registerSingleton("myHandler", MyHandler.class);

    AbstractHandlerMethodMapping<String> mapping1 = new MyHandlerMethodMapping();
    mapping1.setApplicationContext(new StaticApplicationContext(cxt));
    mapping1.afterPropertiesSet();

    assertEquals(0, mapping1.getHandlerMethods().size());

    AbstractHandlerMethodMapping<String> mapping2 = new MyHandlerMethodMapping();
    mapping2.setDetectHandlerMethodsInAncestorContexts(true);
    mapping2.setApplicationContext(new StaticApplicationContext(cxt));
    mapping2.afterPropertiesSet();

    assertEquals(2, mapping2.getHandlerMethods().size());
}
项目:spring4-understanding    文件:DefaultMockMvcBuilderTests.java   
/**
 * See SPR-12553 and SPR-13075.
 */
@Test
public void rootWacServletContainerAttributeNotPreviouslySetWithContextHierarchy() {
    StaticApplicationContext ear = new StaticApplicationContext();
    StaticWebApplicationContext root = new StaticWebApplicationContext();
    root.setParent(ear);
    root.setServletContext(this.servletContext);
    StaticWebApplicationContext dispatcher = new StaticWebApplicationContext();
    dispatcher.setParent(root);
    dispatcher.setServletContext(this.servletContext);

    DefaultMockMvcBuilder builder = webAppContextSetup(dispatcher);
    WebApplicationContext wac = builder.initWebAppContext();

    assertSame(dispatcher, wac);
    assertSame(root, wac.getParent());
    assertSame(ear, wac.getParent().getParent());
    assertSame(root, WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RequestMappingEndpointTests.java   
@Test
public void beanMethodMappings() {
    StaticApplicationContext context = new StaticApplicationContext();
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(
            Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    context.getDefaultListableBeanFactory().registerSingleton("mapping", mapping);
    this.endpoint.setApplicationContext(context);
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked")
    Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
            .next();
    assertThat(handler.containsKey("method")).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RequestMappingEndpointTests.java   
@Test
public void concreteMethodMappings() {
    EndpointHandlerMapping mapping = new EndpointHandlerMapping(
            Arrays.asList(new EndpointMvcAdapter(new DumpEndpoint())));
    mapping.setApplicationContext(new StaticApplicationContext());
    mapping.afterPropertiesSet();
    this.endpoint.setMethodMappings(
            Collections.<AbstractHandlerMethodMapping<?>>singletonList(mapping));
    Map<String, Object> result = this.endpoint.invoke();
    assertThat(result).hasSize(1);
    assertThat(result.keySet().iterator().next().contains("/dump")).isTrue();
    @SuppressWarnings("unchecked")
    Map<String, Object> handler = (Map<String, Object>) result.values().iterator()
            .next();
    assertThat(handler.containsKey("method")).isTrue();
}
项目:springboot-shiro-cas-mybatis    文件:AbstractServiceValidateControllerTests.java   
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    this.serviceValidateController.setAuthenticationSystemSupport(getAuthenticationSystemSupport());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClientFactoryBean().getObject());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(getArgumentExtractor());
    this.serviceValidateController.setServicesManager(getServicesManager());
}
项目:springboot-shiro-cas-mybatis    文件:ProxyControllerTests.java   
@Before
public void onSetUp() throws Exception {
    this.proxyController = new ProxyController();
    this.proxyController
    .setCentralAuthenticationService(getCentralAuthenticationService());

    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.proxyController.setApplicationContext(context);
}
项目:springboot-shiro-cas-mybatis    文件:AbstractServiceValidateControllerTests.java   
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClientFactoryBean().getObject());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
    this.serviceValidateController.setServicesManager(this.servicesManager);
}
项目:springboot-shiro-cas-mybatis    文件:ProxyControllerTests.java   
@Before
public void onSetUp() throws Exception {
    this.proxyController = new ProxyController();
    this.proxyController
    .setCentralAuthenticationService(getCentralAuthenticationService());

    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.proxyController.setApplicationContext(context);
}
项目:cas-5.1.0    文件:AbstractServiceValidateControllerTests.java   
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    this.serviceValidateController.setAuthenticationSystemSupport(getAuthenticationSystemSupport());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler(new SimpleHttpClientFactoryBean().getObject(), new DefaultUniqueTicketIdGenerator());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(getArgumentExtractor());
    this.serviceValidateController.setServicesManager(getServicesManager());
    this.serviceValidateController.setValidationSpecification(new Cas20WithoutProxyingValidationSpecification());
    this.serviceValidateController.setMultifactorTriggerSelectionStrategy(new DefaultMultifactorTriggerSelectionStrategy("", ""));
}
项目:cas-5.1.0    文件:ProxyControllerTests.java   
@Before
public void onSetUp() throws Exception {
    this.proxyController = new ProxyController(getCentralAuthenticationService(), getWebApplicationServiceFactory());
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.proxyController.setApplicationContext(context);
}
项目:alfresco-repository    文件:ChainingUserRegistrySynchronizerTest.java   
/**
 * Sets the user registries.
 * 
 * @param registries
 *            the new user registries
 */
public void setUserRegistries(IMockUserRegistry... registries)
{
    this.contexts = new LinkedHashMap<String, ApplicationContext>(registries.length * 2);
    for (IMockUserRegistry registry : registries)
    {
        StaticApplicationContext context = new StaticApplicationContext();
        context.getDefaultListableBeanFactory().registerSingleton("userRegistry", registry);
        this.contexts.put(registry.getZoneId(), context);
    }
}
项目:cas4.0.x-server-wechat    文件:ProxyControllerTests.java   
@Before
public void onSetUp() throws Exception {
    this.proxyController = new ProxyController();
    this.proxyController
    .setCentralAuthenticationService(getCentralAuthenticationService());

    StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.proxyController.setApplicationContext(context);
}
项目:cas4.0.x-server-wechat    文件:ServiceValidateControllerTests.java   
@Before
public void onSetUp() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClient());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
}
项目:nixmash-blog    文件:SolrProductControllerTests.java   
@Before
public void setUp() throws GeoLocationException {

    final ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver();
    final StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerBeanDefinition("solrController",
            new RootBeanDefinition(SolrController.class, null, null));
    exceptionResolver.setApplicationContext(applicationContext);
    exceptionResolver.afterPropertiesSet();

    mockProductService = mock(ProductService.class);

    String badLocation = "35.453487-97.5184727";
    when(mockProductService.getProductsByLocation(badLocation)).thenThrow(new GeoLocationException());

    solrController = new SolrController(mockProductService);
    mockMvc = MockMvcBuilders.standaloneSetup(solrController)
            .setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
            .setHandlerExceptionResolvers(exceptionResolver).build();

    product = createProduct(1000);
    when(mockProductService.getProduct(PRODUCT_ID)).thenReturn(product);

    allProducts = createProductList(10);
    when(mockProductService.getProducts()).thenReturn(allProducts);

}
项目:cas-server-4.2.1    文件:AbstractServiceValidateControllerTests.java   
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    this.serviceValidateController.setAuthenticationSystemSupport(getAuthenticationSystemSupport());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClientFactoryBean().getObject());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(getArgumentExtractor());
    this.serviceValidateController.setServicesManager(getServicesManager());
}
项目:cas-server-4.2.1    文件:ProxyControllerTests.java   
@Before
public void onSetUp() throws Exception {
    this.proxyController = new ProxyController();
    this.proxyController
    .setCentralAuthenticationService(getCentralAuthenticationService());

    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.proxyController.setApplicationContext(context);
}
项目:summer-mqtt    文件:AutomaticReconnectTest.java   
private StaticApplicationContext getStaticApplicationContext()
{
    clientConnectedCount.set(0);
    clientDisconnectedCount.set(0);
    clientLostConnectionCount.set(0);
    clientFailedConnectionCount.set(0);
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.addApplicationListener(this);
    applicationContext.refresh();
    applicationContext.start();
    return applicationContext;
}
项目:summer-mqtt    文件:AutomaticReconnectTest.java   
@Test
public void testMqttConnectOptionsAutomaticReconnectDefaultServerAvailableAtStartup()
    throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
        null);
    service.setApplicationEventPublisher(applicationContext);
    service.setInboundMessageChannel(inboundMessageChannel);
    service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
        MqttQualityOfService.QOS_0);
    service.getMqttConnectOptions().setCleanSession(true);
    Assert.assertTrue(service.start());
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    // simulate a lost connection
    CRUSHER_PROXY.reopen();
    Assert.assertFalse(service.isStarted());
    Assert.assertFalse(service.isConnected());
    Thread.sleep(1000);
    Assert.assertFalse(service.isStarted());
    Assert.assertFalse(service.isConnected());
    Assert.assertEquals(1, clientConnectedCount.get());
    Assert.assertEquals(0, clientDisconnectedCount.get());
    Assert.assertEquals(1, clientLostConnectionCount.get());
    Assert.assertEquals(0, clientFailedConnectionCount.get());
    service.stop();
    service.close();
    applicationContext.close();
}