use of org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest in project archiva by apache.
the class AbstractRepositoryServletTestCase method getWebResponse.
protected // , boolean followRedirect )
WebResponse getWebResponse(// , boolean followRedirect )
WebRequest webRequest) throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI(webRequest.getUrl().getPath());
request.addHeader("User-Agent", "Apache Archiva unit test");
request.setMethod(webRequest.getHttpMethod().name());
if (webRequest.getHttpMethod() == HttpMethod.PUT) {
PutMethodWebRequest putRequest = PutMethodWebRequest.class.cast(webRequest);
request.setContentType(putRequest.contentType);
request.setContent(IOUtils.toByteArray(putRequest.inputStream));
}
if (webRequest instanceof MkColMethodWebRequest) {
request.setMethod("MKCOL");
}
final MockHttpServletResponse response = execute(request);
if (response.getStatus() == HttpServletResponse.SC_MOVED_PERMANENTLY || response.getStatus() == HttpServletResponse.SC_MOVED_TEMPORARILY) {
String location = response.getHeader("Location");
log.debug("follow redirect to {}", location);
return getWebResponse(new GetMethodWebRequest(location));
}
return new WebResponse(null, null, 1) {
@Override
public String getContentAsString() {
try {
return response.getContentAsString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
@Override
public int getStatusCode() {
return response.getStatus();
}
@Override
public String getResponseHeaderValue(String headerName) {
return response.getHeader(headerName);
}
};
}
use of org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest in project archiva by apache.
the class RepositoryServletDeployTest method testMkColWithMissingParentCollectionFails.
@Test
public void testMkColWithMissingParentCollectionFails() throws Exception {
setupCleanRepo(repoRootInternal);
String putUrl = "http://machine.com/repository/internal/path/to/";
WebRequest request = new MkColMethodWebRequest(putUrl);
WebResponse response = getServletUnitClient().getResponse(request);
assertEquals(HttpServletResponse.SC_CONFLICT, response.getStatusCode());
Path mkColLocalPath = repoRootInternal.resolve("path/to/");
assertFalse(Files.exists(mkColLocalPath));
}
Aggregations