Predefined validators
JCV comes with a library of pre-defined validators :
contains
Parameters
- (required) the text to search for
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator contains`() {
//sampleStart
val actualJson = """
{
"field_name": "Hello world!"
}
"""
val expectedJson = """
{
"field_name": "{#contains:llo wor#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
starts_with
Parameters
- (required) the text to search for
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator starts_with`() {
//sampleStart
val actualJson = """
{
"field_name": "Hello world!"
}
"""
val expectedJson = """
{
"field_name": "{#starts_with:Hello#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
ends_with
Parameters
- (required) the text to search for
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator ends_with`() {
//sampleStart
val actualJson = """
{
"field_name": "Hello world!"
}
"""
val expectedJson = """
{
"field_name": "{#ends_with:world!#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
regex
Parameters
- (required) the regex pattern
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator regex`() {
//sampleStart
val actualJson = """
{
"field_name": "Hellowurld !!!"
}
"""
val expectedJson = """
{
"field_name": "{#regex:.*llo ?w.r.*#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
uuid
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator uuid`() {
//sampleStart
val actualJson = """
{
"field_name": "8525aa57-d491-41e2-b065-013aaacb24f7"
}
"""
val expectedJson = """
{
"field_name": "{#uuid#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
not_null
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator not_null`() {
//sampleStart
val actualJson = """
{
"field_name": true
}
"""
val expectedJson = """
{
"field_name": "{#not_null#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
not_empty
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator not_empty`() {
//sampleStart
val actualJson = """
{
"field_name": " "
}
"""
val expectedJson = """
{
"field_name": "{#not_empty#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
boolean_type
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator boolean_type`() {
//sampleStart
val actualJson = """
{
"field_name": true
}
"""
val expectedJson = """
{
"field_name": "{#boolean_type#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
string_type
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator string_type`() {
//sampleStart
val actualJson = """
{
"field_name": "some text"
}
"""
val expectedJson = """
{
"field_name": "{#string_type#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
number_type
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator number_type`() {
//sampleStart
val actualJson = """
{
"field_name": 123.45
}
"""
val expectedJson = """
{
"field_name": "{#number_type#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
array_type
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator array_type`() {
//sampleStart
val actualJson = """
{
"field_name": ["Value 1", "Value 2"]
}
"""
val expectedJson = """
{
"field_name": "{#array_type#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
object_type
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator object_type`() {
//sampleStart
val actualJson = """
{
"field_name": { "some_sub_field": "some value" }
}
"""
val expectedJson = """
{
"field_name": "{#object_type#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
url
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator url`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path?param"
}
"""
val expectedJson = """
{
"field_name": "{#url#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
url_ending
Parameters
- (required) url ending
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator url_ending`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path?param"
}
"""
val expectedJson = """
{
"field_name": "{#url_ending:/path?param#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
url_regex
Parameters
- (required) regex pattern
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator url_regex`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path?param"
}
"""
val expectedJson = """
{
"field_name": "{#url_regex:^.+some\\.url.+/path\\?param$#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
templated_url
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator templated_url`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path{?param}"
}
"""
val expectedJson = """
{
"field_name": "{#templated_url#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
templated_url_ending
Parameters
- (required) templated url ending
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator templated_url_ending`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path{?param}"
}
"""
val expectedJson = """
{
"field_name": "{#templated_url_ending:/path{?param}#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
templated_url_regex
Parameters
- (required) regex pattern
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator templated_url_regex`() {
//sampleStart
val actualJson = """
{
"field_name": "http://some.url:9999/path{?param}"
}
"""
val expectedJson = """
{
"field_name": "{#templated_url_regex:^.+some\\.url.+/path\\{\\?param\\}$#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
Parameters
- (required) the date time pattern (a predefined patterns or a custom pattern)
- (optional) the language tag (IETF BCP 47) for the custom pattern
Examples
import com.ekino.oss.jcv.assertion.assertj.JsonCompareAssert.Companion.assertThatJson
import org.junit.Test
class ValidatorsExampleTest {
@Test
fun `validator date_time_format`() {
//sampleStart
val actualJson = """
{
"date_time_predefined_format": "10:15:30+01:00",
"date_time_format": "3 Feb 2011",
"date_time_format_with_locale": "3 févr. 2011"
}
"""
val expectedJson = """
{
"date_time_predefined_format": "{#date_time_format:iso_time#}",
"date_time_format": "{#date_time_format:d MMM uuu#}",
"date_time_format_with_locale": "{#date_time_format:d MMM uuu;fr-FR#}"
}
"""
//sampleEnd
assertThatJson(actualJson.trimIndent()).isValidAgainst(expectedJson.trimIndent())
}
}
JCV libraries available: jcv-assertj:1.5.0 and jcv-hamcrest:1.5.0
back to top ▲
Predefined patterns
Pattern name |
Description |
Example |
basic_iso_date |
Basic ISO date |
20111203 |
iso_local_date |
ISO Local Date |
2011-12-03 |
iso_offset_date |
ISO Date with offset |
2011-12-03+01:00 |
iso_date |
ISO Date with or without offset '2011-12-03+01:00'; |
2011-12-03 |
iso_local_time |
Time without offset |
10:15:30 |
iso_offset_time |
Time with offset |
10:15:30+01:00 |
iso_time |
Time with or without offset '10:15:30+01:00'; |
10:15:30 |
iso_local_date_time |
ISO Local Date and Time |
2011-12-03T10:15:30 |
iso_offset_date_time |
Date Time with Offset |
2011-12-03T10:15:30+01:00 |
iso_zoned_date_time |
Zoned Date Time |
2011-12-03T10:15:30+01:00[Europe/Paris] |
iso_date_time |
Date and time with ZoneId |
2011-12-03T10:15:30+01:00[Europe/Paris] |
iso_ordinal_date |
Year and day of year |
2012-337 |
iso_week_date |
Year and Week |
2012-W48-6 |
iso_instant |
Date and Time of an Instant |
2011-12-03T10:15:30Z |
rfc_1123_date_time |
RFC 1123 / RFC 822 |
Tue, 3 Jun 2008 11:05:30 GMT |
Custom pattern symbols
Symbol |
Meaning |
Presentation |
Examples |
G |
era |
text |
AD; Anno Domini; A |
u |
year |
year |
2004; 04 |
y |
year-of-era |
year |
2004; 04 |
D |
day-of-year |
number |
189 |
M/L |
month-of-year |
number/text |
7; 07; Jul; July; J |
d |
day-of-month |
number |
10 |
Q/q |
quarter-of-year |
number/text |
3; 03; Q3; 3rd quarter |
Y |
week-based-year |
year |
1996; 96 |
w |
week-of-week-based-year |
number |
27 |
W |
week-of-month |
number |
4 |
E |
day-of-week |
text |
Tue; Tuesday; T |
e/c |
localized day-of-week |
number/text |
2; 02; Tue; Tuesday; T |
F |
week-of-month |
number |
3 |
a |
am-pm-of-day |
text |
PM |
h |
clock-hour-of-am-pm (1-12) |
number |
12 |
K |
hour-of-am-pm (0-11) |
number |
0 |
k |
clock-hour-of-am-pm (1-24) |
number |
0 |
H |
hour-of-day (0-23) |
number |
0 |
m |
minute-of-hour |
number |
30 |
s |
second-of-minute |
number |
55 |
S |
fraction-of-second |
fraction |
978 |
A |
milli-of-day |
number |
1234 |
n |
nano-of-second |
number |
987654321 |
N |
nano-of-day |
number |
1234000000 |
V |
time-zone ID |
zone-id |
America/Los_Angeles; Z; -08:30 |
z |
time-zone name |
zone-name |
Pacific Standard Time; PST |
O |
localized zone-offset |
offset-O |
GMT+8; GMT+08:00; UTC-08:00; |
X |
zone-offset 'Z' for zero |
offset-X |
Z; -08; -0830; -08:30; -083015; -08:30:15; |
x |
zone-offset |
offset-x |
+0000; -08; -0830; -08:30; -083015; -08:30:15; |
Z |
zone-offset |
offset-Z |
+0000; -0800; -08:00; |
p |
pad next |
pad modifier |
1 |
' |
escape for text |
delimiter |
|
'' |
single quote |
literal |
' |
[ |
optional section start |
|
|
] |
optional section end |
|
|
# |
reserved for future use |
|
|
{ |
reserved for future use |
|
|
} |
reserved for future use |
|
|
back to top ▲