-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentTest.java
More file actions
615 lines (528 loc) · 25 KB
/
AgentTest.java
File metadata and controls
615 lines (528 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
package be.ugent.idlab.knows.functions.agent;
import be.ugent.idlab.knows.functions.agent.dataType.DataTypeConverterProvider;
import be.ugent.idlab.knows.functions.agent.exception.AgentException;
import be.ugent.idlab.knows.functions.agent.functionIntantiation.Instantiator;
import be.ugent.idlab.knows.functions.agent.functionIntantiation.exception.InstantiationException;
import be.ugent.idlab.knows.functions.agent.functionModelProvider.FunctionModelProvider;
import be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.FnOFunctionModelProvider;
import be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.exception.FnOException;
import be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.exception.FunctionNotFoundException;
import be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.exception.ParameterNotFoundException;
import be.ugent.idlab.knows.functions.agent.model.Function;
import be.ugent.idlab.knows.functions.internalfunctions.InternalTestFunctions;
import be.ugent.idlab.knows.misc.FileFinder;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.NAMESPACES.IDLABFN;
import static be.ugent.idlab.knows.functions.agent.functionModelProvider.fno.NAMESPACES.RDF;
import static org.junit.jupiter.api.Assertions.*;
/**
* <p>
* Copyright 2022 IDLab (Ghent University - imec)
* </p>
*
* @author Gerald Haesendonck
*/
public class AgentTest {
private static final String FNS = "http://example.com/functions#";
private static final String EX = "http://example.org/";
@Test
public void testEverythingGoesWell() throws Exception {
// first initialize a DataTaypeConverterProvider
final DataTypeConverterProvider dataTypeConverterProvider = new DataTypeConverterProvider();
// first initialize a functionModelProvider
FunctionModelProvider functionProvider = new FnOFunctionModelProvider(dataTypeConverterProvider, "src/test/resources/internalTestFunctions.ttl");
Map<String, Function> functions = functionProvider.getFunctions();
// construct an initiator using those functions
Instantiator instantiator = new Instantiator(functions, dataTypeConverterProvider);
// Construct an Agent
Agent agent = new AgentImpl(functions, instantiator);
execute(agent);
}
@Test
public void testWithFactory() throws Exception {
Agent agent = AgentFactory.createFromFnO("internalTestFunctions.ttl");
execute(agent);
}
@Test
public void testGrelClassesOnClassPath() throws Exception {
Agent agent = AgentFactory.createFromFnO("functions_grel.ttl", "grel_java_mapping.ttl");
executeGrel(agent);
}
@Test
public void testGrelClassesOnClassPathRemoteFnODoc() throws Exception {
Agent agent = AgentFactory.createFromFnO("https://raw.githubusercontent.com/FnOio/grel-functions-fno/752738bd613614947105f1b32859d1cb1f0bcf20/grel.ttl", "grel_java_mapping.ttl");
executeGrel(agent);
}
@Test
public void testBooleanConversionAsStringListGrel() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("functions_grel.ttl", "grel_java_mapping.ttl")) {
// prepare the parameters for the function
Arguments arguments = new Arguments()
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#param_rep_b", "false")
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#param_rep_b", "false");
// execute the function
Object result = agent.execute("http://users.ugent.be/~bjdmeest/function/grel.ttl#boolean_and", arguments);
assertFalse((Boolean) result, "\"false\" | \"false\" should be false");
}
}
@Test
public void testAaabimFromJar() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("aaabim_java_mapping.ttl")) {
final String aaabimPrefix = "http://users.ugent.be/~tdlva/function/aaabim.ttl#";
final Arguments arguments = new Arguments().add(aaabimPrefix + "p_milliseconds", 1591782480076L);
// execute the function
result = agent.execute(aaabimPrefix + "millisecondsToInstant", arguments);
}
assertTrue(result instanceof Instant);
Instant resultingTimeInstant = (Instant) result;
String resultFormattedTime = resultingTimeInstant.toString();
assertEquals("2020-06-10T09:48:00.076Z", resultFormattedTime);
System.out.println();
}
@Test
public void testAaabimWithImportsFromJar() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("aaabim_java_mapping.ttl")) {
final String aaabimPrefix = "http://users.ugent.be/~tdlva/function/aaabim.ttl#";
final Arguments arguments = new Arguments().add(aaabimPrefix + "p_geohash", "u14dhw2phg54");
// execute the function
result = agent.execute(aaabimPrefix + "geoHashToLatitude", arguments);
}
assertTrue(result instanceof Double);
assertEquals(3.7135869450867176d, result);
System.out.println();
}
/**
* Tests if a function that takes an RDF List as parameter in the descriptions works with
* an implementation that has a method that takes a Java array as input parameter.
*/
@Test
public void testListFnO_ArrayImplementation() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("src/test/resources/functions_grel.ttl", "grel_java_mapping.ttl")) {
// prepare the parameter: a list of ints to take the sum of
Arguments arguments = new Arguments()
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#p_array_a", 1)
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#p_array_a", 4);
// Execute the array_sum function
result = agent.execute("http://users.ugent.be/~bjdmeest/function/grel.ttl#array_sum", arguments);
}
assertEquals(5, result, "1 + 4 should be 5");
}
private void execute(final Agent agent) throws Exception {
// prepare the parameters for the function
Arguments arguments = new Arguments()
.add(EX + "p_int1", "5")
.add(EX + "p_int2", "1");
// execute the function
Object result = agent.execute(EX + "sum", arguments);
assertEquals(6L, result, "5 + 1 should be 6");
}
private void executeGrel(final Agent agent) throws Exception {
// prepare the parameters for the function
Arguments arguments = new Arguments()
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#param_rep_b", false)
.add("http://users.ugent.be/~bjdmeest/function/grel.ttl#param_rep_b", true);
// execute the function
Object result = agent.execute("http://users.ugent.be/~bjdmeest/function/grel.ttl#boolean_or", arguments);
assertTrue((Boolean) result, "false | true should be true");
}
@Test
public void testCompositeFunctionSum3() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("sum-composition.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
// fns:aParameter fns:bParameter fns:cParameter
.add(FNS + "a", "1")
.add(FNS + "b", "2")
.add(FNS + "c", "3");
result = agent.execute(FNS + "sum3", arguments);
}
assertEquals(6L, result, "1 + 2 + 3 should be 6");
}
@Test
public void testCompositeFunctionAdd10() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("add10.ttl")) {
Arguments arguments = new Arguments().add(FNS + "b10", "5");
result = agent.execute(FNS + "add10", arguments);
}
assertEquals(15L, result, "5 + 10 should be 15");
}
@Test
public void testCompositeFunctionComplexLinearDependencies() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "computation.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 4)
.add(EX + "p_int2", 2)
.add(EX + "p_int3", 3)
.add(EX + "p_int4", 5);
result = agent.execute(FNS + "computation", arguments);
}
assertEquals(980L, result, "4*(2+3^5) should be 980");
}
@Test
public void testCompositeFunctionComplexNonLinearDependencies() throws Exception {
// calculate (a+b)² with the formula a² + 2ab + b²
Object result;
try (Agent agent = AgentFactory.createFromFnO("sum-composition.ttl", "squareOfSum.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 4)
.add(EX + "p_int2", 5);
result = agent.execute(FNS + "squareOfSum", arguments);
}
assertEquals(81L, result, "(4+5)² should be 81");
}
@Test
public void testIdentityFunctionNoImplemenation() throws Exception {
// the identity function implemented only as a composition
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "identityInteger.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", "1");
result = agent.execute(FNS + "identityInteger", arguments);
assertEquals(1L, result, "Identity function should return input");
arguments = new Arguments()
.add(EX + "p_int1", "2");
result = agent.execute(FNS + "identityInteger", arguments);
}
assertEquals(2L, result, "Identity function should return input");
}
@Test
public void testThrowExceptionForCyclicDependencies() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "identityInteger.ttl", "cyclic.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", "1");
assertThrows(InstantiationException.class, () -> agent.execute(FNS + "cyclicFunction", arguments), "expected an exception to be thrown");
}
}
@Test
public void aliasTest() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "aliasTest.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 1)
.add(EX + "p_int2", 2);
result = agent.execute(FNS + "sumAlias", arguments);
}
assertEquals(3L, result, "alias should work as original function");
}
@Test
public void testThrowExceptionForNonExistingFunction() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("badFunction.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 1);
assertThrows(Exception.class, () -> agent.execute(FNS + "bad", arguments), "expected an exception");
}
}
@Test
public void testThrowExceptionForNonExistingParameter() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("badParameter.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 1);
assertThrows(InstantiationException.class, () -> agent.execute(FNS + "bad", arguments), "expected an exception");
}
}
@Test
public void testCompositeFunctionSum3WithDebug() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("sum-composition.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
// fns:aParameter fns:bParameter fns:cParameter
.add(FNS + "a", "1")
.add(FNS + "b", "2")
.add(FNS + "c", "3");
result = agent.execute(FNS + "sum3", arguments, true);
}
assertEquals(6L, result, "1 + 2 + 3 should be 6");
URL file = FileFinder.findFile("test.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.openStream()));
String line = bufferedReader.readLine();
assertEquals(6, Integer.parseInt(line), "print effect did not trigger");
}
@Test
public void testCompositeFunctionAdd10WithDebug() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("add10.ttl")) {
Arguments arguments = new Arguments().add(FNS + "b10", "5");
result = agent.execute(FNS + "add10", arguments, true);
}
assertEquals(15L, result, "5 + 10 should be 15");
}
@Test
public void testCompositeFunctionComplexLinearDependenciesWithDebug() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "computation.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 4)
.add(EX + "p_int2", 2)
.add(EX + "p_int3", 3)
.add(EX + "p_int4", 5);
result = agent.execute(FNS + "computation", arguments, true);
}
assertEquals(980L, result, "4*(2+3^5) should be 980");
}
@Test
public void testCompositeFunctionComplexNonLinearDependenciesWithDebug() throws Exception {
// calculate (a+b)² with the formula a² + 2ab + b²
Object result;
try (Agent agent = AgentFactory.createFromFnO("sum-composition.ttl", "squareOfSum.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", 4)
.add(EX + "p_int2", 5);
result = agent.execute(FNS + "squareOfSum", arguments, true);
}
assertEquals(81L, result, "(4+5)² should be 81");
}
@Test
public void testCompositeFunctionWithComplexSidePath() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("complex_side_path.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments()
// fns:aParameter fns:bParameter fns:cParameter
.add(FNS + "a", "1")
.add(FNS + "b", "2")
.add(FNS + "c", "3");
result = agent.execute(FNS + "complexSidePath", arguments, true);
}
assertEquals(6L, result, "1 + 2 + 3 should be 6");
URL file = FileFinder.findFile("test0.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.openStream()));
String line = bufferedReader.readLine();
assertEquals(12L, Integer.parseInt(line), "print effect did not trigger");
}
@Test
public void testPartialFunctionApplication() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "add10PartialApplication.ttl")) {
Arguments arguments = new Arguments().add(EX + "p_int2", 15);
result = agent.execute(FNS + "add10", arguments);
}
assertEquals(25L, result, "15 + 10 should be 25");
}
@Test
public void testPartialFunctionApplicationWithCompositions() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "add10PartialApplicationWithComposition.ttl", "sum-composition.ttl")) {
Arguments arguments = new Arguments().add(FNS + "a", 15);
result = agent.execute(FNS + "add10", arguments);
}
assertEquals(25L, result, "15 + 10 should be 25");
}
@Test
public void testPartialApplicationThrowsExceptionNonExistingFunction() {
assertThrows(FunctionNotFoundException.class, () -> {
Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "badPartialApplicationFunction.ttl");
agent.close();
}, "expected an exception");
}
@Test
public void testPartialApplicationThrowsExceptionNonExistingParameter() {
assertThrows(ParameterNotFoundException.class, () -> {
Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "badPartialApplicationParameter.ttl");
agent.close();
}, "expected an exception");
}
@Test
public void testPartialApplicationWithoutMappingsIsApplies() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("partialApplicationNoMappings.ttl", "generalFunctions.ttl")) {
Arguments arguments = new Arguments().add(EX + "p_int1", 5).add(EX + "p_int2", 15);
result = agent.execute(FNS + "add10", arguments);
}
assertEquals(20L, result, "15 + 5 should be 20");
}
@Test
public void functionWithoutReturnValue() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl")) {
Arguments arguments = new Arguments()
// fns:aParameter fns:bParameter fns:cParameter
.add(EX + "p_int1", "1")
.add(EX + "p_string", "test1.txt");
result = agent.execute(EX + "writeToFileNoReturn", arguments, false);
}
assertNull(result);
}
@Test
public void rdfListFromSeqTest1Element() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_1", "a");
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<String> correct = new ArrayList<>();
correct.add("a");
assertEquals(correct, result, "should be a list with element a");
}
@Test
public void rdfListFromSeqTest2Elements() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_1", "a")
.add(RDF + "_2", "b");
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<String> correct = new ArrayList<>();
correct.add("a");
correct.add("b");
assertEquals(correct, result, "should be a list with elements a and b");
}
@Test
public void rdfListFromSeqTest4ElementOneMissing() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_1", "a")
.add(RDF + "_2", "b")
.add(RDF + "_4", "d");
assertThrows(AgentException.class, () -> agent.execute(IDLABFN + "makeListFromSeq", arguments), "expected exception for missing _3 parameter");
}
}
@Test
public void rdfSeqTest1Element() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_1", "a");
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<String> correct = new ArrayList<>();
correct.add("a");
assertEquals(correct, result, "should be a list with element a");
}
@Test
public void rdfSeqTest2Element() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_2", "b")
.add(RDF + "_1", "a");
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<String> correct = new ArrayList<>();
correct.add("a");
correct.add("b");
assertEquals(correct, result, "should be a list with elements a and b");
}
@Test
public void rdfSeqTestNoErrorForNegativeIndex() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_-1", "a")
.add(RDF + "_1", "x");
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<String> correct = new ArrayList<>();
correct.add("x");
assertEquals(correct, result, "should be a list with element x");
}
@Test
public void rdfSeqTestElementsAreLists() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeq.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_2", List.of(1, 2))
.add(RDF + "_1", List.of("3", "4", "5"));
result = agent.execute(IDLABFN + "makeListFromSeq", arguments);
}
List<?> correct = List.of(
List.of("3", "4", "5"),
List.of(1, 2)
);
assertEquals(correct, result, "should be a list with elements a and b");
}
@Test
public void testExtraDependencies1() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "weirdComposition1.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", "5")
.add(EX + "p_int2", "4");
assertEquals(90L, agent.execute(FNS + "comp", arguments), "expected 90");
}
}
@Test
public void testExtraDependencies2() throws Exception {
try (Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "weirdComposition2.ttl")) {
Arguments arguments = new Arguments()
.add(EX + "p_int1", "5")
.add(EX + "p_int2", "4");
assertEquals(28L, agent.execute(FNS + "comp", arguments), "expected 28");
}
}
@Test
public void loadNonStaticFunctionThrowsException() throws FnOException {
try (AgentImpl agent = (AgentImpl) AgentFactory.createFromFnO()) {
assertThrows(Exception.class, () -> agent.loadFunction(this.getClass().getMethods()[0])); // all test methods are non static
}
}
@Test
public void loadJavaFunctionTest() throws Exception {
Object result;
try (AgentImpl agent = (AgentImpl) AgentFactory.createFromFnO()) {
String functionId = agent.loadFunction(InternalTestFunctions.class.getMethod("sum", long.class, long.class));
List<String> list = agent.getParameterPredicates(functionId);
Arguments args = new Arguments()
.add(list.get(0), 5)
.add(list.get(1), 6);
result = agent.execute(functionId, args);
}
assertEquals(11L, result, "5 + 6 is 11");
}
@Test
public void testWriteModel() throws Exception {
try (AgentImpl agent = (AgentImpl) AgentFactory.createFromFnO("generalFunctions.ttl")) {
agent.writeModel("testFileWrite.ttl");
}
try (AgentImpl agent = (AgentImpl) AgentFactory.createFromFnO("testFileWrite.ttl")) {
execute(agent);
}
}
@Test
public void testWriteExecutionToFile() throws Exception {
try (AgentImpl agent = (AgentImpl) AgentFactory.createFromFnO("internalTestFunctions.ttl")) {
// prepare the parameters for the function
Arguments arguments = new Arguments().add(EX + "p_int1", "5").add(EX + "p_int2", "1");
// execute the function
agent.executeToFile(EX + "sum", arguments, "testExecution.ttl");
}
}
// @Test
// public void testWriteModelWithComposition() throws Exception{
// Agent agent = AgentFactory.createFromFnO("generalFunctions.ttl", "sum-composition.ttl");
// agent.writeModel("testFileWriteWithComposition.ttl");
// agent = AgentFactory.createFromFnO("testFileWriteWithComposition.ttl");
// Arguments arguments = new Arguments()
// // fns:aParameter fns:bParameter fns:cParameter
// .add(FNS+"a", "1")
// .add(FNS+"b", "2")
// .add(FNS+"c", "3");
//
// Object result = agent.execute(FNS+"sum3", arguments);
//
// assertEquals("1 + 2 + 3 should be 6", 6L, result);
// }
@Test
public void testGenericsInCollectionAsFunctionParameter() throws Exception {
Object result;
try (Agent agent = AgentFactory.createFromFnO("rdfSeqGenerics.ttl")) {
Arguments arguments = new Arguments()
.add(RDF + "_1", "a")
.add(RDF + "_2", "b")
.add(EX + "delimiter", " precedes ");
result = agent.execute(EX + "concatSequence", arguments, true);
}
assertEquals("a precedes b", result );
}
}