本文整理汇总了Java中com.gargoylesoftware.htmlunit.WebRequest类的典型用法代码示例。如果您正苦于以下问题:Java WebRequest类的具体用法?Java WebRequest怎么用?Java WebRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebRequest类属于com.gargoylesoftware.htmlunit包,在下文中一共展示了WebRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBrowse
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testBrowse()
throws Exception
{
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
WebResponse response = getServletUnitClient().getResponse( request );
assertEquals( "Response", HttpServletResponse.SC_OK, response.getStatusCode() );
// dumpResponse( response );
List<String> expectedLinks = Arrays.asList( ".indexer/", "commons-lang/", "net/", "org/" );
Document document = Jsoup.parse( response.getContentAsString() );
Elements elements = document.getElementsByTag( "a" );
assertLinks( expectedLinks, elements );
}
示例2: login
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
private static List<HtmlAnchor> login(final WebClient client)
throws IOException, MalformedURLException, Exception {
final HtmlPage homepage = client.getPage("http://ogame.org");
// we use a POST because filling out the form and clicking the login button doesn't work...
WebRequest settings = new WebRequest(new URL(
"http://ogame.org/main/login"), HttpMethod.POST);
settings.setRequestParameters(new ArrayList<NameValuePair>());
settings.getRequestParameters().add(new NameValuePair("kid", ""));
settings.getRequestParameters().add(new NameValuePair("uni", Main.settings.get("universe")));
settings.getRequestParameters().add(new NameValuePair("login", Main.settings.get("login")));
settings.getRequestParameters().add(new NameValuePair("pass", Main.settings.get("password")));
page = client.getPage(settings);
updateGame(page);
List<HtmlAnchor> menu = (List<HtmlAnchor>)page.getByXPath("//a[contains(@class, 'menubutton')]");
//System.out.println(menu);
//dump(page, "game.html");
return menu;
}
示例3: testGetVersionMetadataDefaultLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetVersionMetadataDefaultLayout()
throws Exception
{
String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
String expectedMetadataContents = "metadata-for-commons-lang-version-2.1";
File checksumFile = new File( repoRootInternal, commonsLangMetadata );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
}
示例4: testGetProjectMetadataDefaultLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetProjectMetadataDefaultLayout()
throws Exception
{
String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
String expectedMetadataContents = "metadata-for-commons-lang-version-for-project";
File checksumFile = new File( repoRootInternal, commonsLangMetadata );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
}
示例5: testGetGroupMetadataDefaultLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetGroupMetadataDefaultLayout()
throws Exception
{
String commonsLangMetadata = "commons-lang/maven-metadata.xml";
String expectedMetadataContents = "metadata-for-commons-lang-group";
File checksumFile = new File( repoRootInternal, commonsLangMetadata );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
}
示例6: testGetSnapshotVersionMetadataDefaultLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetSnapshotVersionMetadataDefaultLayout()
throws Exception
{
String assemblyPluginMetadata =
"org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-2-SNAPSHOT/maven-metadata.xml";
String expectedMetadataContents = "metadata-for-assembly-plugin-version-2.2-beta-2-SNAPSHOT";
File checksumFile = new File( repoRootInternal, assemblyPluginMetadata );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request =
new GetMethodWebRequest( "http://machine.com/repository/internal/" + assemblyPluginMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
}
示例7: testGetDirectoryWhichHasMatchingFile
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetDirectoryWhichHasMatchingFile() //MRM-893
throws Exception
{
new File( repoRootInternal, "org/apache/archiva/artifactId/1.0" ).mkdirs();
new File( repoRootInternal, "org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" ).createNewFile();
WebRequest request =
new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId" );
WebResponse response = getServletUnitClient().getResponse( request, true );
assertEquals( "1st Response", HttpServletResponse.SC_OK, response.getStatusCode() );
request = new GetMethodWebRequest( "http://machine.com/repository/internal/org/apache/archiva/artifactId/" );
response = getServletUnitClient().getResponse( request );
assertEquals( "2nd Response", HttpServletResponse.SC_OK, response.getStatusCode() );
request = new GetMethodWebRequest(
"http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar" );
response = getServletUnitClient().getResponse( request );
assertEquals( "3rd Response", HttpServletResponse.SC_OK, response.getStatusCode() );
request = new GetMethodWebRequest(
"http://machine.com/repository/internal/org/apache/archiva/artifactId/1.0/artifactId-1.0.jar/" );
response = getServletUnitClient().getResponse( request );
assertEquals( "4th Response", HttpServletResponse.SC_NOT_FOUND, response.getStatusCode() );
}
示例8: testGetFromFirstManagedRepositoryReturnOk
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetFromFirstManagedRepositoryReturnOk()
throws Exception
{
String resourceName = "dummy/dummy-first-resource/1.0/dummy-first-resource-1.0.txt";
File dummyInternalResourceFile = new File( repoRootFirst, resourceName );
dummyInternalResourceFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( dummyInternalResourceFile, "first", Charset.defaultCharset() );
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" );
}
示例9: testGetFromLastManagedRepositoryReturnOk
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetFromLastManagedRepositoryReturnOk()
throws Exception
{
String resourceName = "dummy/dummy-last-resource/1.0/dummy-last-resource-1.0.txt";
File dummyReleasesResourceFile = new File( repoRootLast, resourceName );
dummyReleasesResourceFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( dummyReleasesResourceFile, "last", Charset.defaultCharset() );
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( "last" );
}
示例10: testGetNoProxyTimestampedSnapshotArtifactLegacyLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
throws Exception
{
String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
File artifactFile = new File( repoRootInternal, commonsLangJar );
artifactFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest(
"http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
}
示例11: testGetNoProxyDualExtensionDefaultLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
/**
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
*/
@Test
public void testGetNoProxyDualExtensionDefaultLayout()
throws Exception
{
String expectedContents = "the-contents-of-the-dual-extension";
String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
File checksumFile = new File( repoRootInternal, dualExtensionPath );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
}
示例12: testGetNoProxyDistributionLegacyLayout
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@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";
File checksumFile = new File( repoRootInternal, dualExtensionPath );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest(
"http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
}
示例13: testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
throws Exception
{
String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
String expectedMetadataContents = "dummy-versioned-metadata";
// TODO: find out what this should be from maven-artifact
File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
metadataFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
}
示例14: testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
throws Exception
{
// TODO: find out what it is meant to be from maven-artifact
String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
String expectedMetadataContents = "dummy-project-metadata";
File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
metadataFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
}
示例15: testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy
import com.gargoylesoftware.htmlunit.WebRequest; //导入依赖的package包/类
@Test
public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
throws Exception
{
String commonsLangMetadata = "commons-lang/maven-metadata.xml";
String expectedMetadataContents = "dummy-group-metadata";
File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
metadataFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
}