Skip to content

Commit

Permalink
Created tests for 2 config properties.
Browse files Browse the repository at this point in the history
They work correctly now.
  • Loading branch information
bnouwt committed Nov 21, 2024
1 parent 53b26fb commit 40dac34
Showing 1 changed file with 108 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package eu.knowledge.engine.smartconnector.misc;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.concurrent.ExecutionException;
Expand All @@ -17,6 +19,7 @@
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.ExchangeInfo;
import eu.knowledge.engine.smartconnector.api.GraphPattern;
import eu.knowledge.engine.smartconnector.util.KnowledgeNetwork;
import eu.knowledge.engine.smartconnector.util.MockedKnowledgeBase;
Expand All @@ -25,11 +28,12 @@ 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;
private KnowledgeNetwork kn;
private MockedKnowledgeBase kb1;
private AskKnowledgeInteraction askKI;
private MockedKnowledgeBase kb2;
private AnswerKnowledgeInteraction answerKI;
private int waitTimeout = 0;

@BeforeEach
public void beforeTest() {
Expand All @@ -39,15 +43,39 @@ public void beforeTest() {
intializeKB2();
kn.addKB(kb1);
kn.addKB(kb2);

LOG.info("Before sync...");
kn.sync();
LOG.info("After sync...");
}

@Test
public void testConfigValidateDefault() {
public void testConfigValidateTrue() {
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();
assertTrue(askResult.getExchangeInfoPerKnowledgeBase().iterator().hasNext());
var info = askResult.getExchangeInfoPerKnowledgeBase().iterator().next();

assertEquals(ExchangeInfo.Status.FAILED, info.getStatus());
assertTrue(info.getFailedMessage().contains("java.lang.IllegalArgumentException"));

} catch (InterruptedException | ExecutionException e) {
LOG.info("{}", e);
}

LOG.info("Result: {}", askResult);
}

@Test
public void testConfigValidateFalse() {
System.setProperty("sc.validate.outgoing.bindings.wrt.incoming.bindings", "false");

BindingSet bs = new BindingSet();

Expand All @@ -60,7 +88,70 @@ public void testConfigValidateDefault() {
AskResult askResult = null;
try {
askResult = future.get();
// TODO check for FAILED and Illegal argument in exchange info.
assertTrue(askResult.getExchangeInfoPerKnowledgeBase().iterator().hasNext());
var info = askResult.getExchangeInfoPerKnowledgeBase().iterator().next();

assertEquals(ExchangeInfo.Status.SUCCEEDED, info.getStatus());
assertEquals(null, info.getFailedMessage());

} catch (InterruptedException | ExecutionException e) {
LOG.info("{}", e);
}

LOG.info("Result: {}", askResult);
}

@Test
public void testConfigWaitForKnowledgeBaseNegative() {
System.setProperty("ke.kb.wait.timeout", "1");
waitTimeout = 2000;

BindingSet bs = new BindingSet();

var bs1 = new Binding();
bs1.put("s", "<barry1>");
bs.add(bs1);

var future = kb1.ask(this.askKI, bs);

AskResult askResult = null;
try {
askResult = future.get();
assertTrue(askResult.getExchangeInfoPerKnowledgeBase().iterator().hasNext());
var info = askResult.getExchangeInfoPerKnowledgeBase().iterator().next();

assertEquals(ExchangeInfo.Status.FAILED, info.getStatus());
assertTrue(info.getFailedMessage() != null);
assertTrue(info.getFailedMessage().contains("TimeoutException"));

} catch (InterruptedException | ExecutionException e) {
LOG.info("{}", e);
}

LOG.info("Result: {}", askResult);
waitTimeout = 0;
}

@Test
public void testConfigWaitForKnowledgeBasePositive() {
System.setProperty("ke.kb.wait.timeout", "2");
waitTimeout = 0;
BindingSet bs = new BindingSet();

var bs1 = new Binding();
bs1.put("s", "<barry1>");
bs.add(bs1);

var future = kb1.ask(this.askKI, bs);

AskResult askResult = null;
try {
askResult = future.get();
assertTrue(askResult.getExchangeInfoPerKnowledgeBase().iterator().hasNext());
var info = askResult.getExchangeInfoPerKnowledgeBase().iterator().next();

assertEquals(ExchangeInfo.Status.SUCCEEDED, info.getStatus());
assertEquals(null, info.getFailedMessage());

} catch (InterruptedException | ExecutionException e) {
LOG.info("{}", e);
Expand Down Expand Up @@ -101,6 +192,13 @@ private void intializeKB2() {
b.put("p", "<barry1>");
b.put("name", "\"Barry Nouwt\"");
bs.add(b);

try {
Thread.sleep(waitTimeout);
} catch (InterruptedException e) {
fail();
}

return bs;
});
}
Expand Down

0 comments on commit 40dac34

Please sign in to comment.