You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/10/07 20:00:15 UTC
[groovy] branch GROOVY-8258 updated: GROOVY-8258: add a test case
for querying json
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-8258
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-8258 by this push:
new 55d3207 GROOVY-8258: add a test case for querying json
55d3207 is described below
commit 55d320704119c478f4c8ffd203b74d210725f408
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Oct 8 03:59:53 2020 +0800
GROOVY-8258: add a test case for querying json
---
subprojects/groovy-linq/build.gradle | 1 +
.../groovy/org/apache/groovy/linq/GinqTest.groovy | 38 +++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/subprojects/groovy-linq/build.gradle b/subprojects/groovy-linq/build.gradle
index cc476c4..6a7aabb 100644
--- a/subprojects/groovy-linq/build.gradle
+++ b/subprojects/groovy-linq/build.gradle
@@ -22,6 +22,7 @@ dependencies {
implementation project(':groovy-macro')
testImplementation rootProject.sourceSets.test.runtimeClasspath
testImplementation project(':groovy-test')
+ testImplementation project(':groovy-json')
}
task moduleDescriptor(type: org.codehaus.groovy.gradle.WriteExtensionDescriptorTask) {
diff --git a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
index 1863d18..91c59fa 100644
--- a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
+++ b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
@@ -18,7 +18,8 @@
*/
package org.apache.groovy.linq
-
+import groovy.json.JsonSlurper
+import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.junit.Test
@@ -1032,4 +1033,39 @@ class GinqTest {
}.toList()
'''
}
+
+ @CompileDynamic
+ @Test
+ void "testGinq - query json - 1"() {
+ def parser = new JsonSlurper()
+ def json = parser.parseText('''
+ {
+ "persons": [
+ {"id": 1, "name": "Daniel"},
+ {"id": 2, "name": "Paul"},
+ {"id": 3, "name": "Eric"}
+ ],
+ "tasks": [
+ {"id": 1, "assignee": 1, "content": "task1"},
+ {"id": 2, "assignee": 1, "content": "task2"},
+ {"id": 3, "assignee": 2, "content": "task3"},
+ {"id": 4, "assignee": 3, "content": "task4"}
+ ]
+ }
+ ''')
+
+ def expected = [
+ [taskId: 1, taskContent: 'task1', assignee: 'Daniel'],
+ [taskId: 3, taskContent: 'task3', assignee: 'Paul'],
+ [taskId: 4, taskContent: 'task4', assignee: 'Eric']
+ ]
+
+ assert expected == GINQ {
+ from p in json.persons
+ innerJoin t in json.tasks
+ on t.assignee == p.id
+ where t.id in [1, 3, 4]
+ select (taskId: t.id, taskContent: t.content, assignee: p.name)
+ }.toList()
+ }
}