Skip to content

Commit

Permalink
#9: Fixed multipart data with URL. Also implemented unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges Labrèche committed Jan 1, 2018
1 parent 83d6811 commit be6c940
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Iterator iter(boolean keyed, boolean extended, boolean cast, boolean rela
String thePath = paths.getString(i);

if (urlValidator.isValid(thePath)) {
URL url = (URL)this.getPath();
URL url = new URL(thePath);
Table table = new Table(url);
tableIteratorArray[i] = table.iterator(keyed, extended, cast, relations);

Expand Down
39 changes: 37 additions & 2 deletions src/test/java/io/frictionlessdata/datapackage/ResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testIterateDataFromFilePath() throws Exception{
}

@Test
public void testIterateDataFromMultipartPath() throws Exception{
public void testIterateDataFromMultipartFilePath() throws Exception{
List<String[]> expectedData = new ArrayList();
expectedData.add(new String[]{"libreville", "0.41,9.29"});
expectedData.add(new String[]{"dakar", "14.71,-17.53"});
Expand All @@ -93,7 +93,42 @@ public void testIterateDataFromMultipartPath() throws Exception{
expectedData.add(new String[]{"rome", "41.89,12.51"});

JSONArray multipartPathJsonArray = new JSONArray("[\"src/test/resources/fixtures/data/cities.csv\", \"src/test/resources/fixtures/data/cities2.csv\", \"src/test/resources/fixtures/data/cities3.csv\"]");
Resource resource = new Resource("population", multipartPathJsonArray);
Resource resource = new Resource("coordinates", multipartPathJsonArray);

// Set the profile to tabular data resource.
resource.setProfile(Profile.PROFILE_TABULAR_DATA_RESOURCE);

Iterator<String[]> iter = resource.iter();
int expectedDataIndex = 0;

// Assert data.
while(iter.hasNext()){
String[] record = iter.next();
String city = record[0];
String coords = record[1];

Assert.assertEquals(expectedData.get(expectedDataIndex)[0], city);
Assert.assertEquals(expectedData.get(expectedDataIndex)[1], coords);

expectedDataIndex++;
}
}

@Test
public void testIterateDataFromMultipartURLPath() throws Exception{
List<String[]> expectedData = new ArrayList();
expectedData.add(new String[]{"libreville", "0.41,9.29"});
expectedData.add(new String[]{"dakar", "14.71,-17.53"});
expectedData.add(new String[]{"ouagadougou", "12.35,-1.67"});
expectedData.add(new String[]{"barranquilla", "10.98,-74.88"});
expectedData.add(new String[]{"rio de janeiro", "-22.91,-43.72"});
expectedData.add(new String[]{"cuidad de guatemala", "14.62,-90.56"});
expectedData.add(new String[]{"london", "51.50,-0.11"});
expectedData.add(new String[]{"paris", "48.85,2.30"});
expectedData.add(new String[]{"rome", "41.89,12.51"});

JSONArray multipartPathJsonArray = new JSONArray("[\"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/data/cities.csv\", \"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/data/cities2.csv\", \"https://raw.githubusercontent.com/frictionlessdata/datapackage-java/master/src/test/resources/fixtures/data/cities3.csv\"]");
Resource resource = new Resource("coordinates", multipartPathJsonArray);

// Set the profile to tabular data resource.
resource.setProfile(Profile.PROFILE_TABULAR_DATA_RESOURCE);
Expand Down

0 comments on commit be6c940

Please sign in to comment.