Skip to content

Commit

Permalink
[Test] Add tests for the #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Kulich committed Aug 29, 2022
1 parent 70b41fd commit b652c1e
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import cz.cvut.spipes.modules.exception.TableSchemaException;
import cz.cvut.spipes.test.JenaTestUtils;
import cz.cvut.spipes.util.StreamResourceUtils;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -17,8 +16,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class TabularModuleTest extends AbstractModuleTestHelper {
Expand Down Expand Up @@ -150,6 +148,51 @@ public void execute_TableSchemaWithNoExistingColumn_throwsException() throws URI
assertThrows(TableSchemaException.class, () -> module.executeSelf());
}

@Test
public void executeSimpleTransformationWithoutHeaders() throws URISyntaxException, IOException {
module.setSkipHeader(true);

module.setSourceResource(
StreamResourceUtils.getStreamResource(DATA_PREFIX,getFilePath("examples/noHeader/schemaExample/input.csv"))
);

Model inputModel = JenaTestUtils.laodModelFromResource("/examples/noHeader/schemaExample/input-data-schema.ttl");
module.setInputContext(ExecutionContextFactory.createContext(inputModel));

ExecutionContext outputContext = module.executeSelf();

String[] columns = new String[]{"col_1", "col_2", "col_3", "col_4", "col_5"};

for (int i = 1; i <= 3; i++) {
Resource resource = ResourceFactory.createResource(DATA_PREFIX + "#row-" + i);
for (String column: columns) {
Property property = ResourceFactory.createProperty(DATA_PREFIX, column);
assertTrue(outputContext.getDefaultModel().contains(resource, property));
}
}
}

@Test
public void executeWithSimpleTransformationWithoutHeaders_NoSchema() throws URISyntaxException, IOException {
module.setSkipHeader(true);

module.setSourceResource(
StreamResourceUtils.getStreamResource(DATA_PREFIX,getFilePath("examples/noHeader/noSchemaExample/input.tsv"))
);

ExecutionContext outputContext = module.executeSelf();

for (int i = 1; i <= 3; i++) {
Resource resource = ResourceFactory.createResource(DATA_PREFIX + "#row-" + i);
for (int j = 1; j <= 6; j++) {
String columnName = "column_" + j;
Property property = ResourceFactory.createProperty(DATA_PREFIX, columnName);

assertTrue(outputContext.getDefaultModel().contains(resource, property));
}
}
}

@Override
public String getModuleName() {
return "tabular";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
6568520 59999 KULICMAT 08.04.2022 16:00 09.04.2022
6797451 59999 KULICMAT 06.02.2022 14:00 06.03.2022
6797461 59999 KULICMAT 16.07.2022 13:00 18.08.2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
_:b0 <http://www.w3.org/ns/csvw#name>
"bookingno_i" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/bookingno_i" ;
<http://www.w3.org/ns/csvw#title>
"bookingno_i" .

[ a <http://www.w3.org/ns/csvw#TableGroup> ;
<http://www.w3.org/ns/csvw#table>
[ a <http://www.w3.org/ns/csvw#Table> ;
<http://www.w3.org/ns/csvw#row>
[ a <http://www.w3.org/ns/csvw#Row> ;
<http://www.w3.org/ns/csvw#describes>
<http://onto.fel.cvut.cz/data/#row-3> ;
<http://www.w3.org/ns/csvw#rownum>
2 ;
<http://www.w3.org/ns/csvw#url>
<http://onto.fel.cvut.cz/data/#row=3>
] ;
<http://www.w3.org/ns/csvw#row>
[ a <http://www.w3.org/ns/csvw#Row> ;
<http://www.w3.org/ns/csvw#describes>
<http://onto.fel.cvut.cz/data/#row-2> ;
<http://www.w3.org/ns/csvw#rownum>
1 ;
<http://www.w3.org/ns/csvw#url>
<http://onto.fel.cvut.cz/data/#row=2>
] ;
<http://www.w3.org/ns/csvw#tableSchema>
[ a <http://www.w3.org/ns/csvw#TableSchema> ;
<http://www.w3.org/ns/csvw#aboutUrl>
"http://onto.fel.cvut.cz/data/#row-{_row}"^^<http://www.w3.org/ns/csvw#uriTemplate> ;
<http://www.w3.org/ns/csvw#column>
_:b1 , _:b2 , _:b3 , _:b4 , _:b5 , _:b0 ;
<http://www.w3.org/ns/csvw#columns>
( _:b0
_:b5
_:b4
_:b3
_:b2
_:b1
)
] ;
<http://www.w3.org/ns/csvw#url>
<http://onto.fel.cvut.cz/data/>
]
] .

_:b4 <http://www.w3.org/ns/csvw#name>
"user_sign" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/user_sign" ;
<http://www.w3.org/ns/csvw#title>
"user_sign" .

_:b2 <http://www.w3.org/ns/csvw#name>
"Start_Time" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/Start_Time" ;
<http://www.w3.org/ns/csvw#title>
"Start Time" .

<http://onto.fel.cvut.cz/data/#row-3>
<http://onto.fel.cvut.cz/data/Employee_No>
"59999" ;
<http://onto.fel.cvut.cz/data/End_Date>
"06.03.2022" ;
<http://onto.fel.cvut.cz/data/Start_Date>
"06.02.2022" ;
<http://onto.fel.cvut.cz/data/Start_Time>
"14:00" ;
<http://onto.fel.cvut.cz/data/bookingno_i>
"6797451" ;
<http://onto.fel.cvut.cz/data/user_sign>
"KULICMAT" .

_:b3 <http://www.w3.org/ns/csvw#name>
"Start_Date" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/Start_Date" ;
<http://www.w3.org/ns/csvw#title>
"Start Date" .

<http://onto.fel.cvut.cz/data/#row-2>
<http://onto.fel.cvut.cz/data/Employee_No>
"59999" ;
<http://onto.fel.cvut.cz/data/End_Date>
"09.04.2022" ;
<http://onto.fel.cvut.cz/data/Start_Date>
"08.04.2022" ;
<http://onto.fel.cvut.cz/data/Start_Time>
"16:00" ;
<http://onto.fel.cvut.cz/data/bookingno_i>
"6568520" ;
<http://onto.fel.cvut.cz/data/user_sign>
"KULICMAT" .

_:b1 <http://www.w3.org/ns/csvw#name>
"End_Date" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/End_Date" ;
<http://www.w3.org/ns/csvw#title>
"End Date" .

_:b5 <http://www.w3.org/ns/csvw#name>
"Employee_No" ;
<http://www.w3.org/ns/csvw#propertyUrl>
"http://onto.fel.cvut.cz/data/Employee_No" ;
<http://www.w3.org/ns/csvw#title>
"Employee No" .
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@prefix : <http://onto.fel.cvut.cz/data/data-schema/> .
@prefix csvw: <http://www.w3.org/ns/csvw#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .


:input-data-schema a owl:Ontology .

:input-table-schema a csvw:TableSchema ;
csvw:column :Column_1 ;
csvw:column :Column_2 ;
csvw:column :Column_3 ;
csvw:column :Column_4 ;
csvw:column :Column_5 ;
csvw:columns ( :Column_1 :Column_2 :Column_3 :Column_4 :Column_5) ;

.

:Column_1 a csvw:Column;
csvw:name "col_1";
csvw:title "col_1";
.
:Column_2 a csvw:Column;
csvw:name "col_2" ;
csvw:title "col_2";
.
:Column_3 a csvw:Column;
csvw:name "col_3" ;
csvw:title "col_3";
.

:Column_4 a csvw:Column;
csvw:name "col_4" ;
csvw:title "col_4";
.

:Column_5 a csvw:Column;
csvw:name "col_5" ;
csvw:title "col_5";
.

csvw:property a rdf:Property .
csvw:property rdfs:range rdf:Property .
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
50000 A 1 2021-09-28 05:39:04
50000 N 2 2021-09-28 18:08:22
50036 A 1 2021-09-24 05:58:57

0 comments on commit b652c1e

Please sign in to comment.