Closed donbeave closed 6 years ago
Seems testing has been failed. :)
And also, I think it's better to remove gson
dependency, and replace it to JSONObject
which is provied by Grails
itself, so this would be help to reduce the dependencies size. :)
And I did it, but I'm not fix the testing for now. I will upload my patch later.
@abcfy2 build fixed
OK. Here is my patch from your branch for now. I try to remove gson
dependency, and move test/
to src/integration-test/
, and all tests passed in my local environment. Please git apply
this patch and check if working?
diff --git a/build.gradle b/build.gradle
index 3422e22..46c84bc 100644
--- a/build.gradle
+++ b/build.gradle
@@ -75,11 +75,10 @@ dependencies {
profile 'org.grails.profiles:web-plugin'
provided 'org.grails:grails-plugin-services'
provided 'org.grails:grails-plugin-domain-class'
+ provided 'org.postgresql:postgresql:42.2.2'
testCompile 'org.grails:grails-plugin-testing'
testCompile 'org.grails:grails-gorm-testing-support'
- provided 'org.postgresql:postgresql:42.2.2'
-
// plugins
provided 'org.grails.plugins:hibernate5'
@@ -88,7 +87,6 @@ dependencies {
provided("org.hibernate:hibernate-ehcache:$hibernateVersion") {
exclude group: 'net.sf.ehcache', module: 'ehcache'
}
- compile 'com.google.code.gson:gson:2.8.4'
}
task wrapper(type: Wrapper) {
diff --git a/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy
new file mode 100644
index 0000000..f5ffa91
--- /dev/null
+++ b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy
@@ -0,0 +1,57 @@
+package net.kaleidos.hibernate.json
+
+import grails.gorm.transactions.Rollback
+import grails.testing.mixin.integration.Integration
+import spock.lang.Specification
+import spock.lang.Unroll
+import test.json.TestMapJson
+
+@Integration
+@Rollback
+class PgJsonPathsIntegrationSpec extends Specification {
+
+ def pgJsonTestSearchService
+
+ @Unroll
+ void 'Test equals finding nested values (json): a'() {
+ setup:
+ new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
+ new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
+ new TestMapJson(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
+
+ when:
+ def result = pgJsonTestSearchService.search('pgJson', 'data', '#>>', '{nested, a}', '=', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.nested.a == value }
+
+ where:
+ value || size
+ 1 || 2 // there are 2 items with nested.a equal to 1
+ 2 || 1
+ 3 || 0
+ }
+
+ @Unroll
+ void 'Test equals finding nested values (json): b'() {
+ setup:
+ new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
+ new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
+ new TestMapJson(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
+
+ when:
+ def result = pgJsonTestSearchService.search('pgJson', 'data', '#>>', '{nested, b}', '>', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.nested.b > value.toInteger() }
+
+ where:
+ value || size
+ 1 || 3 // There are 3 items with nested.b > 1
+ 3 || 1
+ 6 || 0
+ }
+
+}
diff --git a/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy
new file mode 100644
index 0000000..2cd9a08
--- /dev/null
+++ b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy
@@ -0,0 +1,75 @@
+package net.kaleidos.hibernate.json
+
+import grails.gorm.transactions.Rollback
+import grails.testing.mixin.integration.Integration
+import spock.lang.Specification
+import spock.lang.Unroll
+import test.json.TestMapJson
+
+@Integration
+@Rollback
+class PgJsonValuesIntegrationSpec extends Specification {
+
+ def pgJsonTestSearchService
+
+ @Unroll
+ void 'Test equals finding value: #value with condition is ilike (json)'() {
+ setup:
+ new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', 'ilike', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name.matches "^(?i)${value.replace('%', '.*')}\$" }
+
+ where:
+ value || size
+ '%iv%' || 2
+ 'John' || 0
+ }
+
+ @Unroll
+ void 'Test equals finding value: #value with condition equals (json)'() {
+ setup:
+ new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', '=', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name == value }
+
+ where:
+ value || size
+ 'Iván' || 2
+ 'John' || 0
+ }
+
+ @Unroll
+ void 'Test equals finding value: #value with condition does not equal (json)'() {
+ setup:
+ new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', '<>', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name != value }
+
+ where:
+ value || size
+ 'Iván' || 1
+ 'John' || 3
+ }
+
+}
diff --git a/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy
new file mode 100644
index 0000000..e924189
--- /dev/null
+++ b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy
@@ -0,0 +1,34 @@
+package net.kaleidos.hibernate.json
+
+import grails.gorm.transactions.Rollback
+import grails.testing.mixin.integration.Integration
+import spock.lang.Specification
+import spock.lang.Unroll
+import test.json.TestMapJsonb
+
+@Integration
+@Rollback
+class PgJsonbEqualsIntegrationSpec extends Specification {
+
+ def pgJsonbTestSearchService
+
+ @Unroll
+ void 'Test equals finding value: #value (jsonb)'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJsonHasFieldValue', 'data', 'name', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name == value }
+
+ where:
+ value || size
+ 'Iván' || 2
+ 'John' || 0
+ }
+}
diff --git a/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy
new file mode 100644
index 0000000..ac21443
--- /dev/null
+++ b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy
@@ -0,0 +1,57 @@
+package net.kaleidos.hibernate.json
+
+import grails.gorm.transactions.Rollback
+import grails.testing.mixin.integration.Integration
+import spock.lang.Specification
+import spock.lang.Unroll
+import test.json.TestMapJsonb
+
+@Integration
+@Rollback
+class PgJsonbPathsIntegrationSpec extends Specification {
+
+ def pgJsonbTestSearchService
+
+ @Unroll
+ void 'Test equals finding nested values (jsonb): a'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJson', 'data', '#>>', '{nested, a}', '=', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.nested.a == value }
+
+ where:
+ value || size
+ 1 || 2 // there are 2 items with nested.a equal to 1
+ 2 || 1
+ 3 || 0
+ }
+
+ @Unroll
+ void 'Test equals finding nested values (jsonb): b'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJson', 'data', '#>>', '{nested, b}', '>', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.nested.b > value.toInteger() }
+
+ where:
+ value || size
+ 1 || 3 // There are 3 items with nested.b > 1
+ 3 || 1
+ 6 || 0
+ }
+
+}
diff --git a/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy
new file mode 100644
index 0000000..d7d9afa
--- /dev/null
+++ b/src/integration-test/groovy/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy
@@ -0,0 +1,75 @@
+package net.kaleidos.hibernate.json
+
+import grails.gorm.transactions.Rollback
+import grails.testing.mixin.integration.Integration
+import spock.lang.Specification
+import spock.lang.Unroll
+import test.json.TestMapJsonb
+
+@Integration
+@Rollback
+class PgJsonbValuesIntegrationSpec extends Specification {
+
+ def pgJsonbTestSearchService
+
+ @Unroll
+ void 'Test equals finding value: #value with condition is ilike (jsonb)'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', 'ilike', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name.matches "^(?i)${value.replace('%', '.*')}\$" }
+
+ where:
+ value || size
+ '%iv%' || 2
+ 'John' || 0
+ }
+
+ @Unroll
+ void 'Test equals finding value: #value with condition equals (jsonb)'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', '=', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name == value }
+
+ where:
+ value || size
+ 'Iván' || 2
+ 'John' || 0
+ }
+
+ @Unroll
+ void 'Test equals finding value: #value with condition does not equal (jsonb)'() {
+ setup:
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
+ new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
+
+ when:
+ def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', '<>', value)
+
+ then:
+ result.size() == size
+ result.every { it.data.name != value }
+
+ where:
+ value || size
+ 'Iván' || 1
+ 'John' || 3
+ }
+
+}
diff --git a/src/main/groovy/net/kaleidos/hibernate/usertype/ArrayType.java b/src/main/groovy/net/kaleidos/hibernate/usertype/ArrayType.java
index 67f2a2f..0142d95 100644
--- a/src/main/groovy/net/kaleidos/hibernate/usertype/ArrayType.java
+++ b/src/main/groovy/net/kaleidos/hibernate/usertype/ArrayType.java
@@ -7,16 +7,8 @@ import org.hibernate.usertype.ParameterizedType;
import org.hibernate.usertype.UserType;
import java.io.Serializable;
-import java.sql.Array;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
+import java.sql.*;
+import java.util.*;
public class ArrayType implements UserType, ParameterizedType {
public static final int INTEGER_ARRAY = 90001;
diff --git a/src/main/groovy/net/kaleidos/hibernate/usertype/JsonMapType.groovy b/src/main/groovy/net/kaleidos/hibernate/usertype/JsonMapType.groovy
index 9be558d..73d3ac9 100644
--- a/src/main/groovy/net/kaleidos/hibernate/usertype/JsonMapType.groovy
+++ b/src/main/groovy/net/kaleidos/hibernate/usertype/JsonMapType.groovy
@@ -1,9 +1,9 @@
package net.kaleidos.hibernate.usertype
-import com.google.gson.Gson
-import com.google.gson.GsonBuilder
+import grails.converters.JSON
import groovy.transform.CompileStatic
import org.apache.commons.lang.ObjectUtils
+import org.grails.web.json.JSONObject
import org.hibernate.HibernateException
import org.hibernate.engine.spi.SharedSessionContractImplementor
import org.hibernate.usertype.UserType
@@ -21,7 +21,6 @@ class JsonMapType implements UserType {
static int SQLTYPE = 90021
private final Type userType = Map
- private final Gson gson = new GsonBuilder().serializeNulls().create()
@Override
int[] sqlTypes() {
@@ -48,7 +47,7 @@ class JsonMapType implements UserType {
PGobject o = rs.getObject(names[0]) as PGobject
String jsonString = o?.value
- gson.fromJson(jsonString, userType)
+ jsonString ? new JSONObject(jsonString) : null
}
@Override
@@ -56,7 +55,7 @@ class JsonMapType implements UserType {
if (value == null) {
st.setNull(index, Types.OTHER)
} else {
- st.setObject(index, gson.toJson(value, userType), Types.OTHER)
+ st.setObject(index, (value as JSON).toString(), Types.OTHER)
}
}
@@ -80,12 +79,12 @@ class JsonMapType implements UserType {
@Override
Serializable disassemble(Object value) throws HibernateException {
- gson.toJson(value, userType)
+ (value as JSON).toString()
}
@Override
Object assemble(Serializable cached, Object owner) throws HibernateException {
- gson.fromJson((String) cached, userType)
+ new JSONObject(cached.toString())
}
@Override
diff --git a/test/integration/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy b/test/integration/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy
deleted file mode 100644
index 4e3dfb8..0000000
--- a/test/integration/net/kaleidos/hibernate/json/PgJsonPathsIntegrationSpec.groovy
+++ /dev/null
@@ -1,53 +0,0 @@
-package net.kaleidos.hibernate.json
-
-import spock.lang.Specification
-import spock.lang.Unroll
-import test.json.TestMapJson
-
-class PgJsonPathsIntegrationSpec extends Specification {
-
- def pgJsonTestSearchService
-
- @Unroll
- void 'Test equals finding nested values (json)'() {
- setup:
- new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
- new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
- new TestMapJson(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
-
- when:
- def result = pgJsonTestSearchService.search('pgJson', 'data', '#>>', '{nested, a}', '=', value)
-
- then:
- result.size() == size
- result.every { it.data.nested.a == value }
-
- where:
- value || size
- 1 || 2 // there are 2 items with nested.a equal to 1
- 2 || 1
- 3 || 0
- }
-
- @Unroll
- void 'Test equals finding nested values (json)'() {
- setup:
- new TestMapJson(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
- new TestMapJson(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
- new TestMapJson(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
-
- when:
- def result = pgJsonTestSearchService.search('pgJson', 'data', '#>>', '{nested, b}', '>', value)
-
- then:
- result.size() == size
- result.every { it.data.nested.b > value.toInteger() }
-
- where:
- value || size
- 1 || 3 // There are 3 items with nested.b > 1
- 3 || 1
- 6 || 0
- }
-
-}
diff --git a/test/integration/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy b/test/integration/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy
deleted file mode 100644
index 32bce4d..0000000
--- a/test/integration/net/kaleidos/hibernate/json/PgJsonValuesIntegrationSpec.groovy
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.kaleidos.hibernate.json
-
-import spock.lang.Specification
-import spock.lang.Unroll
-import test.json.TestMapJson
-
-class PgJsonValuesIntegrationSpec extends Specification {
-
- def pgJsonTestSearchService
-
- @Unroll
- void 'Test equals finding value: #value with condition is ilike (json)'() {
- setup:
- new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', 'ilike', value)
-
- then:
- result.size() == size
- result.every { it.data.name.matches "^(?i)${value.replace('%', '.*')}\$" }
-
- where:
- value || size
- '%iv%' || 2
- 'John' || 0
- }
-
- @Unroll
- void 'Test equals finding value: #value with condition equals (json)'() {
- setup:
- new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', '=', value)
-
- then:
- result.size() == size
- result.every { it.data.name == value }
-
- where:
- value || size
- 'Iván' || 2
- 'John' || 0
- }
-
- @Unroll
- void 'Test equals finding value: #value with condition does not equal (json)'() {
- setup:
- new TestMapJson(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJson(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJson(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonTestSearchService.search('pgJson', 'data', '->>', 'name', '<>', value)
-
- then:
- result.size() == size
- result.every { it.data.name != value }
-
- where:
- value || size
- 'Iván' || 1
- 'John' || 3
- }
-
-}
diff --git a/test/integration/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy b/test/integration/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy
deleted file mode 100644
index 1afd5a2..0000000
--- a/test/integration/net/kaleidos/hibernate/json/PgJsonbEqualsIntegrationSpec.groovy
+++ /dev/null
@@ -1,30 +0,0 @@
-package net.kaleidos.hibernate.json
-
-import spock.lang.Specification
-import spock.lang.Unroll
-import test.json.TestMapJsonb
-
-class PgJsonbEqualsIntegrationSpec extends Specification {
-
- def pgJsonbTestSearchService
-
- @Unroll
- void 'Test equals finding value: #value (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJsonHasFieldValue', 'data', 'name', value)
-
- then:
- result.size() == size
- result.every { it.data.name == value }
-
- where:
- value || size
- 'Iván' || 2
- 'John' || 0
- }
-}
diff --git a/test/integration/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy b/test/integration/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy
deleted file mode 100644
index 6393c7a..0000000
--- a/test/integration/net/kaleidos/hibernate/json/PgJsonbPathsIntegrationSpec.groovy
+++ /dev/null
@@ -1,53 +0,0 @@
-package net.kaleidos.hibernate.json
-
-import spock.lang.Specification
-import spock.lang.Unroll
-import test.json.TestMapJsonb
-
-class PgJsonbPathsIntegrationSpec extends Specification {
-
- def pgJsonbTestSearchService
-
- @Unroll
- void 'Test equals finding nested values (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJson', 'data', '#>>', '{nested, a}', '=', value)
-
- then:
- result.size() == size
- result.every { it.data.nested.a == value }
-
- where:
- value || size
- 1 || 2 // there are 2 items with nested.a equal to 1
- 2 || 1
- 3 || 0
- }
-
- @Unroll
- void 'Test equals finding nested values (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López', nested: [a: 1, b: 2]]).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres', nested: [a: 2, b: 3]]).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez', nested: [a: 1, b: 5]]).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJson', 'data', '#>>', '{nested, b}', '>', value)
-
- then:
- result.size() == size
- result.every { it.data.nested.b > value.toInteger() }
-
- where:
- value || size
- 1 || 3 // There are 3 items with nested.b > 1
- 3 || 1
- 6 || 0
- }
-
-}
diff --git a/test/integration/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy b/test/integration/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy
deleted file mode 100644
index 3918a0f..0000000
--- a/test/integration/net/kaleidos/hibernate/json/PgJsonbValuesIntegrationSpec.groovy
+++ /dev/null
@@ -1,71 +0,0 @@
-package net.kaleidos.hibernate.json
-
-import spock.lang.Specification
-import spock.lang.Unroll
-import test.json.TestMapJsonb
-
-class PgJsonbValuesIntegrationSpec extends Specification {
-
- def pgJsonbTestSearchService
-
- @Unroll
- void 'Test equals finding value: #value with condition is ilike (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', 'ilike', value)
-
- then:
- result.size() == size
- result.every { it.data.name.matches "^(?i)${value.replace('%', '.*')}\$" }
-
- where:
- value || size
- '%iv%' || 2
- 'John' || 0
- }
-
- @Unroll
- void 'Test equals finding value: #value with condition equals (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', '=', value)
-
- then:
- result.size() == size
- result.every { it.data.name == value }
-
- where:
- value || size
- 'Iván' || 2
- 'John' || 0
- }
-
- @Unroll
- void 'Test equals finding value: #value with condition does not equal (jsonb)'() {
- setup:
- new TestMapJsonb(data: [name: 'Iván', lastName: 'López']).save(flush: true)
- new TestMapJsonb(data: [name: 'Alonso', lastName: 'Torres']).save(flush: true)
- new TestMapJsonb(data: [name: 'Iván', lastName: 'Pérez']).save(flush: true)
-
- when:
- def result = pgJsonbTestSearchService.search('pgJson', 'data', '->>', 'name', '<>', value)
-
- then:
- result.size() == size
- result.every { it.data.name != value }
-
- where:
- value || size
- 'Iván' || 1
- 'John' || 3
- }
-
-}
Hi @ilopmar
Please review this pull request. Thanks.
:)
Thank you very much for your contributions! I've released version 6.0.0
:tada:
P.S: Sorry for taking too long...
Big thanx!
Hello!
I have finished migration to Grails 3.3.5. All tests passed, except one which check isDirty on modified map. Seems it doesn't work with new Grails and GORM.
Btw, thanx @abcfy2 for his patch here: https://github.com/kaleidos/grails-postgresql-extensions/issues/111