messagebrokerbeandefinitionparsertests.java
来自「java 和flex的整合,主要是spring和flex的整合,不可多得啊」· Java 代码 · 共 323 行 · 第 1/2 页
JAVA
323 行
/* * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.springframework.flex.config.xml;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.Set;import javax.servlet.ServletConfig;import org.springframework.aop.Advisor;import org.springframework.aop.framework.Advised;import org.springframework.aop.support.AopUtils;import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.flex.config.AbstractFlexConfigurationTests;import org.springframework.flex.config.BeanIds;import org.springframework.flex.config.FlexConfigurationManager;import org.springframework.flex.config.MessageBrokerConfigProcessor;import org.springframework.flex.core.ExceptionTranslationAdvice;import org.springframework.flex.core.ExceptionTranslator;import org.springframework.flex.core.MessageInterceptionAdvice;import org.springframework.flex.core.MessageInterceptor;import org.springframework.flex.core.MessageProcessingContext;import org.springframework.flex.security.EndpointInterceptor;import org.springframework.flex.security.FlexSessionInvalidatingAuthenticationListener;import org.springframework.flex.security.SpringSecurityLoginCommand;import org.springframework.flex.servlet.MessageBrokerHandlerAdapter;import org.springframework.web.filter.RequestContextFilter;import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;import flex.messaging.MessageBroker;import flex.messaging.MessageException;import flex.messaging.config.ConfigMap;import flex.messaging.config.MessagingConfiguration;import flex.messaging.messages.Message;import flex.messaging.security.LoginCommand;import flex.messaging.services.MessageService;import flex.messaging.services.RemotingService;import flex.messaging.services.remoting.adapters.JavaAdapter;public class MessageBrokerBeanDefinitionParserTests extends AbstractFlexConfigurationTests { private MessageBroker broker; public void testMessageBroker_CustomConfigManager() { this.broker = (MessageBroker) getApplicationContext().getBean("customConfigManager", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); TestConfigurationManager configMgr = (TestConfigurationManager) getApplicationContext().getBean("configManager", TestConfigurationManager.class); assertNotNull("Custom ConfigurationManager not found"); assertTrue("The custom ConfigurationManager was not used", configMgr.invoked); } public void testMessageBroker_CustomConfigProcessor() { this.broker = (MessageBroker) getApplicationContext().getBean("customConfigProcessors", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); TestConfigProcessor processor1 = (TestConfigProcessor) getApplicationContext().getBean("processor1", TestConfigProcessor.class); TestConfigProcessor processor2 = (TestConfigProcessor) getApplicationContext().getBean("processor2", TestConfigProcessor.class); assertTrue("Processor1 not invoked", processor1.beforeProcessed && processor1.afterProcessed); assertTrue("Processor2 not invoked", processor2.beforeProcessed && processor2.afterProcessed); } @SuppressWarnings("unchecked") public void testMessageBroker_CustomExceptionTranslator() { this.broker = (MessageBroker) getApplicationContext().getBean("customExceptionTranslators", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); Iterator i = this.broker.getEndpoints().values().iterator(); while (i.hasNext()) { Object endpoint = i.next(); assertTrue("Endpoint should be proxied", AopUtils.isAopProxy(endpoint)); Advised advisedEndpoint = (Advised) endpoint; Advisor a = advisedEndpoint.getAdvisors()[0]; assertTrue("Exception translation advice was not applied", a.getAdvice() instanceof ExceptionTranslationAdvice); Set translators = ((ExceptionTranslationAdvice) a.getAdvice()).getExceptionTranslators(); assertTrue("Custom translator not found", translators.contains(getApplicationContext().getBean("translator1", TestExceptionTranslator.class))); assertTrue("Custom translator not found", translators.contains(getApplicationContext().getBean("translator2", TestExceptionTranslator.class))); } } public void testMessageBroker_CustomMappings() { this.broker = (MessageBroker) getApplicationContext().getBean("customMappings", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); SimpleUrlHandlerMapping defaultMapping = (SimpleUrlHandlerMapping) getApplicationContext().getBean("customMappingsDefaultHandlerMapping", SimpleUrlHandlerMapping.class); assertEquals(0, defaultMapping.getOrder()); assertTrue("Path mapping not correct", defaultMapping.getUrlMap().containsKey("/foo")); assertEquals("Target mapping not correct", "customMappings", defaultMapping.getUrlMap().get("/foo")); assertTrue("Path mapping not correct", defaultMapping.getUrlMap().containsKey("/bar")); assertEquals("Target mapping not correct", "customMappings", defaultMapping.getUrlMap().get("/bar")); } @SuppressWarnings("unchecked") public void testMessageBroker_CustomMessageInterceptors() { this.broker = (MessageBroker) getApplicationContext().getBean("customMessageInterceptors", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); Iterator i = this.broker.getEndpoints().values().iterator(); while (i.hasNext()) { Object endpoint = i.next(); assertTrue("Endpoint should be proxied", AopUtils.isAopProxy(endpoint)); Advised advisedEndpoint = (Advised) endpoint; Advisor a = advisedEndpoint.getAdvisors()[1]; assertTrue("Message interception advice was not applied", a.getAdvice() instanceof MessageInterceptionAdvice); Set interceptors = ((MessageInterceptionAdvice) a.getAdvice()).getMessageInterceptors(); assertTrue("Custom interceptor not found", interceptors.contains(getApplicationContext().getBean("interceptor1", TestMessageInterceptor.class))); assertTrue("Custom interceptor not found", interceptors.contains(getApplicationContext().getBean("interceptor2", TestMessageInterceptor.class))); } } @SuppressWarnings("unchecked") public void testMessageBroker_CustomMessageService() { this.broker = (MessageBroker) getApplicationContext().getBean("customMessageService", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); MessageService messageService = (MessageService) this.broker.getServiceByType(MessageService.class.getName()); assertNotNull("MessageService not found", messageService); String defaultAdapterId = messageService.getDefaultAdapter(); assertEquals("Default adapter id not set on MessageService", "my-default-adapter", defaultAdapterId); List expectedChannels = new ArrayList(); expectedChannels.add("my-polling-amf"); expectedChannels.add("my-secure-amf"); assertEquals("Default channels not set", expectedChannels, messageService.getDefaultChannels()); } @SuppressWarnings("unchecked") public void testMessageBroker_CustomRemotingService() { this.broker = (MessageBroker) getApplicationContext().getBean("customRemotingService", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); RemotingService remotingService = (RemotingService) this.broker.getServiceByType(RemotingService.class.getName()); assertNotNull("RemotingService not found", remotingService); String defaultAdapterId = remotingService.getDefaultAdapter(); assertEquals("Default adapter id not set on RemotingService", "my-default-adapter", defaultAdapterId); List expectedChannels = new ArrayList(); expectedChannels.add("my-amf"); expectedChannels.add("my-secure-amf"); assertEquals("Default channels not set", expectedChannels, remotingService.getDefaultChannels()); TestJavaAdapter adapter = (TestJavaAdapter) getApplicationContext().getBean(defaultAdapterId, TestJavaAdapter.class); assertTrue(adapter.initialized); } public void testMessageBroker_CustomServicesConfigPath() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?