Java Code Examples for com.meterware.httpunit.WebResponse#getInputStream()

The following examples show how to use com.meterware.httpunit.WebResponse#getInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnonPortalTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
	try
	{
		wc = new WebConversation();
		WebRequest req = new GetMethodWebRequest(TEST_URL);
		WebResponse resp = wc.getResponse(req);
		DataInputStream inputStream = new DataInputStream(resp.getInputStream());
		buffer = new byte[resp.getContentLength()];
		inputStream.readFully(buffer);
		visited = new HashMap<String, String>();
	}
	catch (Exception notfound)
	{
		enabled = false;
	}
}
 
Example 2
Source File: AnonPortalTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
	try
	{
		wc = new WebConversation();
		WebRequest req = new GetMethodWebRequest(TEST_URL);
		WebResponse resp = wc.getResponse(req);
		DataInputStream inputStream = new DataInputStream(resp.getInputStream());
		buffer = new byte[resp.getContentLength()];
		inputStream.readFully(buffer);
		visited = new HashMap<String, String>();
	}
	catch (Exception notfound)
	{
		enabled = false;
	}
}
 
Example 3
Source File: JaxRsServletTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void testInvokingBookService(String serviceAddress) throws Exception {
    ServletUnitClient client = newClient();
    client.setExceptionsThrownOnErrorStatus(false);

    WebRequest req =
        new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress);

    WebResponse response = client.getResponse(req);
    InputStream in = response.getInputStream();
    InputStream expected = JaxRsServletTest.class
        .getResourceAsStream("resources/expected_get_book123.txt");

    assertEquals(" Can't get the expected result ",
                 getStringFromInputStream(expected),
                 getStringFromInputStream(in));

}
 
Example 4
Source File: TransferTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testExportProject() throws CoreException, IOException, SAXException {
	//create content to export
	String directoryPath = "sample/directory/path" + System.currentTimeMillis();
	createDirectory(directoryPath);
	createDirectory(directoryPath + "/empty");
	String fileContents = "This is the file contents";
	createFile(directoryPath + "/file.txt", fileContents);

	GetMethodWebRequest export = new GetMethodWebRequest(getExportRequestPath(directoryPath));
	setAuthentication(export);
	WebResponse response = webConversation.getResponse(export);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	boolean found = false;
	boolean emptyDirFound = false;
	ZipInputStream in = new ZipInputStream(response.getInputStream());
	ZipEntry entry;
	while ((entry = in.getNextEntry()) != null) {
		if (entry.getName().equals("file.txt")) {
			found = true;
			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
			IOUtilities.pipe(in, bytes, false, false);
			assertEquals(fileContents, new String(bytes.toByteArray()));
		} else if (entry.getName().equals("empty/") && entry.isDirectory()) {
			emptyDirFound = true;
		}
	}
	assertTrue(found && emptyDirFound);
}