-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does not work yet.
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
smart-connector/src/test/java/eu/knowledge/engine/smartconnector/misc/ConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package eu.knowledge.engine.smartconnector.misc; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import eu.knowledge.engine.smartconnector.api.AnswerExchangeInfo; | ||
import eu.knowledge.engine.smartconnector.api.AnswerKnowledgeInteraction; | ||
import eu.knowledge.engine.smartconnector.api.AskKnowledgeInteraction; | ||
import eu.knowledge.engine.smartconnector.api.AskResult; | ||
import eu.knowledge.engine.smartconnector.api.Binding; | ||
import eu.knowledge.engine.smartconnector.api.BindingSet; | ||
import eu.knowledge.engine.smartconnector.api.CommunicativeAct; | ||
import eu.knowledge.engine.smartconnector.api.GraphPattern; | ||
import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork; | ||
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase; | ||
|
||
public class ConfigurationTest { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ConfigurationTest.class); | ||
|
||
public KnowledgeNetwork kn; | ||
public MockedKnowledgeBase kb1; | ||
public AskKnowledgeInteraction askKI; | ||
public MockedKnowledgeBase kb2; | ||
public AnswerKnowledgeInteraction answerKI; | ||
|
||
@BeforeEach | ||
public void beforeTest() { | ||
this.kn = new KnowledgeNetwork(); | ||
|
||
intializeKB1(); | ||
intializeKB2(); | ||
kn.addKB(kb1); | ||
kn.addKB(kb2); | ||
|
||
LOG.info("Before sync..."); | ||
kn.sync(); | ||
LOG.info("After sync..."); | ||
} | ||
|
||
@Test | ||
public void testConfigValidateDefault() { | ||
System.setProperty("sc.validate.outgoing.bindings.wrt.incoming.bindings", "true"); | ||
|
||
BindingSet bs = new BindingSet(); | ||
|
||
var bs1 = new Binding(); | ||
bs1.put("s", "<barry2>"); | ||
bs.add(bs1); | ||
|
||
var future = kb1.ask(this.askKI, bs); | ||
|
||
AskResult askResult = null; | ||
try { | ||
askResult = future.get(); | ||
// TODO check for FAILED and Illegal argument in exchange info. | ||
|
||
} catch (InterruptedException | ExecutionException e) { | ||
LOG.info("{}", e); | ||
} | ||
|
||
LOG.info("Result: {}", askResult); | ||
} | ||
|
||
@AfterEach | ||
public void afterTTest() { | ||
try { | ||
kn.stop().get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
fail(); | ||
} | ||
} | ||
|
||
private void intializeKB1() { | ||
this.kb1 = new MockedKnowledgeBase("kb1"); | ||
GraphPattern gp1 = new GraphPattern(""" | ||
?s a <Person> . | ||
?s <hasName> ?n . | ||
"""); | ||
this.askKI = new AskKnowledgeInteraction(new CommunicativeAct(), gp1); | ||
this.kb1.register(askKI); | ||
} | ||
|
||
private void intializeKB2() { | ||
this.kb2 = new MockedKnowledgeBase("kb2"); | ||
GraphPattern gp1 = new GraphPattern(""" | ||
?p a <Person> . | ||
?p <hasName> ?name . | ||
"""); | ||
this.answerKI = new AnswerKnowledgeInteraction(new CommunicativeAct(), gp1); | ||
this.kb2.register(answerKI, (AnswerKnowledgeInteraction ki, AnswerExchangeInfo exchangeInfo) -> { | ||
var bs = new BindingSet(); | ||
var b = new Binding(); | ||
b.put("p", "<barry1>"); | ||
b.put("name", "\"Barry Nouwt\""); | ||
bs.add(b); | ||
return bs; | ||
}); | ||
} | ||
|
||
} |