Search in sources :

Example 86 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.

the class JSONIOTest method writeFile.

@Test
public void writeFile() throws ManipulationException, IOException {
    DocumentContext doc = jsonIO.parseJSON(npmFile);
    File target = tf.newFile();
    jsonIO.writeJSON(target, doc.jsonString());
    assertTrue(FileUtils.contentEquals(npmFile, target));
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) File(java.io.File) Test(org.junit.Test)

Example 87 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.

the class JSONIOTest method readFile.

@Test
public void readFile() throws ManipulationException, IOException {
    DocumentContext o = jsonIO.parseJSON(npmFile);
    logger.debug("Read {} ", o.jsonString());
    logger.debug("File {}", FileUtils.readFileToString(npmFile));
    // They won't be equal as jsonString is not pretty printed.
    assertNotEquals(o.jsonString(), FileUtils.readFileToString(npmFile));
    assertTrue(o != null);
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 88 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.

the class JSONIOTest method updateURL.

@Test
public void updateURL() throws ManipulationException, IOException {
    String modifyPath = "$.repository.url";
    DocumentContext doc = jsonIO.parseJSON(pluginFile);
    doc.set(modifyPath, "https://maven.repository.redhat.com/ga/");
    logger.debug("Modified {} ", doc.jsonString());
    File target = tf.newFile();
    jsonIO.writeJSON(target, doc.jsonString());
    assertTrue(doc.jsonString().contains("https://maven.repository.redhat.com/ga/"));
    assertTrue(doc.jsonString().contains("1.2.2-SNAPSHOT"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) File(java.io.File) Test(org.junit.Test)

Example 89 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.

the class JSONIOTest method updateVersions.

@Test
public void updateVersions() throws ManipulationException, IOException {
    String modifyPath = "$..version";
    DocumentContext doc = jsonIO.parseJSON(pluginFile);
    doc.set(modifyPath, "1.3.0.rebuild-1");
    logger.debug("Modified {} ", doc.jsonString());
    File target = tf.newFile();
    jsonIO.writeJSON(target, doc.jsonString());
    assertTrue(!doc.jsonString().contains("1.2.2-SNAPSHOT"));
    assertTrue(doc.jsonString().contains("1.3.0.rebuild-1"));
    assertFalse(FileUtils.contentEquals(pluginFile, target));
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) File(java.io.File) Test(org.junit.Test)

Example 90 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.

the class JSONIOTest method updateWithInvalidPath.

@Test(expected = ManipulationException.class)
public void updateWithInvalidPath() throws ManipulationException, IOException {
    String modifyPath = "$.I.really.do.not.exist.repository.url";
    try {
        DocumentContext doc = jsonIO.parseJSON(pluginFile);
        doc.set(modifyPath, "https://maven.repository.redhat.com/ga/");
    } catch (JsonPathException e) {
        throw new ManipulationException("Caught JsonPath", e);
    }
}
Also used : JsonPathException(com.jayway.jsonpath.JsonPathException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Aggregations

DocumentContext (com.jayway.jsonpath.DocumentContext)146 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)8 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 InvalidJsonException (com.jayway.jsonpath.InvalidJsonException)4