Search in sources :

Example 31 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project spring-cloud-open-service-broker by spring-cloud.

the class UpdateServiceInstanceResponseTest method responseWithAllValuesIsBuilt.

@Test
public void responseWithAllValuesIsBuilt() {
    UpdateServiceInstanceResponse response = UpdateServiceInstanceResponse.builder().async(true).operation("in progress").build();
    assertThat(response.isAsync()).isEqualTo(true);
    assertThat(response.getOperation()).isEqualTo("in progress");
    DocumentContext json = JsonUtils.toJsonPath(response);
    assertThat(json).hasPath("$.operation").isEqualTo("in progress");
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 32 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project fabric8-maven-plugin by fabric8io.

the class Verify method verifyResourceDescriptors.

public static void verifyResourceDescriptors(File actualPath, File expectedPath, boolean strict) throws IOException, ParseException {
    String actualText = readFile(actualPath);
    String expectedText = readFile(expectedPath);
    JsonTextMessageValidator validator = new JsonTextMessageValidator();
    validator.setStrict(strict);
    DocumentContext actualContext = JsonPath.parse(actualText);
    validator.validateJson(newMessage(actualText), newMessage(expectedText), new JsonMessageValidationContext(), createTestContext(), actualContext);
}
Also used : JsonTextMessageValidator(com.consol.citrus.validation.json.JsonTextMessageValidator) JsonMessageValidationContext(com.consol.citrus.validation.json.JsonMessageValidationContext) DocumentContext(com.jayway.jsonpath.DocumentContext)

Example 33 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project connectors-workspace-one by vmware.

the class SalesforceControllerTest method getAccountRequestSoql.

private String getAccountRequestSoql(String filePath) throws IOException {
    DocumentContext ctx = JsonPath.parse(fromFile(filePath));
    final String senderDomain = '@' + StringUtils.substringAfterLast(senderEmail(ctx), "@");
    return String.format(QUERY_FMT_ACCOUNT, senderDomain, userEmail(ctx));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DocumentContext(com.jayway.jsonpath.DocumentContext)

Example 34 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project solr-cmd-utils by tblsoft.

the class JsonPathReader method loadJsonContext.

protected DocumentContext loadJsonContext() throws IOException {
    DocumentContext context = null;
    String url = getProperty("url", null);
    String filename = getProperty("filename", null);
    if (StringUtils.isNotEmpty(url)) {
        // @todo jsonBody has encoding bug
        String jsonBody = HTTPHelper.get(url);
        context = JsonPath.parse(jsonBody);
    } else if (StringUtils.isNotEmpty(filename)) {
        File jsonFile = IOUtils.getAbsoluteFileAsFile(getBaseDir(), filename);
        context = JsonPath.parse(jsonFile);
    }
    return context;
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) File(java.io.File)

Example 35 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project JsonPath by json-path.

the class IssuesTest method issue_97.

@Test
public void issue_97() throws Exception {
    String json = "{ \"books\": [ " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"fiction\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" }, " + "{ \"category\": \"reference\" } ]  }";
    Configuration conf = Configuration.builder().jsonProvider(new GsonJsonProvider()).mappingProvider(new GsonMappingProvider()).build();
    DocumentContext context = JsonPath.using(conf).parse(json);
    context.delete("$.books[?(@.category == 'reference')]");
    List<String> categories = context.read("$..category", List.class);
    assertThat(categories).containsOnly("fiction");
}
Also used : GsonMappingProvider(com.jayway.jsonpath.spi.mapper.GsonMappingProvider) Configuration(com.jayway.jsonpath.Configuration) GsonJsonProvider(com.jayway.jsonpath.spi.json.GsonJsonProvider) DocumentContext(com.jayway.jsonpath.DocumentContext) BaseTest(com.jayway.jsonpath.BaseTest) Test(org.junit.Test)

Aggregations

DocumentContext (com.jayway.jsonpath.DocumentContext)150 Test (org.junit.Test)106 HashMap (java.util.HashMap)14 BaseTest (com.jayway.jsonpath.BaseTest)12 Map (java.util.Map)12 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)9 JsonPath (com.jayway.jsonpath.JsonPath)7 File (java.io.File)7 List (java.util.List)7 JsonPathAssert (com.revinate.assertj.json.JsonPathAssert)6 Query (org.graylog.plugins.views.search.Query)6 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)6 Time (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time)6 Values (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values)6 DateTime (org.joda.time.DateTime)6 Configuration (com.jayway.jsonpath.Configuration)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 IOException (java.io.IOException)4