Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
App Blocks
Commits
d9bd0f45
Commit
d9bd0f45
authored
Jun 29, 2022
by
Matija Obreza
Browse files
JUnit
parent
be32d5c2
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/src/test/java/org/genesys/blocks/tests/model/TestingEntityTest.java
View file @
d9bd0f45
...
...
@@ -52,7 +52,7 @@ public class TestingEntityTest extends ServiceTest {
}
@Test
public
void
testNumberFilter
()
{
public
void
testNumberFilter
()
throws
NoSuchFieldException
,
IllegalAccessException
{
TestingEntity
entity1
=
repository
.
save
(
new
TestingEntity
(
null
,
10
));
TestingEntity
entity2
=
repository
.
save
(
new
TestingEntity
(
null
,
20
));
...
...
@@ -86,6 +86,9 @@ public class TestingEntityTest extends ServiceTest {
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getTotalElements
(),
is
(
2L
));
filter
.
clearFilter
(
"number"
);
assertThat
(
filter
.
number
,
is
(
nullValue
()));
filter
.
number
=
new
NumberFilter
<>();
filter
.
number
.
eq
();
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
...
...
@@ -193,6 +196,30 @@ public class TestingEntityTest extends ServiceTest {
filter
.
NOT
.
tags
=
Set
.
of
(
"tag5"
);
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getContent
(),
hasSize
(
0
));
// Test null
var
entity3
=
new
TestingEntity
(
new
Date
(),
null
);
entity3
.
setTags
(
Set
.
of
(
"tag1"
,
"tag2"
));
entity3
=
repository
.
save
(
entity3
);
filter
=
new
TestingEntityFilter
();
filter
.
NULL
=
Set
.
of
(
"number"
);
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getContent
(),
hasSize
(
1
));
filter
.
number
().
gt
=
10
;
assertThat
(
filter
.
number
,
not
(
nullValue
()));
TestingEntityFilter
.
normalize
(
filter
);
// NULL has precedence
assertThat
(
filter
.
number
,
is
(
nullValue
()));
filter
.
notNull
().
add
(
"tags"
);
filter
.
notNull
().
add
(
"tags"
);
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getContent
(),
hasSize
(
1
));
filter
=
new
TestingEntityFilter
();
filter
.
NOTNULL
=
Set
.
of
(
"tags"
);
page
=
repository
.
findAll
(
filter
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getContent
(),
hasSize
(
3
));
}
...
...
@@ -255,4 +282,15 @@ public class TestingEntityTest extends ServiceTest {
page
=
repository
.
findAll
(
filterWithoutT
.
buildPredicate
(),
PageRequest
.
of
(
0
,
5
));
assertThat
(
page
.
getContent
(),
containsInAnyOrder
(
entity3
));
}
@Test
public
void
testSerialization
()
{
// NOT
var
filter
=
new
TestingEntityFilter
();
filter
.
tags
=
Set
.
of
(
"tag1"
);
filter
.
NOT
=
new
TestingEntityFilter
();
filter
.
NOT
.
number
().
eq
=
Set
.
of
(
3
);
assertThat
(
filter
.
toString
(),
is
(
"{\"NOT\":{\"number\":{\"eq\":[3]}},\"tags\":[\"tag1\"]}"
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment