本文整理匯總了Java中com.jayway.restassured.http.ContentType類的典型用法代碼示例。如果您正苦於以下問題:Java ContentType類的具體用法?Java ContentType怎麽用?Java ContentType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ContentType類屬於com.jayway.restassured.http包,在下文中一共展示了ContentType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: completeMultipart
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
public String completeMultipart(String stagingUrl, String path, String uploadId, List<Integer> partNums,
List<String> etags)
{
ObjectNode request = newObject();
ArrayNode parts = newArray();
request.put("parts", parts);
int i = 0;
for( Integer partNum : partNums )
{
String etag = etags.get(i++);
ObjectNode partObj = newObject();
partObj.put("partNumber", partNum);
partObj.put("etag", etag);
parts.add(partObj);
}
return successfulRequest().content(request).contentType(ContentType.JSON).queryParam("uploadId", uploadId)
.post(getFileUrl(stagingUrl, path)).getHeader("E-Tag");
}
示例2: setUp
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
/**
* Initial Setup
*/
@Before
public void setUp() {
this.activeProfile = RestUtil.getCurrentProfile();
this.conf = ConfigFactory.load("application-" + this.activeProfile);
this.baseURI = conf.getString("server.baseURI");
this.port = conf.getInt("server.port");
this.timeout = conf.getInt("service.api.timeout");
final RequestSpecBuilder build = new RequestSpecBuilder().setBaseUri(baseURI).setPort(port);
rspec = build.build();
RestAssured.config = new RestAssuredConfig().encoderConfig(encoderConfig().defaultContentCharset("UTF-8")
.encodeContentTypeAs("application-json", ContentType.JSON));
}
示例3: createDataverse
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
private static Response createDataverse(TestDataverse dataverseToCreate, TestUser creator) {
JsonArrayBuilder contactArrayBuilder = Json.createArrayBuilder();
contactArrayBuilder.add(Json.createObjectBuilder().add("contactEmail", creator.getEmail()));
JsonArrayBuilder subjectArrayBuilder = Json.createArrayBuilder();
subjectArrayBuilder.add("Other");
JsonObject dvData = Json.createObjectBuilder()
.add("alias", dataverseToCreate.alias)
.add("name", dataverseToCreate.name)
.add("dataverseContacts", contactArrayBuilder)
.add("dataverseSubjects", subjectArrayBuilder)
.build();
Response createDataverseResponse = given()
.body(dvData.toString()).contentType(ContentType.JSON)
.when().post("/api/dataverses/:root?key=" + creator.apiToken);
return createDataverseResponse;
}
示例4: shouldSuccess_WhenAllRequiredFieldsAreProvidedAndValid
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void shouldSuccess_WhenAllRequiredFieldsAreProvidedAndValid() throws Exception {
String email = "[email protected]";
String telephoneNumber = "088882345689";
ImmutableMap<String, String> payload = ImmutableMap.of("telephone_number", telephoneNumber, "email", email, "password", "plain_text_password");
givenSetup()
.when()
.body(mapper.writeValueAsString(payload))
.contentType(ContentType.JSON)
.post(SERVICE_INVITES_CREATE_URL)
.then()
.statusCode(CREATED.getStatusCode())
.body("email", is(email.toLowerCase()))
.body("telephone_number", is(telephoneNumber))
.body("_links", hasSize(2))
.body("_links[0].href", matchesPattern("^https://selfservice.pymnt.localdomain/invites/[0-9a-z]{32}$"))
.body("_links[0].method", is("GET"))
.body("_links[0].rel", is("invite"));
}
示例5: shouldFail_WhenEmailIsNotPublicSectorDomain
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void shouldFail_WhenEmailIsNotPublicSectorDomain() throws Exception {
String email = "[email protected]";
String telephoneNumber = "088882345689";
ImmutableMap<String, String> payload = ImmutableMap.of("telephone_number", telephoneNumber, "email", email, "password", "plain_text_password");
givenSetup()
.when()
.body(mapper.writeValueAsString(payload))
.contentType(ContentType.JSON)
.post(SERVICE_INVITES_CREATE_URL)
.then()
.statusCode(FORBIDDEN.getStatusCode())
.body("errors", hasSize(1))
.body("errors", hasItems("Email [[email protected]] is not a valid public sector email"));
}
示例6: shouldFail_WhenEmailIsAlreadyRegistered
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void shouldFail_WhenEmailIsAlreadyRegistered() throws Exception {
String email = "[email protected]";
UserDbFixture.userDbFixture(databaseHelper).withEmail(email).insertUser();
String telephoneNumber = "088882345689";
ImmutableMap<String, String> payload = ImmutableMap.of("telephone_number", telephoneNumber, "email", email, "password", "plain_text_password");
givenSetup()
.when()
.body(mapper.writeValueAsString(payload))
.contentType(ContentType.JSON)
.post(SERVICE_INVITES_CREATE_URL)
.then()
.statusCode(CONFLICT.getStatusCode())
.body("errors", hasSize(1))
.body("errors", hasItems("email [[email protected]] already exists"));
}
示例7: validateOtp_shouldFail_whenInvalidOtpAuthCode
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void validateOtp_shouldFail_whenInvalidOtpAuthCode() throws Exception {
// create an invitation
code = InviteDbFixture.inviteDbFixture(databaseHelper)
.withEmail(EMAIL)
.withOtpKey(OTP_KEY)
.withTelephoneNumber(TELEPHONE_NUMBER)
.withPassword(PASSWORD)
.insertInvite();
// generate invalid invitationOtpRequest and execute it
ImmutableMap<Object, Object> invitationOtpRequest = ImmutableMap.builder()
.put("code", code)
.put("otp", 123456)
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationOtpRequest))
.contentType(ContentType.JSON)
.post(INVITES_VALIDATE_OTP_RESOURCE_URL)
.then()
.statusCode(UNAUTHORIZED.getStatusCode());
}
示例8: validateServiceOtpKey_shouldSucceed_whenValidOtp
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void validateServiceOtpKey_shouldSucceed_whenValidOtp() throws Exception {
code = InviteDbFixture.inviteDbFixture(databaseHelper)
.withOtpKey(OTP_KEY)
.insertInvite();
ImmutableMap<Object, Object> sendRequest = ImmutableMap.builder()
.put("code", code)
.put("otp", PASSCODE)
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(sendRequest))
.contentType(ContentType.JSON)
.post(SERVICE_INVITES_VALIDATE_OTP_RESOURCE_URL)
.then()
.statusCode(OK.getStatusCode());
}
示例9: validateServiceOtpKey_shouldFailWith401_whenInvalidOtp
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void validateServiceOtpKey_shouldFailWith401_whenInvalidOtp() throws Exception {
code = InviteDbFixture.inviteDbFixture(databaseHelper)
.withOtpKey(OTP_KEY)
.insertInvite();
int invalidOtp = 111111;
ImmutableMap<Object, Object> sendRequest = ImmutableMap.builder()
.put("code", code)
.put("otp", invalidOtp)
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(sendRequest))
.contentType(ContentType.JSON)
.post(SERVICE_INVITES_VALIDATE_OTP_RESOURCE_URL)
.then()
.statusCode(UNAUTHORIZED.getStatusCode());
}
示例10: createInvitation_shouldSucceed_whenInvitingANewUser
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void createInvitation_shouldSucceed_whenInvitingANewUser() throws Exception {
String email = randomAlphanumeric(5) + "[email protected]";
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("sender", senderExternalId)
.put("email", email)
.put("role_name", roleAdminName)
.put("service_external_id", service.getExternalId())
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.post(INVITE_USER_RESOURCE_URL)
.then()
.statusCode(CREATED.getStatusCode())
.body("email", is(email.toLowerCase()))
.body("telephone_number", is(nullValue()))
.body("_links", hasSize(1))
.body("_links[0].href", matchesPattern("^https://selfservice.pymnt.localdomain/invites/[0-9a-z]{32}$"))
.body("_links[0].method", is("GET"))
.body("_links[0].rel", is("invite"));
}
示例11: createInvitation_shouldFail_whenServiceDoesNotExist
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void createInvitation_shouldFail_whenServiceDoesNotExist() throws Exception {
String nonExistentServiceId = "non existant service external id";
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("sender", senderExternalId)
.put("email", randomAlphanumeric(5) + "[email protected]")
.put("role_name", roleAdminName)
.put("service_external_id", nonExistentServiceId)
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.post(INVITE_USER_RESOURCE_URL)
.then()
.statusCode(NOT_FOUND.getStatusCode())
.body(isEmptyString());
}
示例12: createInvitation_shouldFail_whenRoleDoesNotExist
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void createInvitation_shouldFail_whenRoleDoesNotExist() throws Exception {
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("sender", senderExternalId)
.put("email", randomAlphanumeric(5) + "[email protected]")
.put("role_name", "non-existing-role")
.put("service_external_id", service.getExternalId())
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.post(INVITE_USER_RESOURCE_URL)
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.body("errors", hasSize(1))
.body("errors", hasItems("role [non-existing-role] not recognised"));
}
示例13: createInvitation_shouldFail_whenSenderDoesNotExist
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void createInvitation_shouldFail_whenSenderDoesNotExist() throws Exception {
String email = randomAlphanumeric(5) + "[email protected]";
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("sender", "does-not-exist")
.put("email", email)
.put("role_name", roleAdminName)
.put("service_external_id", service.getExternalId())
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.post(INVITE_USER_RESOURCE_URL)
.then()
.statusCode(FORBIDDEN.getStatusCode());
}
示例14: createInvitation_shouldFail_whenSenderDoesNotHaveAdminRole
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void createInvitation_shouldFail_whenSenderDoesNotHaveAdminRole() throws Exception {
int otherRoleId = roleDbFixture(databaseHelper).insertRole().getId();
String senderWithNoAdminRole = userDbFixture(databaseHelper)
.withServiceRole(service.getId(), otherRoleId)
.insertUser().getExternalId();
String email = randomAlphanumeric(5) + "[email protected]";
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("sender", senderWithNoAdminRole)
.put("email", email)
.put("role_name", roleAdminName)
.put("service_external_id", service.getExternalId())
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.post(INVITE_USER_RESOURCE_URL)
.then()
.statusCode(FORBIDDEN.getStatusCode());
}
示例15: generateOtp_shouldSucceed_forUserInvite_evenWhenTokenIsExpired_sinceItShouldBeValidatedOnGetInvite
import com.jayway.restassured.http.ContentType; //導入依賴的package包/類
@Test
public void generateOtp_shouldSucceed_forUserInvite_evenWhenTokenIsExpired_sinceItShouldBeValidatedOnGetInvite() throws Exception {
givenAnExistingUserInvite();
ImmutableMap<Object, Object> invitationRequest = ImmutableMap.builder()
.put("telephone_number", TELEPHONE_NUMBER)
.put("password", PASSWORD)
.build();
givenSetup()
.when()
.body(mapper.writeValueAsString(invitationRequest))
.contentType(ContentType.JSON)
.post(format(INVITES_GENERATE_OTP_RESOURCE_URL, code))
.then()
.statusCode(OK.getStatusCode());
}