loginmessageinterceptortests.java

来自「java 和flex的整合,主要是spring和flex的整合,不可多得啊」· Java 代码 · 共 81 行

JAVA
81
字号
/* * 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.security;import java.util.Map;import junit.framework.TestCase;import org.mockito.MockitoAnnotations;import org.springframework.security.Authentication;import org.springframework.security.GrantedAuthority;import org.springframework.security.GrantedAuthorityImpl;import org.springframework.security.context.SecurityContextHolder;import org.springframework.security.providers.UsernamePasswordAuthenticationToken;import flex.messaging.messages.AcknowledgeMessage;import flex.messaging.messages.CommandMessage;import flex.messaging.messages.Message;public class LoginMessageInterceptorTests extends TestCase {    private CommandMessage inputMessage;    private AcknowledgeMessage outputMessage;    private LoginMessageInterceptor interceptor;    public final void testPostProcessPassThrough() {        this.inputMessage = new CommandMessage(CommandMessage.CLIENT_PING_OPERATION);        this.outputMessage = new AcknowledgeMessage();        assertSame(this.outputMessage, this.interceptor.postProcess(null, this.inputMessage, this.outputMessage));    }    @SuppressWarnings("unchecked")    public final void testPostProcessSuccessfulLogin() {        Authentication auth = new UsernamePasswordAuthenticationToken("foo", "bar", new GrantedAuthority[] { new GrantedAuthorityImpl("ROLE_USER") });        SecurityContextHolder.getContext().setAuthentication(auth);        this.inputMessage = new CommandMessage(CommandMessage.LOGIN_OPERATION);        this.outputMessage = new AcknowledgeMessage();        this.outputMessage.setBody("success");        Message result = this.interceptor.postProcess(null, this.inputMessage, this.outputMessage);        assertTrue(result.getBody() instanceof Map);        Map authResult = (Map) result.getBody();        assertEquals("foo", authResult.get("name"));        assertEquals("ROLE_USER", ((String[]) authResult.get("authorities"))[0]);    }    public final void testPreProcessPassThrough() {        this.inputMessage = new CommandMessage(CommandMessage.LOGIN_OPERATION);        assertSame(this.inputMessage, this.interceptor.preProcess(null, this.inputMessage));    }    @Override    protected void setUp() throws Exception {        MockitoAnnotations.initMocks(this);        this.interceptor = new LoginMessageInterceptor();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?