Search in sources :

Example 41 with WebRequest

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

the class RepositoryServletProxiedTimestampedSnapshotPolicyTest method assertGetProxiedSnapshotsArtifactWithPolicy.

private void assertGetProxiedSnapshotsArtifactWithPolicy(int expectation, String snapshotsPolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
    // --- Setup
    setupSnapshotsRemoteRepo();
    setupCleanInternalRepo();
    String resourcePath = "org/apache/archiva/test/3.0-SNAPSHOT/test-3.0-20070822.033400-42.jar";
    String expectedRemoteContents = "archiva-test-3.0-20070822.033400-42|jar-remote-contents";
    String expectedManagedContents = null;
    Path remoteFile = populateRepo(remoteSnapshots, resourcePath, expectedRemoteContents);
    if (hasManagedCopy) {
        expectedManagedContents = "archiva-test-3.0-20070822.033400-42|jar-managed-contents";
        Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
        Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
    }
    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)

Example 42 with WebRequest

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

the class RepositoryServletRepositoryGroupTest method testGetFromFirstManagedRepositoryReturnOk.

/*
    * Test Case 3.c
    */
@Test
public void testGetFromFirstManagedRepositoryReturnOk() throws Exception {
    String resourceName = "dummy/dummy-first-resource/1.0/dummy-first-resource-1.0.txt";
    Path dummyInternalResourceFile = repoRootFirst.resolve(resourceName);
    Files.createDirectories(dummyInternalResourceFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "first");
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/" + resourceName);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseOK(response);
    assertThat(response.getContentAsString()).isEqualTo("first");
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 43 with WebRequest

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

the class RepositoryServletRepositoryGroupTest method testGetFromValidRepositoryGroupReturnNotFound.

/*
    * Test Case 3.b
    */
@Test
public void testGetFromValidRepositoryGroupReturnNotFound() throws Exception {
    String resourceName = "dummy/dummy-no-resource/1.0/dummy-no-resource-1.0.txt";
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/" + resourceName);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseNotFound(response);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 44 with WebRequest

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

the class RepositoryServletRepositoryGroupTest method testGetMergedMetadata.

// MRM-872
@Test
public void testGetMergedMetadata() throws Exception {
    // first metadata file
    String resourceName = "dummy/dummy-merged-metadata-resource/maven-metadata.xml";
    Path dummyInternalResourceFile = repoRootFirst.resolve(resourceName);
    Files.createDirectories(dummyInternalResourceFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n<groupId>dummy</groupId>\n<artifactId>dummy-merged-metadata-resource</artifactId>\n" + "<versioning>\n<latest>1.0</latest>\n<release>1.0</release>\n<versions>\n<version>1.0</version>\n" + "<version>2.5</version>\n</versions>\n<lastUpdated>20080708095554</lastUpdated>\n</versioning>\n</metadata>");
    // second metadata file
    resourceName = "dummy/dummy-merged-metadata-resource/maven-metadata.xml";
    dummyInternalResourceFile = repoRootLast.resolve(resourceName);
    Files.createDirectories(dummyInternalResourceFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(dummyInternalResourceFile, Charset.defaultCharset(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<metadata><groupId>dummy</groupId><artifactId>dummy-merged-metadata-resource</artifactId>" + "<versioning><latest>2.0</latest><release>2.0</release><versions><version>1.0</version>" + "<version>1.5</version><version>2.0</version></versions><lastUpdated>20080709095554</lastUpdated>" + "</versioning></metadata>");
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml");
    WebResponse response = getServletUnitClient().getResource(request);
    Path returnedMetadata = Paths.get("target/test-classes/retrievedMetadataFile.xml");
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(returnedMetadata, Charset.defaultCharset(), response.getContentAsString());
    ArchivaRepositoryMetadata metadata = MavenMetadataReader.read(returnedMetadata);
    assertResponseOK(response);
    assertThat(metadata.getAvailableVersions()).isNotNull().hasSize(4).contains("1.0", "1.5", "2.0", "2.5");
    // check if the checksum files were generated
    Path checksumFileSha1 = repoRootFirst.resolve(resourceName + ".sha1");
    Files.createDirectories(checksumFileSha1.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFileSha1, Charset.defaultCharset(), "3290853214d3687134");
    Path checksumFileMd5 = repoRootFirst.resolve(resourceName + ".md5");
    Files.createDirectories(checksumFileMd5.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFileMd5, Charset.defaultCharset(), "98745897234eda12836423");
    // request the sha1 checksum of the metadata
    request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml.sha1");
    response = getServletUnitClient().getResource(request);
    assertResponseOK(response);
    assertThat(response.getContentAsString()).isEqualTo("add113b0d7f8c6adb92a5015a7a3701081edf998  maven-metadata-group-with-valid-repos.xml");
    // request the md5 checksum of the metadata
    request = new GetMethodWebRequest("http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/dummy/" + "dummy-merged-metadata-resource/maven-metadata.xml.md5");
    response = getServletUnitClient().getResource(request);
    assertResponseOK(response);
    assertThat(response.getContentAsString()).isEqualTo("5b85ea4aa5f52bb76760041a52f98de8  maven-metadata-group-with-valid-repos.xml");
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) Test(org.junit.Test)

Example 45 with WebRequest

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

the class RepositoryServletRepositoryGroupTest method testPutValidRepositoryGroupReturnBadRequest.

/*
    * Test Case 4
    */
@Test
public void testPutValidRepositoryGroupReturnBadRequest() throws Exception {
    String resourceName = "dummy/dummy-put-resource/1.0/dummy-put-resource-1.0.txt";
    String putUrl = "http://machine.com/repository/" + REPO_GROUP_WITH_VALID_REPOS + "/" + resourceName;
    InputStream is = getClass().getResourceAsStream("/artifact.jar");
    WebRequest request = new PutMethodWebRequest(putUrl, is, "text/plain");
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseMethodNotAllowed(response);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) InputStream(java.io.InputStream) 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