|
1 | 1 | package org.geoscript.geocss
|
2 | 2 |
|
3 |
| -import org.specs2._ |
4 | 3 | import org.opengis.filter.Filter.{ INCLUDE, EXCLUDE }
|
5 | 4 | import org.opengis.{ filter => ogc }
|
| 5 | +import org.scalatest._, matchers._ |
6 | 6 |
|
7 | 7 | /**
|
8 | 8 | * Tests for token methods
|
9 | 9 | */
|
10 |
| -class TokenTest extends Specification with matcher.DataTables { |
| 10 | +class TokenTest extends FunSuite with ShouldMatchers { |
11 | 11 | val filterFactory =
|
12 | 12 | org.geotools.factory.CommonFactoryFinder.getFilterFactory2(null)
|
13 | 13 | import filterFactory._
|
14 | 14 |
|
15 |
| - val expr = |
16 |
| - (org.geotools.filter.text.ecql.ECQL.toFilter(_: String)) andThen |
17 |
| - (Selector.asSelector) |
| 15 | + val expr = (x: String) => |
| 16 | + Selector.asSelector(org.geotools.filter.text.ecql.ECQL.toFilter(x)) |
18 | 17 | val expr1 = expr("a>b")
|
19 | 18 | val expr2 = expr("c<d")
|
20 | 19 |
|
21 |
| - def is = |
22 |
| - "'And' Selectors should do some basic simplification" ^ |
23 |
| - "empty And goes to Include" ! { |
24 |
| - And(Nil).filterOpt must beSome(INCLUDE) |
25 |
| - } ^ |
26 |
| - "single-element And goes to simple filter" ! { |
27 |
| - And(List(expr1)).filterOpt must_== expr1.filterOpt |
28 |
| - } ^ |
29 |
| - "'and' filter is correctly generated for larger And's" ! { |
30 |
| - And(List(expr1, expr2)).filterOpt must_== |
31 |
| - (for { f <- expr1.filterOpt; g <- expr2.filterOpt } |
32 |
| - yield and(f, g)) |
33 |
| - } ^ end ^ |
34 |
| - "'Not' selectors produce negated Filters" ! { |
35 |
| - "selector" | "filter" | |
36 |
| - Not(Accept) ! Some(EXCLUDE) | |
37 |
| - Not(Not(Accept)) ! Some(INCLUDE) | |
38 |
| - Accept ! Some(INCLUDE) |> { |
39 |
| - (sel, filt) => sel.filterOpt must_== filt |
40 |
| - } |
41 |
| - } ^ end ^ |
42 |
| - "Spot checks on miscellaneous filter combos" ! { |
43 |
| - "selector" | "criterion" | |
44 |
| - expr1 ! beAnInstanceOf[ogc.PropertyIsGreaterThan] | |
45 |
| - Not(expr1) ! beAnInstanceOf[ogc.Not] | |
46 |
| - Or(List(expr1)) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] | |
47 |
| - And(List(expr1)) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] | |
48 |
| - Not(And(List(expr1))) ! beAnInstanceOf[ogc.Not] | |
49 |
| - Or(List(And(List(expr1)))) ! beAnInstanceOf[ogc.PropertyIsGreaterThan] | |
50 |
| - Or(List(And(List(Not(expr1))))) ! beAnInstanceOf[ogc.Not] |> |
51 |
| - { (sel, pass) => sel.filterOpt must beSome.which(_ must pass) } |
| 20 | + test("empty And goes to Include") { |
| 21 | + And(Nil).filterOpt should be(Some(INCLUDE)) |
| 22 | + } |
| 23 | + |
| 24 | + test("single-element And goes to simple filter") { |
| 25 | + And(List(expr1)).filterOpt should equal(expr1.filterOpt) |
| 26 | + } |
| 27 | + |
| 28 | + test("'and' filter is correctly generated for larger And's") { |
| 29 | + val expected = |
| 30 | + for { |
| 31 | + f <- expr1.filterOpt |
| 32 | + g <- expr2.filterOpt |
| 33 | + } yield and(f, g) |
| 34 | + |
| 35 | + expect(expected) { |
| 36 | + And(List(expr1, expr2)).filterOpt |
52 | 37 | }
|
| 38 | + } |
| 39 | + |
| 40 | + test("'Not' selectors produce negated Filters") { |
| 41 | + Not(Accept).filterOpt should equal(Some(EXCLUDE)) |
| 42 | + Not(Not(Accept)).filterOpt should equal(Some(INCLUDE)) |
| 43 | + Accept.filterOpt should equal(Some(INCLUDE)) |
| 44 | + } |
| 45 | + |
| 46 | + test("Spot checks on miscellaneous filter combos") { |
| 47 | + assert(expr1.filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan])) |
| 48 | + assert(Not(expr1).filterOpt exists(_.isInstanceOf[ogc.Not])) |
| 49 | + assert(Or(List(expr1)).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan])) |
| 50 | + assert(And(List(expr1)).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan])) |
| 51 | + assert(Not(And(List(expr1))).filterOpt exists(_.isInstanceOf[ogc.Not])) |
| 52 | + assert(Or(List(And(List(expr1)))).filterOpt exists(_.isInstanceOf[ogc.PropertyIsGreaterThan])) |
| 53 | + assert(Or(List(And(List(Not(expr1))))).filterOpt exists(_.isInstanceOf[ogc.Not])) |
| 54 | + } |
53 | 55 | }
|
0 commit comments