Search in sources :

Example 16 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletNoProxyTest method testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy.

@Test
public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy() throws Exception {
    String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
    String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
    Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
    Files.createDirectories(artifactFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/legacy/" + commonsLangJar);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseNotFound(response);
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 17 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletNoProxyTest method testGetNoProxyDualExtensionDefaultLayoutManagedLegacy.

/**
 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
 */
@Test
public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy() throws Exception {
    String expectedContents = "the-contents-of-the-dual-extension";
    String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
    Path checksumFile = repoRootLegacy.resolve("org.project/distributions/example-presentation-3.2.xml.zip");
    Files.createDirectories(checksumFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/legacy/" + dualExtensionPath);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseNotFound(response);
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 18 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletNoProxyTest method testGetNoProxyDistributionLegacyLayoutManagedLegacy.

@Test
public void testGetNoProxyDistributionLegacyLayoutManagedLegacy() throws Exception {
    String expectedContents = "the-contents-of-the-dual-extension";
    String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
    Path checksumFile = repoRootLegacy.resolve(dualExtensionPath);
    Files.createDirectories(checksumFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/legacy/" + dualExtensionPath);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseNotFound(response);
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 19 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletNoProxyTest method testGetNoProxyArtifactDefaultLayoutManagedLegacy.

@Test
public void testGetNoProxyArtifactDefaultLayoutManagedLegacy() throws Exception {
    String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
    String expectedArtifactContents = "dummy-commons-lang-artifact";
    Path artifactFile = repoRootLegacy.resolve("commons-lang/jars/commons-lang-2.1.jar");
    Files.createDirectories(artifactFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/legacy/" + commonsLangJar);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseNotFound(response);
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 20 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletProxiedPassthroughTest method assertGetProxiedResource.

private void assertGetProxiedResource(int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp, String path, String contents) throws Exception {
    // --- Setup
    setupCentralRemoteRepo();
    setupCleanInternalRepo();
    String expectedRemoteContents = contents;
    String expectedManagedContents = null;
    Path remoteFile = populateRepo(remoteCentral, path, expectedRemoteContents);
    if (hasManagedCopy) {
        expectedManagedContents = contents;
        Path managedFile = populateRepo(repoRootInternal, path, expectedManagedContents);
        Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
    }
    setupConnector(REPOID_INTERNAL, remoteCentral);
    saveConfiguration();
    // --- Execution
    // process the response code later, not via an exception.
    // HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + path);
    WebResponse response = getServletUnitClient().getResponse(request);
    switch(expectation) {
        case EXPECT_MANAGED_CONTENTS:
            assertResponseOK(response);
            assertTrue("Invalid Test Case: Can't expect managed contents with " + "test that doesn't have a managed copy in the first place.", hasManagedCopy);
            assertEquals("Expected managed file contents", expectedManagedContents, response.getContentAsString());
            break;
        case EXPECT_REMOTE_CONTENTS:
            assertResponseOK(response, path);
            assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
            break;
        case EXPECT_NOT_FOUND:
            assertResponseNotFound(response);
            assertManagedFileNotExists(repoRootInternal, path);
            break;
    }
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest)

Aggregations

WebRequest (com.gargoylesoftware.htmlunit.WebRequest)84 Test (org.junit.Test)65 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)49 URL (java.net.URL)31 Path (java.nio.file.Path)31 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)12 TextPage (com.gargoylesoftware.htmlunit.TextPage)12 InputStream (java.io.InputStream)7 MkColMethodWebRequest (org.apache.archiva.webdav.httpunit.MkColMethodWebRequest)7 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)7 WebClient (com.gargoylesoftware.htmlunit.WebClient)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 IOException (java.io.IOException)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Page (com.gargoylesoftware.htmlunit.Page)3 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)3 HashMap (java.util.HashMap)3 Issue (org.jvnet.hudson.test.Issue)3 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)2 IncorrectnessListener (com.gargoylesoftware.htmlunit.IncorrectnessListener)2