-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 2.12.0
- Loading branch information
Showing
11 changed files
with
170 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ email: [email protected] | |
project_name: data-model-lib | ||
project_short_description: "Data models. A collection of QBiC's central data models\ | ||
\ and DTOs. " | ||
version: 2.11.0 | ||
version: 2.12.0 | ||
domain: lib | ||
language: groovy | ||
project_slug: data-model-lib | ||
|
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
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
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
20 changes: 20 additions & 0 deletions
20
src/main/groovy/life/qbic/datamodel/validation/ValidationException.groovy
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,20 @@ | ||
package life.qbic.datamodel.validation | ||
|
||
/** | ||
* <p>Should be thrown in case a validation failed</p> | ||
* | ||
* @since 2.12.0 | ||
*/ | ||
class ValidationException extends RuntimeException { | ||
/** Constructs a new runtime exception with the specified detail message. | ||
* The cause is not initialized, and may subsequently be initialized by a | ||
* call to {@link #initCause}. | ||
* | ||
* @param message the detail message. The detail message is saved for | ||
* later retrieval by the {@link #getMessage()} method. | ||
* @since 2.12.0 | ||
*/ | ||
ValidationException(String message) { | ||
super(message) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidator.groovy
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,37 @@ | ||
package life.qbic.datamodel.validation.projectmanagement | ||
|
||
import life.qbic.datamodel.validation.ValidationException | ||
|
||
import java.util.function.Consumer | ||
import java.util.function.Predicate | ||
import java.util.regex.Pattern | ||
|
||
/** | ||
* <b>Project Code Validator</b> | ||
* | ||
* <p>Consumes a project code and throws a {@link ValidationException} in case it is not valid.</p> | ||
* | ||
* @since 2.12.0 | ||
*/ | ||
class ProjectCodeValidator implements Consumer<String> { | ||
private static final Predicate<String> IS_VALID_PROJECT_CODE = Pattern.compile("^Q[A-X0-9]{4}\$").asPredicate() | ||
|
||
/** | ||
* Consumes the project code and throws a {@link ValidationException} in case of invalidity. | ||
* | ||
* @param projectCode the project code to validate | ||
* @throws ValidationException in case of validation failure | ||
* @since 2.12.0 | ||
*/ | ||
@Override | ||
void accept(String projectCode) throws ValidationException { | ||
ValidationException validationException = new ValidationException("'${projectCode}' is not a valid project code.") | ||
if (!projectCode) { | ||
throw validationException | ||
} | ||
if (!IS_VALID_PROJECT_CODE.test(projectCode)) { | ||
throw validationException | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/test/groovy/life/qbic/datamodel/dtos/business/facilities/FacilitySpec.groovy
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,29 @@ | ||
package life.qbic.datamodel.dtos.business.facilities | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* Tests for the {@link Facility} enum class | ||
* | ||
* @since 2.12.0 | ||
*/ | ||
class FacilitySpec extends Specification { | ||
|
||
def "given an enum, calling the label function returns the right label"() { | ||
|
||
when: | ||
String result = facility.label | ||
|
||
then: | ||
result == expectedLabel | ||
|
||
where: | ||
facility | expectedLabel | ||
Facility.CFMB | "CFMB" | ||
Facility.CFMB_PCT | "Proteomics Facility" | ||
Facility.IMGAG | "IMGAG" | ||
Facility.MGM | "MGM" | ||
Facility.QBIC | "QBIC" | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...t/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidatorSpec.groovy
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,34 @@ | ||
package life.qbic.datamodel.validation.projectmanagement | ||
|
||
import life.qbic.datamodel.validation.ValidationException | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
/** | ||
* <p>Tests the ProjectCodeValidator</p> | ||
* | ||
* @since 2.12.0 | ||
*/ | ||
class ProjectCodeValidatorSpec extends Specification { | ||
ProjectCodeValidator validator = new ProjectCodeValidator() | ||
|
||
@Unroll | ||
def "Accept throws no exception for valid project code: #validProjectCode"() { | ||
when: | ||
validator.accept(validProjectCode) | ||
then: | ||
noExceptionThrown() | ||
where: | ||
validProjectCode << ["QABCD", "QBBBA", "QPPEO", "QQQQQ", "Q0000", "Q00A0"] | ||
} | ||
|
||
@Unroll | ||
def "Accept throws ValidationException for invalid project code: #invalidProjectCode"() { | ||
when: | ||
validator.accept(invalidProjectCode) | ||
then: | ||
thrown(ValidationException) | ||
where: | ||
invalidProjectCode << [null, "", "testQABCD", "QABCD0000", "YABCD", "ZABCD", "QZZBA"] | ||
} | ||
} |