messagebrokerbeandefinitionparsertests.java
来自「java 和flex的整合,主要是spring和flex的整合,不可多得啊」· Java 代码 · 共 323 行 · 第 1/2 页
JAVA
323 行
this.broker = (MessageBroker) getApplicationContext().getBean("customServicesConfigPath", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); assertTrue("Custom configuration was not read", this.broker.getChannelIds().contains("my-custom-path-channel")); } @SuppressWarnings("unchecked") public void testMessageBroker_DefaultSecured() { this.broker = (MessageBroker) getApplicationContext().getBean("defaultSecured", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); LoginCommand loginCommand = this.broker.getLoginManager().getLoginCommand(); assertNotNull("LoginCommand not found", loginCommand); assertTrue("LoginCommand of wrong type", loginCommand instanceof SpringSecurityLoginCommand); assertSame("LoginCommand not a managed spring bean", loginCommand, getApplicationContext().getBean("defaultSecuredLoginCommand")); 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); a = advisedEndpoint.getAdvisors()[1]; assertTrue("Message interception advice was not applied", a.getAdvice() instanceof MessageInterceptionAdvice); } getApplicationContext().getBean(BeanIds.FLEX_SESSION_AUTHENTICATION_LISTENER, FlexSessionInvalidatingAuthenticationListener.class); getApplicationContext().getBean(BeanIds.REQUEST_CONTEXT_FILTER, RequestContextFilter.class); } public void testMessageBroker_DisabledHandlerMapping() { this.broker = (MessageBroker) getApplicationContext().getBean("disabledHandlerMapping", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); assertFalse("Default handler mapping not disabled", getApplicationContext().containsBean("disabledHandlerMappingDefaultHandlerMapping")); } @SuppressWarnings("unchecked") public void testMessageBroker_EndpointSecured() { this.broker = (MessageBroker) getApplicationContext().getBean("endpointSecured", 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("MessageInterception advice was not applied", a.getAdvice() instanceof MessageInterceptionAdvice); Iterator<MessageInterceptor> m = ((MessageInterceptionAdvice) a.getAdvice()).getMessageInterceptors().iterator(); while (m.hasNext()) { MessageInterceptor interceptor = m.next(); if (interceptor instanceof EndpointInterceptor) { Collection definitions = ((EndpointInterceptor) interceptor).getObjectDefinitionSource().getConfigAttributeDefinitions(); assertEquals("Incorrect number of EnpointDefinitionSource instances", 3, definitions.size()); } } } } public void testMessageBroker_InvalidConfig() { try { new ClassPathXmlApplicationContext("org/springframework/flex/config/invalid-message-broker.xml"); fail("Invalid message-broker config was not caught"); } catch (BeanDefinitionParsingException ex) { // Expected } } @SuppressWarnings("unchecked") public void testMessageBroker_LoginCommandConfigured() { this.broker = (MessageBroker) getApplicationContext().getBean("loginCommandConfigured", MessageBroker.class); assertNotNull("MessageBroker bean not found for custom id", this.broker); SpringSecurityLoginCommand loginCommand = (SpringSecurityLoginCommand) this.broker.getLoginManager().getLoginCommand(); assertNotNull("LoginCommand not found", loginCommand); assertTrue("perClientAuthentication not configured", loginCommand.isPerClientAuthentication()); 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); } } public void testMessageBrokerDefaultConfig() { this.broker = (MessageBroker) getApplicationContext().getBean(BeanIds.MESSAGE_BROKER, MessageBroker.class); assertNotNull("MessageBroker bean not found for default ID", this.broker); assertTrue("MessageBroker should be started", this.broker.isStarted()); assertNotNull("MessageBroker should have a RemotingService", this.broker.getServiceByType(RemotingService.class.getName())); assertNotNull("MessageBrokerHandlerAdapter not found", getApplicationContext().getBean(BeanIds.MESSAGE_BROKER_HANDLER_ADAPTER, MessageBrokerHandlerAdapter.class)); SimpleUrlHandlerMapping defaultMapping = (SimpleUrlHandlerMapping) getApplicationContext().getBean( BeanIds.MESSAGE_BROKER + "DefaultHandlerMapping", SimpleUrlHandlerMapping.class); assertTrue("Default mapping not correct", defaultMapping.getUrlMap().containsKey("/*")); assertEquals("Default mapping not correct", BeanIds.MESSAGE_BROKER, defaultMapping.getUrlMap().get("/*")); } public static final class TestConfigProcessor implements MessageBrokerConfigProcessor { protected boolean afterProcessed = false; protected boolean beforeProcessed = false; public MessageBroker processAfterStartup(MessageBroker broker) { this.afterProcessed = true; return broker; } public MessageBroker processBeforeStartup(MessageBroker broker) { this.beforeProcessed = true; return broker; } } public static final class TestConfigurationManager extends FlexConfigurationManager { protected boolean invoked = false; @Override public MessagingConfiguration getMessagingConfiguration(ServletConfig servletConfig) { this.invoked = true; return super.getMessagingConfiguration(servletConfig); } } public static final class TestExceptionTranslator implements ExceptionTranslator { public boolean handles(Class<?> clazz) { return false; } public MessageException translate(Throwable t) { return null; } } public static final class TestJavaAdapter extends JavaAdapter { protected boolean initialized = false; @Override public void initialize(String id, ConfigMap properties) { ConfigMap foo = properties.getPropertyAsMap("foo", null); assertNotNull(foo); assertTrue(foo.getPropertyAsBoolean("bar", false)); assertEquals("moo", foo.getProperty("baz")); this.initialized = true; } } public static final class TestMessageInterceptor implements MessageInterceptor { public Message postProcess(MessageProcessingContext context, Message inputMessage, Message outputMessage) { return null; } public Message preProcess(MessageProcessingContext context, Message inputMessage) { return null; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?