Commit d9bd0f45 authored by Matija Obreza's avatar Matija Obreza
Browse files

JUnit

parent be32d5c2
...@@ -52,7 +52,7 @@ public class TestingEntityTest extends ServiceTest { ...@@ -52,7 +52,7 @@ public class TestingEntityTest extends ServiceTest {
} }
@Test @Test
public void testNumberFilter() { public void testNumberFilter() throws NoSuchFieldException, IllegalAccessException {
TestingEntity entity1 = repository.save(new TestingEntity(null, 10)); TestingEntity entity1 = repository.save(new TestingEntity(null, 10));
TestingEntity entity2 = repository.save(new TestingEntity(null, 20)); TestingEntity entity2 = repository.save(new TestingEntity(null, 20));
...@@ -86,6 +86,9 @@ public class TestingEntityTest extends ServiceTest { ...@@ -86,6 +86,9 @@ public class TestingEntityTest extends ServiceTest {
page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5)); page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5));
assertThat(page.getTotalElements(), is(2L)); assertThat(page.getTotalElements(), is(2L));
filter.clearFilter("number");
assertThat(filter.number, is(nullValue()));
filter.number = new NumberFilter<>(); filter.number = new NumberFilter<>();
filter.number.eq(); filter.number.eq();
page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5)); page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5));
...@@ -193,6 +196,30 @@ public class TestingEntityTest extends ServiceTest { ...@@ -193,6 +196,30 @@ public class TestingEntityTest extends ServiceTest {
filter.NOT.tags = Set.of("tag5"); filter.NOT.tags = Set.of("tag5");
page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5)); page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5));
assertThat(page.getContent(), hasSize(0)); 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 { ...@@ -255,4 +282,15 @@ public class TestingEntityTest extends ServiceTest {
page = repository.findAll(filterWithoutT.buildPredicate(), PageRequest.of(0, 5)); page = repository.findAll(filterWithoutT.buildPredicate(), PageRequest.of(0, 5));
assertThat(page.getContent(), containsInAnyOrder(entity3)); 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\"]}"));
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment