本文整理匯總了Java中com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException類的典型用法代碼示例。如果您正苦於以下問題:Java FailingHttpStatusCodeException類的具體用法?Java FailingHttpStatusCodeException怎麽用?Java FailingHttpStatusCodeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FailingHttpStatusCodeException類屬於com.gargoylesoftware.htmlunit包,在下文中一共展示了FailingHttpStatusCodeException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: authenticatedAccess
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
*
* @throws Exception
*/
@PresetData(NO_ANONYMOUS_READACCESS)
@Test
public void authenticatedAccess() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
wc.login("alice", "alice");
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例2: validAnonymousViewStatusAccess
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
*
* @throws Exception
*/
@Test
public void validAnonymousViewStatusAccess() throws Exception {
final SecurityRealm realm = j.createDummySecurityRealm();
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
auth.add(VIEW_STATUS, "anonymous");
j.getInstance().setSecurityRealm(realm);
j.getInstance().setAuthorizationStrategy(auth);
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例3: validAnonymousAccess
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
*
* @throws Exception
*/
@PresetData(ANONYMOUS_READONLY)
@Test
public void validAnonymousAccess() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
// try with correct job name
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例4: testFormControllerFail
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
@Test
public void testFormControllerFail() throws Exception {
final HtmlPage page = webClient.getPage(webUrl);
final HtmlForm form = page.getFormByName("form");
final HtmlTextInput name = form.getInputByName("name");
final HtmlTextInput age = form.getInputByName("age");
final HtmlSubmitInput button = form.getInputByName("button");
name.setValueAttribute("john");
age.setValueAttribute("2"); // Not old enough!
try {
button.click();
fail("Validation error expected in form submission");
} catch (FailingHttpStatusCodeException e) {
assertTrue(e.getStatusCode() == 400);
assertTrue(e.getResponse().getContentAsString().contains("<h1>Form Error</h1>"));
assertTrue(e.getResponse().getContentAsString().contains("<p>Param: age</p>"));
}
}
示例5: testFormControllerPropertyFail
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
@Test
public void testFormControllerPropertyFail() throws Exception {
final HtmlPage page = webClient.getPage(webUrl + "indexprop.html");
final HtmlForm form = page.getFormByName("form");
final HtmlTextInput name = form.getInputByName("name");
final HtmlTextInput age = form.getInputByName("age");
final HtmlSubmitInput button = form.getInputByName("button");
name.setValueAttribute("john");
age.setValueAttribute("2"); // Not old enough!
try {
button.click();
fail("Validation error expected in form submission");
} catch (FailingHttpStatusCodeException e) {
assertTrue(e.getStatusCode() == 400);
assertTrue(e.getResponse().getContentAsString().contains("<h1>Form Error</h1>"));
assertTrue(e.getResponse().getContentAsString().contains("<p>Param: age</p>"));
}
}
示例6: testFormFail
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Retrieves a form, removes CSRF hidden field and attempts to submit. Should
* result in a 403 error.
*
* @throws Exception an error occurs or validation fails.
*/
@Test
public void testFormFail() throws Exception {
HtmlPage page1 = webClient.getPage(webUrl + "resources/csrf");
HtmlForm form = (HtmlForm) page1.getDocumentElement().getHtmlElementsByTagName("form").get(0);
// Remove hidden input field to cause a CSRF validation failure
HtmlElement input = form.getHtmlElementsByTagName("input").get(1);
form.removeChild(input);
// Submit form - should fail
HtmlSubmitInput button = (HtmlSubmitInput) form.getHtmlElementsByTagName("input").get(0);
try {
button.click();
fail("CSRF validation should have failed!");
} catch (FailingHttpStatusCodeException e) {
// falls through
}
}
示例7: main
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
public static void main(String[] args) throws FailingHttpStatusCodeException,
MalformedURLException, IOException {
PersonaExtractor extractor = new PersonaExtractor();
Map<String, Persona> personas = null;
Persona persona = null;
try {
extractor.processArgs(args);
String host = extractor.getHost();
if (host == null) {
LOG.info("Extracting all personas");
personas = extractor.obtainPersonasForAllHosts();
for (String personaHost : personas.keySet()) {
LOG.info("Host: [" + personaHost + "]: Personas: "
+ personas.get(host).getUsernames());
}
} else {
persona = extractor.obtainPersonas(extractor.getHost());
LOG.info("Host: [" + host + "]: Personas: " + persona.getUsernames());
}
} catch (CmdLineException e) {
// don't move on
}
}
示例8: loginBySpecialPost
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
protected RespWithTokenJSON loginBySpecialPost() throws FailingHttpStatusCodeException, IOException {
WebRequest wr = new WebRequest(new URL(MP_WEIXIN_LOGIN), HttpMethod.POST);
wr.getAdditionalHeaders().put("Accept", "*/*");
wr.getAdditionalHeaders().put("Accept-Encoding", "gzip, deflate, br");
wr.getAdditionalHeaders().put("Accept-Language", "en-US,en;q=0.5");
wr.getAdditionalHeaders().put("Connection", "keep-alive");
wr.getAdditionalHeaders().put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
wr.getAdditionalHeaders().put("Host", "mp.weixin.qq.com");
wr.getAdditionalHeaders().put("Referer", "https://mp.weixin.qq.com/");
wr.getAdditionalHeaders().put("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0");
wr.getAdditionalHeaders().put("X-Requested-With", "XMLHttpRequest");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("f", "json"));
params.add(new NameValuePair("imgcode", ""));
//here password should be encrypt by MD5 and to lower case
params.add(new NameValuePair("pwd", this.securityNP.getPass()));
params.add(new NameValuePair("username", this.securityNP.getName()));
wr.setRequestParameters(params);
Page page = this.webClient.getPage(wr);
String respJson = page.getWebResponse().getContentAsString();
return RespWithTokenJSON.fromJson(respJson);
}
示例9: JiraSiteHandler
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Constructor of the Jira Site Handler object.
*
* @param tc is the caller test case
* @param environment provide the Environment object of Gepard, it must contain connectivity info to JIRA.
*/
public JiraSiteHandler(final GepardTestClass tc, final Environment environment) {
this.environment = environment;
webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
String phrase = Base64.encode((environment.getProperty(Environment.JIRA_SITE_USERNAME) + ":" + environment.getProperty(Environment.JIRA_SITE_PASSWORD)).getBytes());
webClient.addRequestHeader("Authorization", "Basic " + phrase);
try {
JSONObject serverInfo = getJiraServerInfo();
String serverTitle = serverInfo.get("serverTitle").toString();
String version = serverInfo.get("version").toString();
tc.logComment("Connected to JIRA Server: \"" + serverTitle + "\", version: " + version);
} catch (FailingHttpStatusCodeException | IOException | JSONException e) {
throw new SimpleGepardException("Cannot connect to JIRA properly, pls check the settings, reason: " + e.getMessage(), e);
}
}
示例10: setTicketFieldValue
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
private void setTicketFieldValue(final GepardTestClass tc, final String ticket, final String fieldName, final String value) throws IOException {
String jiraSetFieldPage = getIssueFieldSetValueUrl(ticket);
WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.PUT);
requestSettings.setAdditionalHeader("Content-type", "application/json");
requestSettings.setRequestBody("{ \"fields\": {\"" + fieldName + "\": \"" + value + "\"} }");
try {
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
tc.logComment("Field: '" + fieldName + "' of Ticket: " + ticket + " was updated to value: '" + value + "' successfully.");
} else {
throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed, status code: " + infoPage.getWebResponse().getStatusCode());
}
} catch (FailingHttpStatusCodeException e) {
throw new SimpleGepardException("Ticket: " + ticket + " field: " + fieldName + " update failed.", e);
}
}
示例11: transferTicketToStatus
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Transition a ticket to next status in its workflow.
* URL --> https://jira.xxxxxx.com/rest/api/2/issue/TEST-53/transitions?expand=transitions.fields
* POST data --> {"transition":{"id":91}}
* Returned HTTP response --> 204
*
* @param ticket is the specific ticket
* @param statusTransferId is the id of the transaction that should be used to transfer the ticket
* @param expectedStatusName is the name of the expected new status
* @param comment that will be attached to the ticket as comment of the transaction
* @return with the new status
*/
private String transferTicketToStatus(final GepardTestClass tc, final String ticket, final String statusTransferId, final String expectedStatusName, final String comment)
throws IOException, JSONException {
String updateString = "{ \"update\": { \"comment\": [ { \"add\": { \"body\": \"" + comment + "\" } } ] }, \"transition\": { \"id\": \"" + statusTransferId + "\" } }";
String oldStatus = detectActualStatus(ticket);
String newStatus;
String jiraSetFieldPage = getIssueSetTransitionsUrl(ticket);
WebRequest requestSettings = new WebRequest(new URL(jiraSetFieldPage), HttpMethod.POST);
requestSettings.setAdditionalHeader("Content-type", "application/json");
requestSettings.setRequestBody(updateString);
try {
UnexpectedPage infoPage = webClient.getPage(requestSettings);
if (infoPage.getWebResponse().getStatusCode() == HTTP_RESPONSE_OK) {
newStatus = detectActualStatus(ticket);
Assert.assertEquals("Transferring ticket: " + ticket + " to new status failed,", expectedStatusName, newStatus);
tc.logComment("Ticket: " + ticket + " was transferred from status: \"" + oldStatus + "\" to status: \"" + newStatus + "\" successfully.");
} else {
throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ", Status code:" + infoPage.getWebResponse().getStatusCode());
}
} catch (FailingHttpStatusCodeException e) {
throw new SimpleGepardException("ERROR: Status update failed for ticket: " + ticket + ".", e);
}
return newStatus;
}
示例12: testDelete
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Tests an add/edit/delete sequence.
*
* @throws IOException in case of IO error.
*/
@Test
public void testDelete() throws IOException {
String viewUrl = "http://localhost/collections/view/1";
HtmlPage page = getWebClient().getPage(viewUrl);
// Delete
page = deleteWithQuickTask(page, "qt-delete-collection");
// Check redirect after delete. Must be to the publisher index, as there is no collection indec
assertThat(page.getUrl().toString()).matches(".*/publishers/$");
try {
getWebClient().getPage(viewUrl);
Assertions.fail("Should have gotten a 404 error");
} catch (FailingHttpStatusCodeException e) {
assertThat(e.getStatusCode()).isEqualTo(HttpServletResponse.SC_NOT_FOUND);
}
}
示例13: cleanElasticTest
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Not test exactly, just cleaning old data in elastic
*
* @param context
* @throws Exception
*/
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 8)
@OperateOnDeployment("ear")
@RunAsClient
public void cleanElasticTest(@ArquillianResource URL context) throws Exception {
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(
new URL("http://" + System.getenv("SINKIT_ELASTIC_HOST") + ":" + System.getenv("SINKIT_ELASTIC_PORT") +
"/" + ArchiveServiceEJB.ELASTIC_IOC_INDEX + "/"), HttpMethod.DELETE);
Page page;
try {
page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
} catch (FailingHttpStatusCodeException ex) {
//NO-OP index does not exist yet, but it's ok
}
}
示例14: cleanElasticTest
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Not test exactly, just cleaning old data in elastic DNS event logs
*
* @param context
* @throws Exception
*/
@Test(enabled = false, dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER, priority = 17)
@OperateOnDeployment("ear")
@RunAsClient
public void cleanElasticTest(@ArquillianResource URL context) throws Exception {
String index = IoCFactory.getLogIndex();
WebClient webClient = new WebClient();
WebRequest requestSettings = new WebRequest(
new URL("http://" + System.getenv("SINKIT_ELASTIC_HOST") + ":" + System.getenv("SINKIT_ELASTIC_PORT") +
"/" + index + "/"), HttpMethod.DELETE);
Page page;
try {
page = webClient.getPage(requestSettings);
assertEquals(HttpURLConnection.HTTP_OK, page.getWebResponse().getStatusCode());
} catch (FailingHttpStatusCodeException ex) {
//NO-OP index does not exist yet, but it's ok
}
}
示例15: authenticateWithInvalidCredentials
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; //導入依賴的package包/類
/**
* Test authenticating a user logging in using invalid credentials.
*/
@Test
public void authenticateWithInvalidCredentials() throws Exception {
// make GitLab respond with the current user for connection test
stubFor(get(urlEqualTo("/api/v3/user?private_token=private_token"))
.willReturn(aResponse()
.withStatus(200)
.withBodyFile("/api/v3/user.json")));
// make GitLab respond with an HTTP 401 Unauthorized
stubFor(post(urlEqualTo("/api/v3/session"))
.withRequestBody(containing("login=invalidusername"))
.withRequestBody(containing("password=invalidpassword"))
.willReturn(aResponse()
.withStatus(401)));
// login should fail with HTTP 401 Unauthorized
thrown.expect(FailingHttpStatusCodeException.class);
thrown.expectMessage("401");
webClient.login("invalidusername", "invalidpassword");
}