当前位置: 首页>>代码示例>>Java>>正文


Java WebRequest.setHeaderField方法代码示例

本文整理汇总了Java中com.meterware.httpunit.WebRequest.setHeaderField方法的典型用法代码示例。如果您正苦于以下问题:Java WebRequest.setHeaderField方法的具体用法?Java WebRequest.setHeaderField怎么用?Java WebRequest.setHeaderField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.meterware.httpunit.WebRequest的用法示例。


在下文中一共展示了WebRequest.setHeaderField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();

    //Prepare the environment..
    ProxymaFacade proxyma = new ProxymaFacade();
    ProxymaContext context = proxyma.createNewContext("default", "/", "src/test/resources/test-config.xml", "/tmp/");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet( "myServlet", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet?a=1&b=2" );
    wreq.setParameter( "color", "red" );
    wreq.setHeaderField("Cookie", "rewritten=value1");
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:19,代码来源:HttpRedirectsRewriteTransformerTest.java

示例2: testHeaderAccess

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
public void testHeaderAccess() throws Exception {
    WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
    wr.setHeaderField( "sample", "value" );
    HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
    assertEquals( "sample header value", "value", request.getHeader( "sample") );

    assertContains( "Header names", "sample", request.getHeaderNames() );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:HttpServletRequestTest.java

示例3: testSpecifiedLocales

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
public void testSpecifiedLocales() throws Exception {
    WebRequest wr = new GetMethodWebRequest( "http://localhost/simple");
    wr.setHeaderField( "Accept-language", "fr, en;q=0.6, en-us;q=0.7" );

    ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
    verifyLocales( request, new Locale[] { Locale.FRENCH, Locale.US, Locale.ENGLISH } );
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:8,代码来源:HttpServletRequestTest.java

示例4: createWebRequest

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
private HttpServletRequest createWebRequest(String uri, String... parameters) {

        WebRequest request = new PostMethodWebRequest("http://localhost" + uri);

        if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) {
            request.setHeaderField("referer", "http://localhost");

            String sessionId = sc.getSession(true).getId();
            String token = CryptoHelper.computeSessionToken(sessionId);
            request.setParameter(Const.ParamsNames.SESSION_TOKEN, token);
        }

        Map<String, List<String>> paramMultiMap = new HashMap<>();
        for (int i = 0; i < parameters.length; i = i + 2) {
            String key = parameters[i];
            if (paramMultiMap.get(key) == null) {
                paramMultiMap.put(key, new ArrayList<String>());
            }
            paramMultiMap.get(key).add(parameters[i + 1]);
        }

        paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[values.size()])));

        try {
            InvocationContext ic = sc.newInvocation(request);
            return ic.getRequest();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:31,代码来源:GaeSimulation.java

示例5: doTest

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
/**
 * Test link generated using requestUri.
 * @param jspName jsp name, with full path
 * @throws Exception any axception thrown during test.
 */
@Override
@Test
public void doTest() throws Exception
{

    Assert.assertEquals("utf-8", System.getProperty("file.encoding"));

    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName()));
    request.setParameter("city", "MünchenXX");
    request.setHeaderField("Content-Type", "text/html; charset=utf-8");

    // just check that everything is ok before reaching displaytag
    Assert.assertEquals("MünchenXX", request.getParameter("city"));
    WebResponse response = runner.getResponse(request);

    Assert.assertEquals("utf-8", response.getCharacterSet());

    if (log.isDebugEnabled())
    {
        log.debug(response.getText());
    }

    WebTable[] tables = response.getTables();
    Assert.assertEquals("Wrong number of tables.", 1, tables.length);

    WebLink[] links = response.getLinks();
    Assert.assertEquals("Wrong number of links in result.", 4, links.length);

    String expected = "M%C3%BCnchen";

    String actual = StringUtils.substringBetween(links[0].getURLString(), "city=", "XX");

    Assert.assertEquals(expected, actual);
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:40,代码来源:EncodedUriTest.java

示例6: doTest

import com.meterware.httpunit.WebRequest; //导入方法依赖的package包/类
/**
 * Link generated for results navigation is breaking national character taken from FormBean.
 * @param jspName jsp name, with full path
 * @throws Exception any axception thrown during test.
 */
@Override
@Test
public void doTest() throws Exception
{
    WebRequest request = new GetMethodWebRequest(getJspUrl(getJspName())); // use post
    String paramValue = "aàeèiìoòuù";

    request.setParameter("testparam", paramValue);

    request.setHeaderField("Content-Type", "text/html; charset=utf-8");

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled())
    {
        log.debug(response.getText());
    }

    WebTable[] tables = response.getTables();
    Assert.assertEquals("Wrong number of tables", 1, tables.length);

    WebLink[] links = response.getLinks();
    Assert.assertEquals("Wrong number of links", 3, links.length); // sorting + paging

    String url = URLDecoder.decode(links[0].getURLString(), "UTF-8");

    String actual = StringUtils.substringAfter(url, "testparam=");
    if (StringUtils.contains(actual, "&"))
    {
        actual = StringUtils.substringBefore(actual, "&");
    }

    Assert.assertEquals(paramValue, actual);
}
 
开发者ID:webbfontaine,项目名称:displaytag,代码行数:40,代码来源:Displ249Test.java


注:本文中的com.meterware.httpunit.WebRequest.setHeaderField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。