本文整理汇总了Java中org.apache.commons.text.StringEscapeUtils.escapeJava方法的典型用法代码示例。如果您正苦于以下问题:Java StringEscapeUtils.escapeJava方法的具体用法?Java StringEscapeUtils.escapeJava怎么用?Java StringEscapeUtils.escapeJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.text.StringEscapeUtils
的用法示例。
在下文中一共展示了StringEscapeUtils.escapeJava方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeNottableString
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
public static String serializeNottableString(NottableString nottableString) {
if (nottableString.isNot()) {
return "not(\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\")";
} else {
return "\"" + StringEscapeUtils.escapeJava(nottableString.getValue()) + "\"";
}
}
示例2: shouldDeserializeCompleteResponse
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldDeserializeCompleteResponse() throws IOException, ClassNotFoundException {
// given
String requestBytes = "{" + NEW_LINE +
" \"type\" : \"org.mockserver.model.HttpResponse\"," + NEW_LINE +
" \"value\" : \"{" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"statusCode\\\" : 123," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"headers\\\" : [ {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"name\\\" : \\\"someHeaderName\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"values\\\" : [ \\\"someHeaderValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
" } ]," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"cookies\\\" : [ {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"name\\\" : \\\"someCookieName\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"value\\\" : \\\"someCookieValue\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
" } ]," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"body\\\" : \\\"somebody\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"delay\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"timeUnit\\\" : \\\"SECONDS\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"value\\\" : 5" + StringEscapeUtils.escapeJava(NEW_LINE) +
" }" + StringEscapeUtils.escapeJava(NEW_LINE) +
"}\"" + NEW_LINE +
"}";
// when
Object httpResponse = new WebSocketMessageSerializer(new MockServerLogger()).deserialize(requestBytes);
// then
assertEquals(new HttpResponseDTO()
.setStatusCode(123)
.setBody(BodyWithContentTypeDTO.createDTO(exact("somebody")))
.setHeaders(new Headers().withEntries(
header("someHeaderName", "someHeaderValue")
))
.setCookies(new Cookies().withEntries(
cookie("someCookieName", "someCookieValue")
))
.setDelay(new DelayDTO(seconds(5)))
.buildObject(), httpResponse);
}
示例3: shouldParseJsonWithJsonSchemaBodyWithNot
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyWithNot() throws IOException {
// given
String jsonSchema = "{" + NEW_LINE +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"not\" : true," + NEW_LINE +
" \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
assertEquals(new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema), true))
), expectationDTO);
}
示例4: shouldParseJsonWithJsonSchemaBodyWithoutType
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyWithoutType() throws IOException {
// given
String jsonSchema = "{" + NEW_LINE +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
assertEquals(new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema)))
), expectationDTO);
}
示例5: shouldParseJsonWithJsonSchemaBodyUsingJsonProperty
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithJsonSchemaBodyUsingJsonProperty() throws IOException {
// given
String jsonSchema = "{" + NEW_LINE +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"type\" : \"JSON_SCHEMA\"," + NEW_LINE +
" \"jsonSchema\" : \"" + StringEscapeUtils.escapeJava(jsonSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
assertEquals(new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new JsonSchemaBodyDTO(new JsonSchemaBody(jsonSchema)))
), expectationDTO);
}
示例6: shouldParseJsonWithXmlSchemaBodyWithNot
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyWithNot() throws IOException {
// given
String xmlSchema = "{" + NEW_LINE +
" \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"not\" : true," + NEW_LINE +
" \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
assertEquals(new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema), true))
), expectationDTO);
}
示例7: shouldParseJsonWithXmlSchemaBodyWithoutType
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyWithoutType() throws IOException {
// given
String xmlSchema = "{" + NEW_LINE +
" \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
assertEquals(new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema)))
), expectationDTO);
}
示例8: shouldParseJsonWithXmlSchemaBodyUsingJsonProperty
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldParseJsonWithXmlSchemaBodyUsingJsonProperty() throws IOException {
// given
String xmlSchema = "{" + NEW_LINE +
" \"$schema\": \"http://xml-schema.org/draft-04/schema#\"," + NEW_LINE +
" \"title\": \"Product\"," + NEW_LINE +
" \"description\": \"A product from Acme's catalog\"," + NEW_LINE +
" \"type\": \"object\"," + NEW_LINE +
" \"properties\": {" + NEW_LINE +
" \"id\": {" + NEW_LINE +
" \"description\": \"The unique identifier for a product\"," + NEW_LINE +
" \"type\": \"integer\"" + NEW_LINE +
" }" + NEW_LINE +
" }," + NEW_LINE +
" \"required\": [\"id\"]" + NEW_LINE +
"}";
String json = ("{" + NEW_LINE +
" \"httpRequest\": {" + NEW_LINE +
" \"body\" : {" + NEW_LINE +
" \"type\" : \"XML_SCHEMA\"," + NEW_LINE +
" \"xmlSchema\" : \"" + StringEscapeUtils.escapeJava(xmlSchema) + "\"" + NEW_LINE +
" }" + NEW_LINE +
" }" + NEW_LINE +
"}");
// when
ExpectationDTO expectationDTO = ObjectMapperFactory.createObjectMapper().readValue(json, ExpectationDTO.class);
// then
final ExpectationDTO expected = new ExpectationDTO()
.setHttpRequest(
new HttpRequestDTO()
.setBody(new XmlSchemaBodyDTO(new XmlSchemaBody(xmlSchema)))
);
assertEquals(expected, expectationDTO);
}
示例9: shouldDeserializeCompleteRequest
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
@Test
public void shouldDeserializeCompleteRequest() throws IOException, ClassNotFoundException {
// given
String requestBytes = "{" + NEW_LINE +
" \"type\" : \"org.mockserver.model.HttpRequest\"," + NEW_LINE +
" \"value\" : \"{" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"method\\\" : \\\"someMethod\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"path\\\" : \\\"somePath\\\"," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"queryStringParameters\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"queryParameterName\\\" : [ \\\"queryParameterValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
" }," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"headers\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"someHeaderName\\\" : [ \\\"someHeaderValue\\\" ]" + StringEscapeUtils.escapeJava(NEW_LINE) +
" }," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"cookies\\\" : {" + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"someCookieName\\\" : \\\"someCookieValue\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
" }," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"keepAlive\\\" : false," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"secure\\\" : true," + StringEscapeUtils.escapeJava(NEW_LINE) +
" \\\"body\\\" : \\\"somebody\\\"" + StringEscapeUtils.escapeJava(NEW_LINE) +
"}\"" + NEW_LINE +
"}";
// when
Object httpRequest = new WebSocketMessageSerializer(new MockServerLogger()).deserialize(requestBytes);
// then
assertEquals(new HttpRequestDTO()
.setMethod(string("someMethod"))
.setPath(string("somePath"))
.setQueryStringParameters(new Parameters().withEntries(
param("queryParameterName", "queryParameterValue")
))
.setBody(BodyDTO.createDTO(exact("somebody")))
.setHeaders(new Headers().withEntries(
header("someHeaderName", "someHeaderValue")
))
.setCookies(new Cookies().withEntries(
cookie("someCookieName", "someCookieValue")
))
.setSecure(true)
.setKeepAlive(false)
.buildObject(), httpRequest);
}
示例10: jsonEncode
import org.apache.commons.text.StringEscapeUtils; //导入方法依赖的package包/类
/**
* Escaped the given JSON content using Java String rules.
*
* Assumes " is used as quote char and not used inside values and does
* not escape '.
*
* @param object the String.
* @return the escaped representation.
*/
public String jsonEncode( String object )
{
return StringEscapeUtils.escapeJava( object );
}