use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class TestWsdlServlet method doWsdlServletRequest.
String doWsdlServletRequest(String wsdlUrl, boolean admin, int expectedCode) throws Exception {
Server localServer = Provisioning.getInstance().getLocalServer();
String protoHostPort;
if (admin)
protoHostPort = "https://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraAdminPort, 0);
else
protoHostPort = "http://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraMailPort, 0);
String url = protoHostPort + wsdlUrl;
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
try {
int respCode = HttpClientUtil.executeMethod(client, method);
int statusCode = method.getStatusCode();
String statusLine = method.getStatusLine().toString();
ZimbraLog.test.debug("respCode=" + respCode);
ZimbraLog.test.debug("statusCode=" + statusCode);
ZimbraLog.test.debug("statusLine=" + statusLine);
assertTrue("Response code", respCode == expectedCode);
assertTrue("Status code", statusCode == expectedCode);
Header[] respHeaders = method.getResponseHeaders();
for (int i = 0; i < respHeaders.length; i++) {
String header = respHeaders[i].toString();
ZimbraLog.test.debug("ResponseHeader:" + header);
}
String respBody = method.getResponseBodyAsString();
// ZimbraLog.test.debug("Response Body:" + respBody);
return respBody;
} catch (HttpException e) {
fail("Unexpected HttpException" + e);
throw e;
} catch (IOException e) {
fail("Unexpected IOException" + e);
throw e;
} finally {
method.releaseConnection();
}
}
use of org.apache.commons.httpclient.Header in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteUpdateObjectFailure.
@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteUpdateObjectFailure() throws BigSwitchBcfApiException, IOException {
NetworkData network = new NetworkData();
_method = mock(PutMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true);
try {
_api.executeUpdateObject(network, "/", Collections.<String, String>emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
use of org.apache.commons.httpclient.Header in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteDeleteObjectFailure.
@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteDeleteObjectFailure() throws BigSwitchBcfApiException, IOException {
_method = mock(DeleteMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true);
try {
_api.executeDeleteObject("/");
} finally {
verify(_method, times(1)).releaseConnection();
}
}
use of org.apache.commons.httpclient.Header in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteCreateObjectOK.
@Test
public void testExecuteCreateObjectOK() throws BigSwitchBcfApiException, IOException {
NetworkData network = new NetworkData();
_method = mock(PostMethod.class);
when(_method.getResponseHeader("X-BSN-BVS-HASH-MATCH")).thenReturn(new Header("X-BSN-BVS-HASH-MATCH", UUID.randomUUID().toString()));
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
String hash = _api.executeCreateObject(network, "/", Collections.<String, String>emptyMap());
verify(_method, times(1)).releaseConnection();
verify(_client, times(1)).executeMethod(_method);
assertNotEquals(hash, "");
assertNotEquals(hash, BigSwitchBcfApi.HASH_CONFLICT);
assertNotEquals(hash, BigSwitchBcfApi.HASH_IGNORE);
}
use of org.apache.commons.httpclient.Header in project cloudstack by apache.
the class BigSwitchApiTest method testExecuteCreateObjectFailure.
@Test(expected = BigSwitchBcfApiException.class)
public void testExecuteCreateObjectFailure() throws BigSwitchBcfApiException, IOException {
NetworkData network = new NetworkData();
_method = mock(PostMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true);
try {
_api.executeCreateObject(network, "/", Collections.<String, String>emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
Aggregations