亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testcmsflexresponse.java

?? cms是開源的框架
?? JAVA
字號:
/*
 * File   : $Source: /usr/local/cvs/opencms/test/org/opencms/flex/TestCmsFlexResponse.java,v $
 * Date   : $Date: 2005/09/11 13:27:06 $
 * Version: $Revision: 1.1 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.flex;

import org.opencms.file.CmsObject;
import org.opencms.main.OpenCms;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.util.CmsRequestUtil;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.extensions.TestSetup;
import junit.framework.TestSuite;

/** 
 * Unit tests for the {@link CmsFlexResponse}.<p> 
 * 
 * This test suite performs way more set-up than is required for the amount of testing that is done.
 * However, there is probably value in demonstrating how to set up a test case to access flex cache resources
 * so that more robust unit tests can be developed here.<p>
 * 
 * @author Jason Trump
 *  
 * @version $Revision: 1.1 $
 * 
 * @since 6.0.1
 */
public class TestCmsFlexResponse extends OpenCmsTestCase {

    /**
     * An InvocationHandler which simply records the arguments for each method that was called.<p>
     * 
     * If a 'stub' object was passed in the contructor, and the stub object has a method of the
     * same signature as the one that is being called, that method will be invoked.<p>
     */
    public static class RecordingMock implements InvocationHandler {

        /** Maps {@link Method} to a {@link List} of arguments passed to each invocation of that method handled by this object. */
        HashMap m_invocations = new HashMap();
        
        /** If non-null, delegate method invocations to this object when possible. */
        Object m_stub;

        /**
         * Default empty construtor.<p>
         */
        public RecordingMock() {
            // noop
        }

        /**
         * Construtor with a 'stub' Object.<p>
         * 
         * @param stub the stub Object to use
         */
        public RecordingMock(Object stub) {

            m_stub = stub;
        }

        /** 
         * Returns a list of all recorded calls to the given method.<p>
         * 
         * @param method the method to get the recorded calls for
         * 
         * @return a list of all recorded calls to the given method
         */
        public List getCalls(Method method) {

            ArrayList calls = (ArrayList)m_invocations.get(method);
            if (calls == null) {
                calls = new ArrayList();
                m_invocations.put(method, calls);
            }
            return calls;
        }


        /**
         * Notice that the given method has been invoked.<p>
         * 
         * Two actions are taken:
         * <ol>
         * <li>The invocation is recorded in <code>{@link #getCalls getCalls(method)}</code>.</li>
         * <li>If {@link #m_stub} is not null, the requested method is invoked on it</li>
         * </ol>
         * 
         * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
         */
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

            // record the invocation
            getCalls(method).add(args);
            
            // check to see if our stub object supports this method.
            if (m_stub != null) {
                Method stubMethod = null;
                try {
                    stubMethod = m_stub.getClass().getMethod(method.getName(), method.getParameterTypes());
                    if (stubMethod != null) {
                        if (stubMethod.getReturnType() == null) {
                            if (method.getReturnType() != null) {
                                stubMethod = null;
                            }
                        } else if (!stubMethod.getReturnType().equals(method.getReturnType())) {
                            stubMethod = null;
                        }
                    }
                } catch (NoSuchMethodException e) {
                    // ignore
                } catch (SecurityException e) {
                    // ignore
                }

                // if stubMethod is not null, then stub object has a public method with the requested signature
                if (stubMethod != null) {
                    return stubMethod.invoke(m_stub, args);
                }
            }

            return null;
        }
    }
    
    /** 
     * A partial implementation of {@link HttpServletRequest} which allows for the setting and getting of request attributes.<p>
     */
    public static class RequestStub {

        /** Attribute map. */
        HashMap m_attributes = new HashMap();

        /**
         * Returns the named attribute value.<p>
         * 
         * @param name the name of the attribute to return
         * @return the value of the attribute
         */
        public Object getAttribute(String name) {

            return m_attributes.get(name);
        }

        /**
         * Removes the named attribute.<p>
         * 
         * @param name the name of the attribute to remove
         */
        public void removeAttribute(String name) {

            m_attributes.remove(name);
        }

        /**
         * Sets the named attribute to the given value.<p>
         * 
         * @param name the name of the attribute to set
         * @param value the value to set
         */
        public void setAttribute(String name, Object value) {

            m_attributes.put(name, value);
        }
    }

    /** Method for setContentType(String) from the HttpServletResponse class. */
    public static Method SET_CONTENT_TYPE = null;
    
    /** Flex controller to be used by the tests. */
    private CmsFlexController m_controller;
    
    /** Request mockup object. */
    private RecordingMock m_reqMock;
    
    /** Response mockup object. */
    private RecordingMock m_resMock;
    
    /** Servlet request to use with the tests. */
    private HttpServletRequest m_request;

    /** Servlet response to use with the tests. */
    private HttpServletResponse m_response;

    /**
     * Default JUnit constructor.<p>
     * 
     * @param arg0 JUnit parameters
     */
    public TestCmsFlexResponse(String arg0) {

        super(arg0);
    }

    /**
     * Static initializer for this test case.<p>
     */
    static {
        try {
            SET_CONTENT_TYPE = HttpServletResponse.class.getMethod("setContentType", new Class[] {String.class});
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("HttpServletResponse linkage error", e);
        }
    }

    /**
     * Test suite for this test class.<p>
     * 
     * @return the test suite
     */    
    public static TestSetup suite() {

        OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);

        TestSuite suite = new TestSuite();
        suite.setName(TestCmsFlexResponse.class.getName());

        suite.addTest(new TestCmsFlexResponse("testContentTypeRules"));

        TestSetup wrapper = new TestSetup(suite) {

            protected void setUp() {

                setupOpenCms("simpletest", "/sites/default/");
            }

            protected void tearDown() {

                removeOpenCms();
            }
        };

        return wrapper;
    }

    /** 
     * Convenience method to create a mock HttpServletRequest backed by the given invocation handler.<p>
     */
    private static HttpServletRequest createMockRequest(RecordingMock recorder) {

        return (HttpServletRequest)createProxy(HttpServletRequest.class, recorder);
    }

    /** 
     * Convenience method to create a mock HttpServletResponse backed by the given invocation handler.<p>
     */
    private static HttpServletResponse createMockResponse(RecordingMock recorder) {

        return (HttpServletResponse)createProxy(HttpServletResponse.class, recorder);
    }

    private static Object createProxy(Class interfaceClass, InvocationHandler handler) {

        return Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(),
            new Class[] {interfaceClass},
            handler);
    }

    /**
     * Test semantics for Content-Type header on
     * {@link CmsFlexResponse#setContentType(String)} and {@link CmsFlexResponse#setHeader(String, String)}.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testContentTypeRules() throws Exception {

        // test that non-top elements won't try to set the content type.
        CmsFlexResponse f_res = new CmsFlexResponse(m_response, m_controller, false, false);
        f_res.setHeader(CmsRequestUtil.HEADER_CONTENT_TYPE, "application/borked");
        assertTrue("non-top request does not set content type header", m_resMock.m_invocations.isEmpty());

        f_res.setContentType("application/stillborked");
        assertTrue("non-top request does not set content type header", m_resMock.m_invocations.isEmpty());

        // test that top elements only set content type once
        // first, try with a call to setContentType()
        f_res = new CmsFlexResponse(m_response, m_controller, false, true);
        f_res.setContentType("text/foo");

        assertEquals("one method has been invoked on the actual response", 1, m_resMock.m_invocations.size());
        List setCalls = m_resMock.getCalls(SET_CONTENT_TYPE);
        assertEquals("top element has called setContentType() on the actual servlet response", 1, setCalls.size());
        assertEquals("correct content type value passed", "text/foo", ((Object[])setCalls.get(0))[0]);

        // subsequent attempts to set the content type on the same response should have no affect
        f_res.setContentType("text/bar");
        assertEquals("top element did NOT call content type method again", 1, setCalls.size());

        f_res.setHeader(CmsRequestUtil.HEADER_CONTENT_TYPE, "text/baz");
        assertEquals("still no more calls to setContentType() method", 1, setCalls.size());
        assertEquals("no other methods called on request", 1, m_resMock.m_invocations.size());

        // now, try with a call to setHeader on a new top response
        f_res = new CmsFlexResponse(m_response, m_controller, false, true);
        f_res.setHeader(CmsRequestUtil.HEADER_CONTENT_TYPE, "text/qux");
        assertEquals("setContentType() was called from setHeader", 2, setCalls.size());
        assertEquals("correct content type value passed", "text/qux", ((Object[])setCalls.get(1))[0]);

        // subsequent attempts to set the content type on the same response should have no affect
        f_res.setContentType("text/quux");
        assertEquals("no further calls to setContentType", 2, setCalls.size());
        assertEquals("no other methods called", 1, m_resMock.m_invocations.size());

        f_res.setHeader(CmsRequestUtil.HEADER_CONTENT_TYPE, "text/arg");
        assertEquals("no further calls to setContentType", 2, setCalls.size());
        assertEquals("no other methods called", 1, m_resMock.m_invocations.size());
    }

    /**
     * Initializes a flex cache controller and mock servlet request and response objects to be
     * used by this unit tests.<p>
     * 
     * @throws Exception if the setup fails
     * 
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {

        super.setUp();
        CmsObject cms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest());
        if (!cms.getRequestContext().currentUser().getName().equals(OpenCms.getDefaultUsers().getUserGuest())) {
            fail("'Guest' user could not be properly initialized!");
        }

        m_reqMock = new RecordingMock(new RequestStub());
        m_request = createMockRequest(m_reqMock);
        m_resMock = new RecordingMock();
        m_response = createMockResponse(m_resMock);

        m_controller = new CmsFlexController(cms, null, CmsFlexDummyLoader.m_flexCache, m_request, m_response, false, true);
        CmsFlexController.setController(m_request, m_controller);
    }

    /**
     * @see junit.framework.TestCase#tearDown()
     */
    protected void tearDown() throws Exception {

        super.tearDown();
        m_reqMock = null;
        m_resMock = null;
        m_request = null;
        m_response = null;
        m_controller = null;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www.日本不卡| ●精品国产综合乱码久久久久| 欧美激情一区二区| 亚洲福利国产精品| 国产精品亚洲人在线观看| 日本大香伊一区二区三区| 欧美videofree性高清杂交| 亚洲一卡二卡三卡四卡无卡久久| 国产成人综合在线观看| 91精品国产综合久久久蜜臀粉嫩 | 久久精品av麻豆的观看方式| 色婷婷激情久久| 国产精品美女久久久久久2018| 日韩国产成人精品| 欧美揉bbbbb揉bbbbb| 国产精品家庭影院| 国产精品综合视频| 精品少妇一区二区三区| 亚洲国产精品久久久久婷婷884| k8久久久一区二区三区| 久久久夜色精品亚洲| 美女网站视频久久| 欧美一区二区三区免费| 丝袜美腿成人在线| 欧美精品三级在线观看| 亚洲成人av在线电影| 欧美日韩精品一区二区天天拍小说 | 国产成人一区在线| 久久久久久99精品| 国产成人精品在线看| 久久亚洲免费视频| 亚洲线精品一区二区三区| 日本韩国一区二区| 亚洲已满18点击进入久久| 欧美在线不卡视频| 亚洲精品美腿丝袜| 欧美日韩在线三级| 天天色天天操综合| 91精品福利在线一区二区三区| 性做久久久久久免费观看| 制服.丝袜.亚洲.中文.综合| 日本不卡的三区四区五区| 欧美不卡123| 国产精品资源站在线| 中文在线免费一区三区高中清不卡| 国产成人自拍高清视频在线免费播放| 久久网这里都是精品| 国产ts人妖一区二区| 国产精品素人一区二区| 色综合天天综合在线视频| 亚洲成人av一区二区| 日韩欧美中文字幕制服| 国产v日产∨综合v精品视频| 亚洲免费视频中文字幕| 精品1区2区3区| 韩国欧美一区二区| 亚洲欧美综合色| 欧美日韩在线电影| 国产精品亚洲一区二区三区妖精| 中文字幕一区二区5566日韩| 欧美日韩综合在线免费观看| 国产一区二区三区在线观看免费| 国产精品成人在线观看| 欧美精品久久久久久久多人混战 | 欧美www视频| 99国内精品久久| 人人狠狠综合久久亚洲| 国产精品丝袜一区| 欧美人与性动xxxx| 国产成人精品www牛牛影视| 亚洲精品成a人| 久久夜色精品国产欧美乱极品| 成人教育av在线| 日日夜夜免费精品| 综合久久综合久久| 精品国产一区二区亚洲人成毛片 | 成人小视频在线| 日韩电影免费在线看| 中文字幕中文字幕在线一区| 日韩女优电影在线观看| 日本高清视频一区二区| 国产91丝袜在线18| 看电视剧不卡顿的网站| 一区二区三区在线视频免费观看| 26uuu国产一区二区三区| 精品视频免费在线| 99久久婷婷国产综合精品 | 久久精品人人爽人人爽| 欧美情侣在线播放| 色成年激情久久综合| 国产精品99久久久久| 蜜桃久久av一区| 午夜精品爽啪视频| 亚洲最色的网站| 亚洲啪啪综合av一区二区三区| 国产亚洲一区二区在线观看| 91精品欧美综合在线观看最新| 91精彩视频在线观看| 成人av资源站| 成人午夜激情影院| 99精品桃花视频在线观看| 91福利在线导航| 99re亚洲国产精品| 国产成人在线视频播放| 亚洲精品v日韩精品| 欧美一级精品大片| 一本大道av一区二区在线播放| 国产高清精品网站| 国产一区二区视频在线播放| 久久精品国产网站| 激情小说亚洲一区| 国产原创一区二区三区| 国产美女在线观看一区| 国产馆精品极品| 国产成人精品www牛牛影视| 丰满白嫩尤物一区二区| 国产成人在线影院| av在线不卡免费看| 色一情一伦一子一伦一区| 色综合久久天天| 欧美午夜电影在线播放| 91.麻豆视频| 欧美精品一区二区三区四区| 久久中文娱乐网| 自拍偷拍欧美精品| 伊人色综合久久天天人手人婷| 一区二区三区丝袜| 手机精品视频在线观看| 九九九精品视频| 福利一区二区在线| 色综合天天性综合| 亚洲免费在线观看| 亚洲va天堂va国产va久| 美国十次了思思久久精品导航| 极品美女销魂一区二区三区| 盗摄精品av一区二区三区| 色先锋资源久久综合| 制服丝袜av成人在线看| 国产日韩精品一区二区浪潮av| 国产精品久久久久久久久图文区 | 精品入口麻豆88视频| 国产清纯在线一区二区www| 中文字幕佐山爱一区二区免费| 亚洲一区二区欧美日韩| 麻豆91在线播放免费| 成人av免费网站| 91麻豆精品国产91久久久久久| 亚洲精品一区二区三区在线观看 | 日韩美女视频一区| 亚洲123区在线观看| 韩国成人精品a∨在线观看| 97精品超碰一区二区三区| 51精品国自产在线| 国产日产欧美一区| 亚洲一区二区三区免费视频| 国产在线日韩欧美| 欧洲中文字幕精品| 日本一区二区三区国色天香 | 丝袜诱惑亚洲看片| av在线不卡网| 久久亚洲二区三区| 一区二区理论电影在线观看| 国产一区二区三区高清播放| 在线精品视频免费观看| 久久精品一区二区三区不卡 | 亚洲午夜精品一区二区三区他趣| 国产在线观看免费一区| 欧美日韩免费在线视频| 中文字幕亚洲一区二区va在线| 免费一级片91| 欧美日韩国产不卡| 亚洲人精品午夜| 粉嫩蜜臀av国产精品网站| 欧美一区二区免费视频| 一区二区高清视频在线观看| 北条麻妃国产九九精品视频| 日韩精品中午字幕| 天天色图综合网| 欧美日韩一区中文字幕| 一区二区三区在线视频观看| 成人免费观看男女羞羞视频| 精品福利视频一区二区三区| 蜜臀va亚洲va欧美va天堂| 欧美精品aⅴ在线视频| 一区二区三区自拍| 91在线观看成人| 国产精品国产三级国产aⅴ无密码| 国产又黄又大久久| 久久久国产一区二区三区四区小说 | 欧美性大战xxxxx久久久| 亚洲男人的天堂在线aⅴ视频| 国产盗摄精品一区二区三区在线 | 精品少妇一区二区三区在线视频| 午夜电影一区二区三区| 91精品91久久久中77777| 依依成人综合视频| 欧美日韩一区二区欧美激情| 亚洲黄色免费电影| 欧美日韩久久不卡| 奇米影视7777精品一区二区|