-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #526 from digital-preservation/DR2-2045_fixOptionR…
…elatedErrorWhenEvaluatingRules Dr2 2045 fix Option-related error when evaluating rules
- Loading branch information
Showing
9 changed files
with
262 additions
and
27 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
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
61 changes: 61 additions & 0 deletions
61
...-core/src/test/scala/uk/gov/nationalarchives/csv/validator/schema/v1_0/EndsRuleSpec.scala
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,61 @@ | ||
/* | ||
* Copyright (c) 2013, The National Archives <[email protected]> | ||
* https://www.nationalarchives.gov.uk | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package uk.gov.nationalarchives.csv.validator.schema.v1_0 | ||
|
||
import cats.data.Validated | ||
import org.junit.runner.RunWith | ||
import org.specs2.mutable.Specification | ||
import org.specs2.runner.JUnitRunner | ||
import uk.gov.nationalarchives.csv.validator.metadata.{Cell, Row} | ||
import uk.gov.nationalarchives.csv.validator.schema._ | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class EndsRuleSpec extends Specification { | ||
|
||
"EndsRule with a string literal behaviour" should { | ||
val globalDirsOne = List(TotalColumns(1)) | ||
|
||
"succeed if cell ends with endsRule value" in { | ||
val endsRule = EndsRule(Literal(Some("world"))) | ||
|
||
endsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if cell does not end with endsRule value" in { | ||
val endsRule = EndsRule(Literal(Some("hello world"))) | ||
endsRule.evaluate(0, Row(List(Cell("hello")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """ends("hello world") fails for line: 1, column: column1, value: "hello"""" | ||
} | ||
} | ||
|
||
"succeed if endsRule is the same as value" in { | ||
val endsRule = EndsRule(Literal(Some("hello world"))) | ||
endsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"succeed if endsRule's column reference does exist" in { | ||
val endsRule = EndsRule(ColumnReference(NamedColumnIdentifier("column1"))) | ||
|
||
endsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if endsRule's column reference doesn't exist" in { | ||
val endsRule = EndsRule(ColumnReference(NamedColumnIdentifier("nonExistentColumn"))) | ||
|
||
endsRule.evaluate(0, Row(List(Cell("hello world today")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """ends($nonExistentColumn) fails for line: 1, column: column1, value: "hello world today"""" | ||
} | ||
} | ||
|
||
"succeed with @ignoreCase" in { | ||
val endsRule = EndsRule(Literal(Some("hello world"))) | ||
endsRule.evaluate(0, Row(List(Cell("hello WORLD")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"), Nil, List(IgnoreCase()))))) mustEqual Validated.Valid(true) | ||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...or-core/src/test/scala/uk/gov/nationalarchives/csv/validator/schema/v1_0/IsRuleSpec.scala
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,55 @@ | ||
/* | ||
* Copyright (c) 2013, The National Archives <[email protected]> | ||
* https://www.nationalarchives.gov.uk | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package uk.gov.nationalarchives.csv.validator.schema.v1_0 | ||
|
||
import cats.data.Validated | ||
import org.junit.runner.RunWith | ||
import org.specs2.mutable.Specification | ||
import org.specs2.runner.JUnitRunner | ||
import uk.gov.nationalarchives.csv.validator.metadata.{Cell, Row} | ||
import uk.gov.nationalarchives.csv.validator.schema._ | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class IsRuleSpec extends Specification { | ||
|
||
"IsRule with a string literal behaviour" should { | ||
val globalDirsOne = List(TotalColumns(1)) | ||
|
||
"succeed if isRule is the same as value" in { | ||
val isRule = IsRule(Literal(Some("hello world"))) | ||
isRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if isRule is not the same as value" in { | ||
val isRule = IsRule(Literal(Some("completely different value"))) | ||
isRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """is("completely different value") fails for line: 1, column: column1, value: "hello world"""" | ||
} | ||
} | ||
|
||
"fail if isRule is embedded in value" in { | ||
val isRule = IsRule(Literal(Some("hello world today"))) | ||
isRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """is("hello world today") fails for line: 1, column: column1, value: "hello world"""" | ||
} | ||
} | ||
|
||
"fail if isRule is not in value" in { | ||
val isRule = IsRule(Literal(Some("hello world"))) | ||
isRule.evaluate(0, Row(List(Cell("hello world today")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """is("hello world") fails for line: 1, column: column1, value: "hello world today"""" | ||
} | ||
} | ||
|
||
"succeed with @ignoreCase" in { | ||
val isRule = IsRule(Literal(Some("hello world"))) | ||
isRule.evaluate(0, Row(List(Cell("hello WORLD")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"), Nil, List(IgnoreCase()))))) mustEqual Validated.Valid(true) | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...r-core/src/test/scala/uk/gov/nationalarchives/csv/validator/schema/v1_0/NotRuleSpec.scala
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,48 @@ | ||
/* | ||
* Copyright (c) 2013, The National Archives <[email protected]> | ||
* https://www.nationalarchives.gov.uk | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package uk.gov.nationalarchives.csv.validator.schema.v1_0 | ||
|
||
import cats.data.Validated | ||
import org.junit.runner.RunWith | ||
import org.specs2.mutable.Specification | ||
import org.specs2.runner.JUnitRunner | ||
import uk.gov.nationalarchives.csv.validator.metadata.{Cell, Row} | ||
import uk.gov.nationalarchives.csv.validator.schema._ | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class NotRuleSpec extends Specification { | ||
|
||
"NotRule with a string literal behaviour" should { | ||
val globalDirsOne = List(TotalColumns(1)) | ||
|
||
"succeed if notRule is not the same as value" in { | ||
val notRule = NotRule(Literal(Some("completely different value"))) | ||
notRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"succeed if notRule is the similar to value" in { | ||
val notRule = NotRule(Literal(Some("hello world "))) | ||
notRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if notRule is the same as value" in { | ||
val notRule = NotRule(Literal(Some("hello world"))) | ||
notRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """not("hello world") fails for line: 1, column: column1, value: "hello world"""" | ||
} | ||
} | ||
|
||
"fail with @ignoreCase" in { | ||
val notRule = NotRule(Literal(Some("hello world"))) | ||
notRule.evaluate(0, Row(List(Cell("hello WORLD")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"), Nil, List(IgnoreCase()))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """not("hello world") fails for line: 1, column: column1, value: "hello WORLD"""" | ||
} | ||
} | ||
} | ||
} |
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
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
61 changes: 61 additions & 0 deletions
61
...ore/src/test/scala/uk/gov/nationalarchives/csv/validator/schema/v1_0/StartsRuleSpec.scala
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,61 @@ | ||
/* | ||
* Copyright (c) 2013, The National Archives <[email protected]> | ||
* https://www.nationalarchives.gov.uk | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package uk.gov.nationalarchives.csv.validator.schema.v1_0 | ||
|
||
import cats.data.Validated | ||
import org.junit.runner.RunWith | ||
import org.specs2.mutable.Specification | ||
import org.specs2.runner.JUnitRunner | ||
import uk.gov.nationalarchives.csv.validator.metadata.{Cell, Row} | ||
import uk.gov.nationalarchives.csv.validator.schema._ | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class StartsRuleSpec extends Specification { | ||
|
||
"StartsRule with a string literal behaviour" should { | ||
val globalDirsOne = List(TotalColumns(1)) | ||
|
||
"succeed if cell starts with startsRule value" in { | ||
val startsRule = StartsRule(Literal(Some("hello world"))) | ||
|
||
startsRule.evaluate(0, Row(List(Cell("hello world today")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if cell does not start with startsRule value" in { | ||
val startsRule = StartsRule(Literal(Some("hello world today"))) | ||
startsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """starts("hello world today") fails for line: 1, column: column1, value: "hello world"""" | ||
} | ||
} | ||
|
||
"succeed if startsRule is the same as value" in { | ||
val startsRule = StartsRule(Literal(Some("hello world"))) | ||
startsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"succeed if startsRule's column reference does exist" in { | ||
val startsRule = StartsRule(ColumnReference(NamedColumnIdentifier("column1"))) | ||
|
||
startsRule.evaluate(0, Row(List(Cell("hello world")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) mustEqual Validated.Valid(true) | ||
} | ||
|
||
"fail if startsRule's column reference doesn't exist" in { | ||
val startsRule = StartsRule(ColumnReference(NamedColumnIdentifier("nonExistentColumn"))) | ||
|
||
startsRule.evaluate(0, Row(List(Cell("hello world today")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"))))) must beLike { | ||
case Validated.Invalid(messages) => messages.head mustEqual """starts($nonExistentColumn) fails for line: 1, column: column1, value: "hello world today"""" | ||
} | ||
} | ||
|
||
"succeed with @ignoreCase" in { | ||
val startsRule = StartsRule(Literal(Some("hello world"))) | ||
startsRule.evaluate(0, Row(List(Cell("hello WORLD")), 1), Schema(globalDirsOne, List(ColumnDefinition(NamedColumnIdentifier("column1"), Nil, List(IgnoreCase()))))) mustEqual Validated.Valid(true) | ||
} | ||
} | ||
} |