Skip to content

Commit ce8ece3

Browse files
Better alignment between Resource and underlying Tables
1 parent 45f0693 commit ce8ece3

File tree

5 files changed

+49
-129
lines changed

5 files changed

+49
-129
lines changed

pom.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,13 @@
263263
<artifactId>tableschema-java</artifactId>
264264
<version>${tableschema-java-version}</version>
265265
</dependency>
266-
267-
<dependency>
268-
<groupId>io.frictionlessdata</groupId>
269-
<artifactId>tableschema-java</artifactId>
270-
<version>0.6.1-SNAPSHOT</version>
271-
<scope>compile</scope>
272-
</dependency>
273-
</dependencies>
274-
</project>
266+
<!--
267+
<dependency>
268+
<groupId>io.frictionlessdata</groupId>
269+
<artifactId>tableschema-java</artifactId>
270+
<version>0.6.1-SNAPSHOT</version>
271+
<scope>compile</scope>
272+
</dependency>
273+
-->
274+
</dependencies>
275+
</project>

src/main/java/io/frictionlessdata/datapackage/Validator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import io.frictionlessdata.datapackage.exceptions.DataPackageException;
55
import io.frictionlessdata.tableschema.exception.ValidationException;
6-
import io.frictionlessdata.tableschema.schema.JsonSchema;
6+
import io.frictionlessdata.tableschema.schema.FormalSchemaValidator;
77
import io.frictionlessdata.tableschema.util.JsonUtil;
88
import org.apache.commons.validator.routines.UrlValidator;
99

@@ -57,7 +57,7 @@ public static void validate(JsonNode jsonObjectToValidate, String profileId) thr
5757

5858
InputStream inputStream = Validator.class.getResourceAsStream("/schemas/" + profileId + ".json");
5959
if(inputStream != null){
60-
JsonSchema schema = JsonSchema.fromJson(inputStream, true);
60+
FormalSchemaValidator schema = FormalSchemaValidator.fromJson(inputStream, true);
6161
schema.validate(jsonObjectToValidate); // throws a ValidationException if this object is invalid
6262

6363
}else{
@@ -77,7 +77,7 @@ public static void validate(JsonNode jsonObjectToValidate, String profileId) thr
7777
public static void validate(JsonNode jsonObjectToValidate, URL schemaUrl) throws IOException, DataPackageException, ValidationException{
7878
try{
7979
InputStream inputStream = schemaUrl.openStream();
80-
JsonSchema schema = JsonSchema.fromJson(inputStream, true);
80+
FormalSchemaValidator schema = FormalSchemaValidator.fromJson(inputStream, true);
8181
schema.validate(jsonObjectToValidate); // throws a ValidationException if this object is invalid
8282

8383
}catch(FileNotFoundException e){

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

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/test/java/io/frictionlessdata/datapackage/beans/GrossDomesticProductBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.time.Year;
88

99
@JsonPropertyOrder({
10-
"countryName", "countryCode", "year", "amount"
10+
"Country Name", "Country Code", "Year", "Value"
1111
})
1212
public class GrossDomesticProductBean {
1313

src/test/java/io/frictionlessdata/datapackage/resource/ResourceTest.java

Lines changed: 35 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
import io.frictionlessdata.datapackage.exceptions.DataPackageException;
99
import io.frictionlessdata.tableschema.schema.Schema;
1010
import io.frictionlessdata.tableschema.util.JsonUtil;
11-
import org.junit.Assert;
12-
import org.junit.Rule;
1311
import org.junit.jupiter.api.Assertions;
1412
import org.junit.jupiter.api.DisplayName;
1513
import org.junit.jupiter.api.Test;
16-
import org.junit.rules.ExpectedException;
1714

1815
import java.io.File;
1916
import java.math.BigInteger;
@@ -46,9 +43,6 @@ public class ResourceTest {
4643
testResources.add(resource2);
4744
}
4845

49-
@Rule
50-
public final ExpectedException exception = ExpectedException.none();
51-
5246
@Test
5347
public void testIterateDataFromUrlPath() throws Exception{
5448

@@ -74,9 +68,9 @@ public void testIterateDataFromUrlPath() throws Exception{
7468
String year = record[1];
7569
String population = record[2];
7670

77-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
78-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
79-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
71+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
72+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
73+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
8074

8175
expectedDataIndex++;
8276
}
@@ -103,9 +97,9 @@ public void testIterateDataFromFilePath() throws Exception{
10397
String year = record[1];
10498
String population = record[2];
10599

106-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
107-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
108-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
100+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
101+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
102+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
109103

110104
expectedDataIndex++;
111105
}
@@ -146,8 +140,8 @@ public void testIterateDataFromMultipartFilePath() throws Exception{
146140
String city = record[0];
147141
String coords = record[1];
148142

149-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
150-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], coords);
143+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
144+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], coords);
151145

152146
expectedDataIndex++;
153147
}
@@ -190,8 +184,8 @@ public void testIterateDataFromMultipartURLPath() throws Exception{
190184
String city = record[0];
191185
String coords = record[1];
192186

193-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
194-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], coords);
187+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
188+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], coords);
195189

196190
expectedDataIndex++;
197191
}
@@ -216,9 +210,9 @@ public void testIterateDataWithCast() throws Exception{
216210
while(iter.hasNext()){
217211
Object[] record = iter.next();
218212

219-
Assert.assertEquals(String.class, record[0].getClass());
220-
Assert.assertEquals(Year.class, record[1].getClass());
221-
Assert.assertEquals(BigInteger.class, record[2].getClass());
213+
Assertions.assertEquals(String.class, record[0].getClass());
214+
Assertions.assertEquals(Year.class, record[1].getClass());
215+
Assertions.assertEquals(BigInteger.class, record[2].getClass());
222216
}
223217
}
224218

@@ -245,9 +239,9 @@ public void testIterateDataFromCsvFormat() throws Exception{
245239
String year = record[1];
246240
String population = record[2];
247241

248-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
249-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
250-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
242+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
243+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
244+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
251245

252246
expectedDataIndex++;
253247
}
@@ -273,9 +267,9 @@ public void testBuildAndIterateDataFromCsvFormat() throws Exception{
273267
String year = record[1];
274268
String population = record[2];
275269

276-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
277-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
278-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
270+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
271+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
272+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
279273

280274
expectedDataIndex++;
281275
}
@@ -300,9 +294,9 @@ public void testBuildAndIterateDataFromTabseparatedCsvFormat() throws Exception{
300294
String year = record[1];
301295
String population = record[2];
302296

303-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
304-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
305-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
297+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
298+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
299+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
306300

307301
expectedDataIndex++;
308302
}
@@ -351,9 +345,9 @@ public void testIterateDataFromJSONFormat() throws Exception{
351345
String year = record[1];
352346
String population = record[2];
353347

354-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
355-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
356-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
348+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
349+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
350+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
357351

358352
expectedDataIndex++;
359353
}
@@ -402,9 +396,9 @@ public void testIterateDataFromJSONFormatAlternateSchema() throws Exception{
402396
String year = record[1];
403397
String population = record[2];
404398

405-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
406-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
407-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
399+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
400+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
401+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
408402

409403
expectedDataIndex++;
410404
}
@@ -430,43 +424,14 @@ public void testBuildAndIterateDataFromJSONFormat() throws Exception{
430424
String year = record[1];
431425
String population = record[2];
432426

433-
Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
434-
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], year);
435-
Assert.assertEquals(expectedData.get(expectedDataIndex)[2], population);
427+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[0], city);
428+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[1], year);
429+
Assertions.assertEquals(expectedData.get(expectedDataIndex)[2], population);
436430

437431
expectedDataIndex++;
438432
}
439433
}
440434

441-
442-
/*
443-
FIXME: since strongly typed, those don't work anymore
444-
@Test
445-
public void testCreatingJSONResourceWithInvalidFormatNullValue() throws Exception {
446-
URL url = new URL("https://raw.githubusercontent.com/frictionlessdata/" +
447-
"datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json");
448-
Package dp = new Package(url, true);
449-
450-
// format property is null but data is not null.
451-
Resource resource = new JSONDataResource("resource-name", testResources, (String)null);
452-
453-
exception.expectMessage("Invalid Resource. The data and format properties cannot be null.");
454-
dp.addResource(resource);
455-
}
456-
457-
@Test
458-
public void testCreatingResourceWithInvalidFormatDataValue() throws Exception {
459-
URL url = new URL("https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/multi_data_datapackage.json");
460-
Package dp = new Package(url, true);
461-
462-
// data property is null but format is not null.
463-
Resource resource = new JSONDataResource("resource-name", (String)null, "csv");
464-
465-
exception.expectMessage("Invalid Resource. The path property or the data and format properties cannot be null.");
466-
dp.addResource(resource);
467-
}
468-
469-
*/
470435
@Test
471436
public void testRead() throws Exception{
472437
Resource resource = buildResource("/fixtures/data/population.csv");
@@ -475,7 +440,7 @@ public void testRead() throws Exception{
475440
resource.setProfile(Profile.PROFILE_TABULAR_DATA_RESOURCE);
476441

477442
// Assert
478-
Assert.assertEquals(3, resource.getData(false, false, false, false).size());
443+
Assertions.assertEquals(3, resource.getData(false, false, false, false).size());
479444
}
480445

481446
@Test
@@ -496,9 +461,9 @@ public void testHeadings() throws Exception{
496461
resource.setProfile(Profile.PROFILE_TABULAR_DATA_RESOURCE);
497462

498463
// Assert
499-
Assert.assertEquals("city", resource.getHeaders()[0]);
500-
Assert.assertEquals("year", resource.getHeaders()[1]);
501-
Assert.assertEquals("population", resource.getHeaders()[2]);
464+
Assertions.assertEquals("city", resource.getHeaders()[0]);
465+
Assertions.assertEquals("year", resource.getHeaders()[1]);
466+
Assertions.assertEquals("population", resource.getHeaders()[2]);
502467
}
503468

504469

0 commit comments

Comments
 (0)