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


Java ServletRunner.newClient方法代码示例

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


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

示例1: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:CookieRewriteEngineTest.java

示例2: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:17,代码来源:ProxymaServletResponseTest.java

示例3: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:17,代码来源:ProxymaServletRequestTest.java

示例4: testLog

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Test of log method, of class FireJavaSimple.
 * @throws IOException
 */
@Test
public void testLog() throws IOException {
    System.out.println("log");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("FireJavaSimple", "FireJavaSimple");
    ServletUnitClient sc = sr.newClient();
    PostMethodWebRequest postRequest = new PostMethodWebRequest("http://zoeey.org/", true);
    postRequest.setParameter("name", "MoXie");
    postRequest.setParameter("email", "[email protected]");
    InvocationContext ic = sc.newInvocation(postRequest);
    HttpServletResponse response = ic.getResponse();
    FireJavaSimple.log(response, "LOG MESSAGE");
    FireJavaSimple.info(response, "INFO MESSAGE");
    FireJavaSimple.warn(response, "WARN MESSAGE");
    FireJavaSimple.error(response, "ERROR MESSAGE");
    WebResponse wresponse = ic.getServletResponse();
    assertEquals(wresponse.getHeaderField("X-WF-1-INDEX"), "4");
    assertEquals(wresponse.getHeaderField("X-WF-1-1-1-1"), "30|[{\"Type\":\"LOG\"},\"LOG MESSAGE\"]|");
    assertEquals(wresponse.getHeaderField("X-WF-1-1-1-2"), "32|[{\"Type\":\"INFO\"},\"INFO MESSAGE\"]|");
    assertEquals(wresponse.getHeaderField("X-WF-1-1-1-3"), "32|[{\"Type\":\"WARN\"},\"WARN MESSAGE\"]|");
    assertEquals(wresponse.getHeaderField("X-WF-1-1-1-4"), "34|[{\"Type\":\"ERROR\"},\"ERROR MESSAGE\"]|");
}
 
开发者ID:eixom,项目名称:zoeey,代码行数:27,代码来源:FireJavaSimpleTest.java

示例5: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:SimpleHttpRetriverTest.java

示例6: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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/library.js", TestServlet.class.getName() );
    ServletUnitClient sc = sr.newClient();
    WebRequest wreq   = new GetMethodWebRequest( "http://test.meterware.com/myServlet/library.js" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    request = ic.getRequest();
    response = ic.getResponse();
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:18,代码来源:JSRewriteTransformerTest.java

示例7: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的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

示例8: testCreate

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Test of create method, of class PostTicket.
 */
@Test
public void testCreate() {
    System.out.println("create");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("Uploader", "Uploader");
    ServletUnitClient sc = sr.newClient();
    /**
     * 创建ticket -> 放入表单中 -> 提交后检验
     */
    /**
     * 第一次提交验证成功
     */
    String ticket = PostTicket.create("tokenKey", sc.getSession(true));
    Boolean isVali = PostTicket.vali(ticket, "tokenKey", sc.getSession(true));
    assertTrue(isVali);
    /**
     * 未获取新的ticket,第二次提交验证失败
     */
    isVali = PostTicket.vali(ticket, "tokenKey", sc.getSession(true));
    assertFalse(isVali);
    /**
     * ticket是模拟出来的,验证失败
     */
    ticket = PostTicket.create("tokenKey", sc.getSession(true));
    ticket += "abc";
    isVali = PostTicket.vali(ticket, "tokenKey", sc.getSession(true));
    assertFalse(isVali);
}
 
开发者ID:eixom,项目名称:zoeey,代码行数:32,代码来源:PostTicketTest.java

示例9: testInit

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 *
 * @throws IOException
 * @throws ServletException
 */
@Test
public void testInit() throws IOException, ServletException {

    ServletRunner sr = new ServletRunner();
    sr.registerServlet("Uploader", "Uploader");
    ServletUnitClient sc = sr.newClient();
    PostMethodWebRequest postRequest = new PostMethodWebRequest("http://zoeey.org/", true);
    postRequest.selectFile("bugFile", new File(TestUtil.getBugPng()));
    postRequest.setParameter("name", "MoXie");
    postRequest.setParameter("email", "[email protected]");
    postRequest.setParameter("multiLine", "1\n2\n3\n");
    InvocationContext ic = sc.newInvocation(postRequest);
    UploadConfig config = new UploadConfig();
    config.setFilesizeMax(888);
    Uploader up = new Uploader(ic.getRequest(), config);
    assertEquals("MoXie", up.getParamenter("name"));
    assertEquals("[email protected]", up.getParamenter("email"));
    /**
     * 多行httpunit bug!?
     */
    assertEquals(JsonHelper.encode("1\r\n2\r\n3\r\n"), JsonHelper.encode(up.getParamenter("multiLine")));
    FileItem fileItem = up.getFileItem("bugFile");
    assertEquals(FileError.OK, fileItem.getError());
    assertEquals("bugFile", fileItem.getFieldName());
    assertEquals("bug.png", fileItem.getOriginalName());
    assertEquals(774, fileItem.getSize());
    assertTrue(fileItem.getTempFile().isFile());
    assertEquals(774, fileItem.getTempFile().length());
    assertEquals("image/png", fileItem.getType());

}
 
开发者ID:eixom,项目名称:zoeey,代码行数:37,代码来源:UploaderTest.java

示例10: testDoProxy

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Test of doProxy method, of class ProxyEngine.
 */
public void testDoProxy() throws IOException, SAXException, IllegalAccessException, Exception {
    System.out.println("doProxy");

    //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();

    System.out.println(" --->test contextroot (expected redirect)");
    WebRequest wreq   = new GetMethodWebRequest( "http://localhost:0/myServlet");
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    HttpServletRequest request = ic.getRequest();
    HttpServletResponse response = ic.getResponse();
    ProxymaResource aResource = proxyma.createNewResource(request, response, context);
    ProxyEngine instance = proxyma.createNewProxyEngine(context);
    ProxyFolderBean folder = proxyma.createNewProxyFolder("google", "http://www.google.com", context);
    folder = proxyma.createNewProxyFolder("apple", "http://www.apple.com", context);
    folder.setEnabled(false);

    int retval = instance.doProxy(aResource);
    assertEquals(302, retval);
    assertEquals(context.getProxymaVersion(), aResource.getResponse().getResponseData().getHeader("Server").getValue());

   

    //Cleanup the pool
    try {
        proxyma.removeProxyFolder(proxyma.getProxyFolderByURLEncodedName("google", context), context);
        proxyma.removeProxyFolder(proxyma.getProxyFolderByURLEncodedName("apple", context), context);
        proxyma.destroyContext(context);
    } catch (Exception x) {
        fail("Unable to unregister the context");
    }
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:41,代码来源:ProxyEngineTest.java

示例11: testHelloWorldUsingServletUnit

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Example for a test using ServletUnit on a SAP HANA Cloud application.
 */
@Test
public void testHelloWorldUsingServletUnit() throws IOException, SAXException {
    // Prepare servlet emulation environment
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("hello-world", HelloWorldServlet.class.getName());
    ServletUnitClient sc = sr.newClient();

    // Call servlet
    WebRequest request = new GetMethodWebRequest("http://test.meterware.com/hello-world");
    WebResponse response = sc.getResponse(request);

    // Check for string "Hello" in the returned response
    Assert.assertTrue(response.getText().indexOf("Hello World") != -1);
}
 
开发者ID:stephanme,项目名称:cloud-helloworld,代码行数:18,代码来源:HelloWorldServletTest.java

示例12: setUp

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
public void setUp() throws Exception {
    InputStream webXmlInputStream = getClass().getClassLoader().getResourceAsStream("WEB-INF/web.xml");
    servletRunner = new ServletRunner(webXmlInputStream);
    client = servletRunner.newClient();

    localServiceTestHelper.setUp();

    nextEmailIndex = 0;
}
 
开发者ID:openmash,项目名称:mashmesh,代码行数:10,代码来源:IntegrationTestHelper.java

示例13: testGetAttributeNames

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Test of getAttributeNames method, of class ProxymaResource.
 */
public void testGetAttributeNames() throws IOException, SAXException {
    System.out.println("getAttributeNames");

    //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" );
    wreq.setParameter( "color", "red" );
    WebResponse wres = sc.getResponse( wreq );
    InvocationContext ic = sc.newInvocation( wreq );
    HttpServletRequest request = ic.getRequest();
    HttpServletResponse response = ic.getResponse();
    ProxymaServletRequest proxumaReq = new ProxymaServletRequest(request, context);
    ProxymaServletResponse proxymaRes = new ProxymaServletResponse(response, context);
    ProxymaResource instance = new ProxymaResource(proxumaReq, proxymaRes, context);

    //run the specific tests
    String anAttributeName = null;
    Object expResult = null;
    Object result = null;
    Collection<String> col = null;

    //regular attributes
    anAttributeName = "testAttribute1";
    expResult = "attrValue1";
    instance.addAttibute(anAttributeName, expResult);
    result = instance.getAttribute(anAttributeName);
    assertSame(expResult, result);

    anAttributeName = "testAttribute2";
    expResult = "attrValue2";
    instance.addAttibute(anAttributeName, expResult);
    result = instance.getAttribute(anAttributeName);
    assertSame(expResult, result);

    col = instance.getAttributeNames();
    assertEquals(2, col.size());

    Iterator<String> iter = col.iterator();
    String string = iter.next();
    if (string.equals("testAttribute1")) {
        string = iter.next();
        assertEquals("testAttribute2", string);
    } else {
        string = iter.next();
        assertEquals("testAttribute1", string);
    }
    

    //Cleanup the pool
    try {
        proxyma.destroyContext(context);
    } catch (Exception x) {
        fail("Unable to unregister the context");
    }
}
 
开发者ID:dpoldrugo,项目名称:proxyma,代码行数:63,代码来源:ProxymaResourceTest.java

示例14: main

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 *
 * @param args
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("Login", "Login");
    ServletUnitClient sc = sr.newClient();
    /**
     * client
     */
    PostMethodWebRequest postRequest = new PostMethodWebRequest("http://zoeey.org/", true);
    postRequest.setParameter("name", "MoXie");
    postRequest.setParameter("password", "moxie's password");
    // ==============
    InvocationContext ic = sc.newInvocation(postRequest);
    /**
     * web server
     */
    HttpServletRequest request = ic.getRequest();
    SessionConveyer sessionConveyer = new SessionConveyer();
    // 会话编号不一定使用 Http Session id,仅是一个不错的选择。
    sessionConveyer.setSessionId(request.getSession().getId());
    Map<String, String> params = new HashMap<String, String>();
    params.put("name", request.getParameter("name"));
    params.put("password", request.getParameter("password"));
    sessionConveyer.setData(UrlBuilder.build(params)); // 也可以使用Json
    // 设定两个Web服务器和SSO服务器内部保留的密匙,用于上下传递时的内容加密
    String ticket = sessionConveyer.getTicket("webserver's key");
    assertEquals(ticket, "HkcLV1gEVgYPBlQHVwcGBFUFAF4FBVAAAAELCwYPAyJ1fT"
            + "NsYTFmJzEtBFQQBwVGDQ5DCAcEXFELGgF9F3x0aSslfyY9NTB/fg8=");
    /**
     * SSO server
     * ticket 的传输可以直接使用location跳转,P3P共享或者Js跨域hack。
     */
    sessionConveyer = new SessionConveyer();
    // 分解ticket内容,并进行验证
    sessionConveyer.parse(ticket, "webserver's key");
    if (sessionConveyer.vali()) {
        // 验证成功,并进行用户信息填充返回。
        params = new HashMap<String, String>();
        params = QueryStringHelper.toMap(sessionConveyer.getData());
        params.remove("password");
        params.put("email", "[email protected]");
        //
        sessionConveyer.setData(JsonHelper.encode(params));
    } else {
        // 验证失败,通告web服务器失败原因。
        sessionConveyer.setData("false");
    }
    ticket = sessionConveyer.getTicket("ssoserver's key");
    assertEquals(ticket, "EEdZXlwKVFJSAlNXUlZWAAEFVA4HUlAPDgQAAFxRUSItc"
            + "DI0bnQ6bDx0CxMAAUFaAhZdcBcOCVRSXlBRQX12bXQWfGxlGy17Gl4oeiQ"
            + "8emRmA08xLlgTdVddHw4qansDeWdqOyU6PTlwBhUCIkALCh8DVhUPeQ==");
    /**
     * web server
     */
    sessionConveyer.parse(ticket, "ssoserver's key");
    if (sessionConveyer.vali(request.getSession().getId())) {
        String data = sessionConveyer.getData();
        if ("false".equals(data)) {
            fail("反馈失败");
        }
        params = (Map<String, String>) JsonHelper.decode(sessionConveyer.getData());
        assertEquals(params.get("email"), "[email protected]");
    } else {
        fail("验证失败");
    }
}
 
开发者ID:eixom,项目名称:zoeey,代码行数:72,代码来源:SimpleSSOSample.java

示例15: testParse

import com.meterware.servletunit.ServletRunner; //导入方法依赖的package包/类
/**
 * Test of parse method, of class StreamParser.
 * @throws Exception
 */
@Test
public void testParse() throws Exception {
    System.out.println("parse");

    HttpUnitOptions.setDefaultCharacterSet("utf-8");
    ServletRunner sr = new ServletRunner();
    sr.registerServlet("ExampleServlet", ExampleServlet.class.getName());
    ServletUnitClient sc = sr.newClient();
    PostMethodWebRequest postRequest = new PostMethodWebRequest("http://zoeey.org/ExampleServlet", true);
    postRequest.setParameter("name1", new String[]{"name1_value"});
    postRequest.setParameter("name2", new String[]{"name2_value"});
    postRequest.setParameter("name3", new String[]{"name3_value"});
    postRequest.setParameter("name5", new String[]{"中文字符串"});
    postRequest.setParameter("name6", new String[]{"路人甲"});
    postRequest.setParameter("MAX_FILE_SIZE", new String[]{"30000"});
    postRequest.selectFile("bugFile", new File(TestUtil.getBugPng()));
    postRequest.selectFile("bugFile2", new File(TestUtil.getBugPng()));
    //
    InvocationContext ic = sc.newInvocation(postRequest);
    HttpServletRequest request = ic.getRequest();
    String contentType = request.getContentType();
    String boundary = contentType.substring(contentType.indexOf('=') + 1);
    InputStream inStream = request.getInputStream();
    //
    UploadConfig config = new UploadConfig();
    File tempDir = new File(TestUtil.getResourceDir().concat("/temp"));
    FileHelper.tryMakeDirs(tempDir);
    config.setTempFileDir(tempDir);
    StreamParser sp = new StreamParser(boundary, config);
    sp.parse(inStream);
    assertEquals("{name5=[中文字符串], name6=[路人甲], name3=[name3_value], name1=[name1_value], name2=[name2_value], MAX_FILE_SIZE=[30000]}",//
            sp.getParamMap().toString());
    for (List<FileItem> fileItemList : sp.getFileMap().values()) {
        for (FileItem fileItem : fileItemList) {
            assertEquals("bug.png", fileItem.getOriginalName());
            assertEquals(fileItem.getError(), FileError.OK);
        }
    }
    FileHelper.tryDelete(tempDir, true);
}
 
开发者ID:eixom,项目名称:zoeey,代码行数:45,代码来源:StreamParserTest.java


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