-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(isnull-operator): implement ISNULL operator
- Loading branch information
1 parent
4fbc96e
commit d754705
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package fr.ouestfrance.querydsl.postgrest.mappers; | ||
|
||
import fr.ouestfrance.querydsl.FilterOperation; | ||
import fr.ouestfrance.querydsl.postgrest.model.Filter; | ||
import fr.ouestfrance.querydsl.postgrest.model.impl.QueryFilter; | ||
|
||
public class IsNullMapper extends AbstractMapper { | ||
|
||
@Override | ||
public Filter getFilter(String field, Object value) { | ||
return QueryFilter.of(field, Boolean.TRUE.equals(value) ? Operators.IS : Operators.IS_NOT, null); | ||
} | ||
|
||
@Override | ||
public Class<? extends FilterOperation> operation() { | ||
return FilterOperation.ISNULL.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...l-postgrest/src/test/java/fr/ouestfrance/querydsl/postgrest/mappers/IsNullMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fr.ouestfrance.querydsl.postgrest.mappers; | ||
|
||
import fr.ouestfrance.querydsl.FilterOperation; | ||
import fr.ouestfrance.querydsl.model.SimpleFilter; | ||
import fr.ouestfrance.querydsl.postgrest.builders.QueryFilterVisitor; | ||
import fr.ouestfrance.querydsl.postgrest.model.Filter; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class IsNullMapperTest { | ||
|
||
@Test | ||
void shouldMapIsNull() { | ||
IsNullMapper mapper = new IsNullMapper(); | ||
assertNotNull(mapper.operation()); | ||
Stream.of(Boolean.TRUE, Boolean.FALSE).forEach(value -> { | ||
Filter result = mapper.map(new SimpleFilter("name", FilterOperation.ISNULL.class, false, null), value); | ||
assertNotNull(result); | ||
QueryFilterVisitor visitor = new QueryFilterVisitor(); | ||
result.accept(visitor); | ||
assertNotNull(visitor.getValue()); | ||
assertEquals(Boolean.TRUE.equals(value) ? "is.null" : "not.is.null", visitor.getValue()); | ||
}); | ||
|
||
} | ||
} |