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);
}
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);
}
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;
}
}
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;
}
}
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);
}
Aggregations