Skip to content
Snippets Groups Projects
Commit 7321af79 authored by Sebastien's avatar Sebastien
Browse files

Merge branch '14-null-pointer-exception' into 'master'

Resolve "Null Pointer Exception"

Closes #14

See merge request !12
parents 1a819005 44dbdd59
Loading
Pipeline #252 passed
[S:00]
{org:en}
For transitions to and from National Operation (STM) the ETCS shall request, an acknowledgement by the driver..
{/org}
{unl}
pur(promise(icl>modal>be,obj>uw,aoj>thing).@entry,transition(icl>change_of_state>thing,equ>passage).@pl)
mod(transition(icl>change_of_state>thing,equ>passage).@pl,to(icl>how,com>content,obj>thing))
mod(operation(icl>business_activity>thing).@maiuscul,national(icl>adj,ant>international).@maiuscul)
obj(to(icl>how,com>content,obj>thing),operation(icl>business_activity>thing).@maiuscul)
nam(operation(icl>business_activity>thing).@maiuscul,stm.@parenthesis)
frm(to(icl>how,com>content,obj>thing),)
aoj(promise(icl>modal>be,obj>uw,aoj>thing).@entry,etcs.@def)
agt(request(icl>communicate>do,agt>volitional_thing,obj>thing),etcs.@def)
obj(promise(icl>modal>be,obj>uw,aoj>thing).@entry,request(icl>communicate>do,agt>volitional_thing,obj>thing))
cnt(promise(icl>modal>be,obj>uw,aoj>thing).@entry,acknowledgement(icl>message>thing,equ>acknowledgment).@indef)
met(acknowledgement(icl>message>thing,equ>acknowledgment).@indef,driver(icl>operator>thing,ant>nondriver).@def)
{/unl}
[/S]
......@@ -53,3 +53,11 @@ popd
```
# Generate jar file
```shell
$ mvn package
$ cd unl-tools-main/target
# you should see unl-tools-main-0.9.jar that is the standalone jar file.
```
\ No newline at end of file
......@@ -18,7 +18,8 @@ public class ExportUnlDocumentsHandler implements CommandHandler<ExportUnlDocume
public Result handle(ExportUnlDocuments command) {
try {
var graphExporter = factory.createGraphExporter(command.getWriter(), command.getExporterName());
graphExporter.write(command.getGraphImporter().Import());
var importedGraph = command.getGraphImporter().Import();
graphExporter.write(importedGraph);
} catch (IOException | GraphExportException e) {
return Result.Failure(String.format("Cannot export unl documents to format '%s' (reason: '%s')", command.getExporterName(), e.getMessage()),
e);
......
......@@ -8,11 +8,13 @@ import java.io.InputStreamReader;
import java.util.List;
public class UnlGraphImporterFromUnlParser implements GraphImporter {
private List<UnlDocument> documents;
private BufferedReader bufferedReader;
WrapperUnlParser wrapper;
public UnlGraphImporterFromUnlParser(BufferedReader bufferedReader) {
this.bufferedReader = bufferedReader;
this.wrapper = null;
}
public static UnlGraphImporterFromUnlParser FromInputReader(InputStreamReader inputStreamReader) {
......@@ -21,13 +23,14 @@ public class UnlGraphImporterFromUnlParser implements GraphImporter {
@Override
public List<UnlDocument> Import() {
if (documents == null) {
try {
documents = new UnlParser(this.bufferedReader).createUnlDocumentList();
} catch (ParseException e) {
e.printStackTrace();
}
if (this.wrapper == null) {
this.wrapper = new WrapperUnlParser(this.bufferedReader);
this.wrapper.parseUnlSource();
if(this.wrapper.hasError()){
var message = String.format("Current error: '%s'", String.join(",", wrapper.getErrors()));
throw new RuntimeException(message);
}
}
return documents;
return wrapper.getUnlDocumentList();
}
}
......@@ -26,7 +26,7 @@ public class WrapperUnlParser {
}
public void parseUnlSource(){
parseContentAndRetrieveErrors();
parseContentIfNecessary();
}
/**
......
......@@ -21,27 +21,10 @@ class Unl2RdfTest {
}
@Tag("integration")
@Test
public void r1ShouldBeConvertedToRdfFile() {
Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "r1", "--output-type", "rdf"}));
}
@Tag("integration")
@Test
public void r2ShouldBeConvertedToRdfFile() {
Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "r2", "--output-type", "rdf"}));
}
@Tag("integration")
@Test
public void catShouldBeConvertedToRdfFile() {
Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "cat", "--output-type", "rdf"}));
}
@Tag("integration")
@Test
public void exemplesShouldBeConvertedToRdfFile() {
Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "exemples_unl", "--output-type", "rdf"}));
@ParameterizedTest(name = "RuntimeException({index}) ==> Unl2Rdf.main({arguments})")
@ArgumentsSource(TestMainShouldNotThrowRuntimeExceptionParameterArgumentProvider.class)
public void TestMainShouldNotThrowRuntimeException(String[] args) {
Assertions.assertThrows(RuntimeException.class, () -> Unl2Rdf.main(args));
}
static class TestMainShouldNotThrowOnPartialParameterArgumentProvider implements ArgumentsProvider {
......@@ -49,9 +32,33 @@ class Unl2RdfTest {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream.of(
Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"})
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"})
);
}
}
static class TestMainShouldNotThrowRuntimeExceptionParameterArgumentProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream.of(
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "dotOnly", "--output-type", "dot"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}),
Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"})
);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment