1- package io .frictionlessdata .datapackage ;
1+ package io .frictionlessdata .datapackage . fk ;
22
3+ import io .frictionlessdata .datapackage .Package ;
4+ import io .frictionlessdata .datapackage .TestUtil ;
35import io .frictionlessdata .datapackage .exceptions .DataPackageValidationException ;
46import io .frictionlessdata .datapackage .resource .Resource ;
57import io .frictionlessdata .tableschema .exception .ForeignKeyException ;
810import org .junit .jupiter .api .Test ;
911
1012import java .nio .file .Path ;
13+ import java .util .List ;
1114
1215import static org .junit .jupiter .api .Assertions .assertThrows ;
1316
14- public class ForeignKeysTest {
17+ public class ForeignKeyTest {
1518
1619 @ Test
1720 @ DisplayName ("Test that foreign keys are validated correctly, good case" )
1821 void testForeignKeysGoodCase () throws Exception {
1922 Path resourcePath = TestUtil .getResourcePath ("/fixtures/datapackages/foreign_keys_valid.json" );
20- Package pkg = new Package (resourcePath , true );
21- pkg .getResource ("teams" );
23+ io .frictionlessdata .datapackage .Package pkg = new io .frictionlessdata .datapackage .Package (resourcePath , true );
24+ Resource teams = pkg .getResource ("teams" );
25+ teams .checkRelations (pkg );
2226 }
2327
2428 @ Test
2529 @ DisplayName ("Test that foreign keys are validated correctly, bad case" )
2630 void testForeignKeysBadCase () throws Exception {
2731 Path resourcePath = TestUtil .getResourcePath ("/fixtures/datapackages/foreign_keys_invalid.json" );
28- Package pkg = new Package (resourcePath , true );
32+ io . frictionlessdata . datapackage . Package pkg = new Package (resourcePath , true );
2933 Resource teams = pkg .getResource ("teams" );
3034
3135 DataPackageValidationException ex = assertThrows (DataPackageValidationException .class ,
@@ -34,4 +38,17 @@ void testForeignKeysBadCase() throws Exception{
3438 Assertions .assertInstanceOf (ForeignKeyException .class , cause );
3539 Assertions .assertEquals ("Foreign key validation failed: [city] -> [name]: 'Munich' not found in resource 'cities'." , cause .getMessage ());
3640 }
41+
42+ @ Test
43+ @ DisplayName ("Test checkRelations on valid resources in different-valid-data-formats datapackage" )
44+ void testCheckRelationsOnAllResources () throws Exception {
45+ Path resourcePath = TestUtil .getResourcePath ("/fixtures/datapackages/different-valid-data-formats/datapackage.json" );
46+ Package dp = new Package (resourcePath , true );
47+
48+ dp .getResource ("teams_with_headers_csv_file" ).checkRelations (dp );
49+ dp .getResource ("teams_arrays_inline" ).checkRelations (dp );
50+ dp .getResource ("teams_objects_inline" ).checkRelations (dp );
51+ dp .getResource ("teams_arrays_file" ).checkRelations (dp );
52+ dp .getResource ("teams_objects_file" ).checkRelations (dp );
53+ }
3754}
0 commit comments