Skip to content

Commit cf954be

Browse files
demo for #46
1 parent 180f32e commit cf954be

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/test/java/io/frictionlessdata/datapackage/PackageTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.frictionlessdata.datapackage.exceptions.DataPackageFileOrUrlNotFoundException;
88
import io.frictionlessdata.datapackage.exceptions.DataPackageValidationException;
99
import io.frictionlessdata.datapackage.resource.*;
10+
import io.frictionlessdata.tableschema.exception.ConstraintsException;
1011
import io.frictionlessdata.tableschema.exception.ValidationException;
1112
import io.frictionlessdata.tableschema.field.DateField;
1213
import io.frictionlessdata.tableschema.schema.Schema;
@@ -968,6 +969,20 @@ public void testReadPackageAllFields() throws Exception{
968969
Assertions.assertEquals("Example Corp", c.getOrganization());
969970
}
970971

972+
@Test
973+
// check for https://github.com/frictionlessdata/datapackage-java/issues/46
974+
@DisplayName("Show that minimum constraints work")
975+
void validateDataPackage() throws Exception {
976+
Package dp = this.getDataPackageFromFilePath(
977+
"/fixtures/datapackages/constraint-violation/datapackage.json", true);
978+
Resource resource = dp.getResource("person_data");
979+
ConstraintsException exception = assertThrows(ConstraintsException.class, () -> resource.getData(false, false, true, false));
980+
981+
// Assert the validation messages
982+
Assertions.assertNotNull(exception.getMessage());
983+
Assertions.assertFalse(exception.getMessage().isEmpty());
984+
}
985+
971986
private static void fingerprintFiles(Path path) {
972987
List<String> fingerprints = new ArrayList<>();
973988
MessageDigest md;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
firstname,lastname,gender,age
2+
John,Doe,male,30
3+
Jane,Smith,female,25
4+
Alice,Johnson,female,19
5+
Bob,Williams,male,1
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name":"csv-validation-using-ig",
3+
"description":"Validates Person",
4+
"dialect":{
5+
"delimiter":","
6+
},
7+
"resources":[
8+
{
9+
"name":"person_data",
10+
"path":"datapackages/constraint-violation/data/person.csv",
11+
"schema":{
12+
"fields":[
13+
{
14+
"name":"firstname",
15+
"type":"string",
16+
"description":"The first name of the person.",
17+
"constraints":{
18+
"required":true
19+
}
20+
},
21+
{
22+
"name":"lastname",
23+
"type":"string",
24+
"description":"The last name of the person.",
25+
"constraints":{
26+
"required":true
27+
}
28+
},
29+
{
30+
"name":"gender",
31+
"type":"string",
32+
"description":"Gender of the person. Valid values are 'male' or 'female'.",
33+
"constraints":{
34+
"enum":[
35+
"male",
36+
"female"
37+
]
38+
}
39+
},
40+
{
41+
"name":"age",
42+
"type":"integer",
43+
"description":"The age of the person. Must be greater than 18.",
44+
"constraints":{
45+
"minimum":19
46+
}
47+
}
48+
]
49+
}
50+
}
51+
]
52+
}

0 commit comments

Comments
 (0)