Search in sources :

Example 56 with WebRequest

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

the class RepositoryServletNoProxyTest method testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy.

@Test
public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy() throws Exception {
    String filename = "commons-lang-2.1-20050821.023400-1.jar";
    String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
    String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
    Path artifactFile = repoRootLegacy.resolve("commons-lang/jars/" + filename);
    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 57 with WebRequest

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

the class RepositoryServletNoProxyTest method testGetNoProxyDistributionLegacyLayout.

@Test
public void testGetNoProxyDistributionLegacyLayout() throws Exception {
    String expectedContents = "the-contents-of-the-dual-extension";
    String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
    Path checksumFile = repoRootInternal.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/internal/" + "org.project/distributions/example-presentation-3.2.zip");
    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 58 with WebRequest

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

the class RepositoryServletProxiedPluginSnapshotPolicyTest method assertGetProxiedSnapshotsArtifactWithPolicy.

private void assertGetProxiedSnapshotsArtifactWithPolicy(int expectation, String snapshotsPolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
    // --- Setup
    setupSnapshotsRemoteRepo();
    setupCleanInternalRepo();
    String resourcePath = "org/apache/archiva/archivatest-maven-plugin/4.0-alpha-1-SNAPSHOT/archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42.jar";
    String expectedRemoteContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-remote-contents";
    String expectedManagedContents = null;
    Path remoteFile = populateRepo(remoteSnapshots, resourcePath, expectedRemoteContents);
    if (hasManagedCopy) {
        expectedManagedContents = "archivatest-maven-plugin-4.0-alpha-1-20070822.033400-42|jar-managed-contents";
        Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
        Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
    }
    archivaConfiguration.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>(0));
    setupSnapshotConnector(REPOID_INTERNAL, remoteSnapshots, snapshotsPolicy);
    saveConfiguration();
    // --- Execution
    // process the response code later, not via an exception.
    // HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + resourcePath);
    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);
            assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
            break;
        case EXPECT_NOT_FOUND:
            assertResponseNotFound(response);
            assertManagedFileNotExists(repoRootInternal, resourcePath);
            break;
    }
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 59 with WebRequest

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

the class RepositoryServletProxiedReleasePolicyTest method assertGetProxiedReleaseArtifactWithPolicy.

private void assertGetProxiedReleaseArtifactWithPolicy(int expectation, String releasePolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
    // --- Setup
    setupCentralRemoteRepo();
    setupCleanInternalRepo();
    String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
    String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
    String expectedManagedContents = null;
    Path remoteFile = populateRepo(remoteCentral, resourcePath, expectedRemoteContents);
    if (hasManagedCopy) {
        expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
        Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
        Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
    }
    archivaConfiguration.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>());
    setupReleaseConnector(REPOID_INTERNAL, remoteCentral, releasePolicy);
    saveConfiguration();
    // --- Execution
    // process the response code later, not via an exception.
    // HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + resourcePath);
    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);
            assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
            break;
        case EXPECT_NOT_FOUND:
            assertResponseNotFound(response);
            assertManagedFileNotExists(repoRootInternal, resourcePath);
            break;
    }
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration)

Example 60 with WebRequest

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

the class RepositoryServletBrowseTest method testBrowseSubdirectory.

@Test
public void testBrowseSubdirectory() throws Exception {
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/org");
    WebResponse response = getServletUnitClient().getResponse(request);
    assertEquals("Response", HttpServletResponse.SC_OK, response.getStatusCode());
    List<String> expectedLinks = Arrays.asList("../", "apache/", "codehaus/");
    Document document = Jsoup.parse(response.getContentAsString());
    Elements elements = document.getElementsByTag("a");
    assertLinks(expectedLinks, elements);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

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