Search in sources :

Example 1 with MkColMethodWebRequest

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);
        }
    };
}
Also used : MkColMethodWebRequest(org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 2 with MkColMethodWebRequest

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));
}
Also used : Path(java.nio.file.Path) MkColMethodWebRequest(org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) MkColMethodWebRequest(org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest) Test(org.junit.Test)

Aggregations

WebResponse (com.gargoylesoftware.htmlunit.WebResponse)2 MkColMethodWebRequest (org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest)2 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1