Skip to content
Snippets Groups Projects
Commit e6a68f9d authored by René Schöne's avatar René Schöne
Browse files

Merge branch 'release/1.1.0' into 'main'

Version 1.1.0

See merge request !39
parents 2128755a f219a5e6
No related branches found
No related tags found
1 merge request!39Version 1.1.0
Pipeline #17588 passed
Root ::= SenderRoot ReceiverRoot;
SenderRoot ::= <SimpleValue:int> SingleA:A ;
ReceiverRoot ::= <ReceivedValue:int> SomeA:A ;
A ::= <Value> Inner ;
Inner ::= <InnerValue> ;
package org.jastadd.ragconnect.tests;
import org.jastadd.ragconnect.tests.utils.TestUtils;
import org.junit.jupiter.api.BeforeEach;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jastadd.ragconnect.tests.utils.TestUtils.readFile;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* TODO: Add description.
*
* @author rschoene - Initial contribution
*/
public abstract class AbstractCompilerTest extends RagConnectTest {
protected abstract String getDirectoryName();
protected String getOutputDirectory() {
return TestUtils.OUTPUT_DIRECTORY_PREFIX + getDirectoryName();
}
protected abstract String getDefaultGrammarName();
@BeforeEach
public void ensureOutputDirectory() {
File outputDirectory = new File(getOutputDirectory());
assertTrue((outputDirectory.exists() && outputDirectory.isDirectory()) || outputDirectory.mkdir());
}
protected Path test(String inputDirectoryName, int expectedReturnValue, String rootNode, String... connectNames) throws IOException {
String grammarFile = Paths.get(inputDirectoryName, getDefaultGrammarName() + ".relast").toString();
List<String> connectFiles = Arrays.stream(connectNames)
.map(connectName -> Paths.get(inputDirectoryName,connectName + ".connect").toString())
.collect(Collectors.toList());
return TestUtils.runCompiler(grammarFile, connectFiles, rootNode,
getDirectoryName(), expectedReturnValue);
}
protected void testAndCompare(String inputDirectoryName, String expectedName, String rootNode, String... connectNames) throws IOException {
Path outPath = test(inputDirectoryName, 1, rootNode, connectNames);
final String startOfErrorsPattern = "Errors:\n";
String out = readFile(outPath, Charset.defaultCharset());
assertThat(out).contains(startOfErrorsPattern);
out = out.substring(out.indexOf(startOfErrorsPattern) + startOfErrorsPattern.length());
TestUtils.assertLinesMatch(getDirectoryName(), expectedName, out);
logger.info("ragconnect for " + expectedName + " returned:\n{}", out);
}
}
......@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.*;
* @author rschoene - Initial contribution
*/
@Tag("Incremental")
@Tag("New")
public class AttributeTest extends AbstractMqttTest {
private static final String TOPIC_WILDCARD = "attr/#";
......
package org.jastadd.ragconnect.tests;
import org.jastadd.ragconnect.tests.utils.TestUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jastadd.ragconnect.tests.utils.TestUtils.readFile;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test error messages.
*
* @author rschoene - Initial contribution
*/
public class ErrorsTest extends RagConnectTest {
private static final String ERROR_DIRECTORY = "errors/";
private static final String OUTPUT_DIRECTORY = TestUtils.OUTPUT_DIRECTORY_PREFIX + ERROR_DIRECTORY;
public class ErrorsTest extends AbstractCompilerTest {
private static final String DEFAULT_GRAMMAR_NAME = "Errors";
@Override
protected String getDirectoryName() {
return "errors";
}
@BeforeAll
public static void createOutputDirectory() {
File outputDirectory = new File(OUTPUT_DIRECTORY);
assertTrue((outputDirectory.exists() && outputDirectory.isDirectory()) || outputDirectory.mkdir());
@Override
protected String getDefaultGrammarName() {
return "Errors";
}
@Test
void testStandardErrors() throws IOException {
test("Standard", "A", "Standard");
testAndCompare(getDirectoryName(), "Standard", "A", "Standard");
}
@Test
void testTwoPartsErrors() throws IOException {
test("Part", "A", "Part1", "Part2");
testAndCompare(getDirectoryName(), "Part", "A", "Part1", "Part2");
}
@SuppressWarnings("SameParameterValue")
private void test(String expectedName, String rootNode, String... connectNames) throws IOException {
String grammarFile = ERROR_DIRECTORY + DEFAULT_GRAMMAR_NAME + ".relast";
List<String> connectFiles = Arrays.stream(connectNames)
.map(connectName -> ERROR_DIRECTORY + connectName + ".connect")
.collect(Collectors.toList());
Path outPath = TestUtils.runCompiler(grammarFile, connectFiles, rootNode, ERROR_DIRECTORY, 1);
final String startOfErrorsPattern = "Errors:\n";
String out = readFile(outPath, Charset.defaultCharset());
assertThat(out).contains(startOfErrorsPattern);
out = out.substring(out.indexOf(startOfErrorsPattern) + startOfErrorsPattern.length());
TestUtils.assertLinesMatch(ERROR_DIRECTORY, expectedName, out);
logger.info("ragconnect for " + expectedName + " returned:\n{}", out);
}
}
......@@ -150,7 +150,10 @@ public class JavaTest extends RagConnectTest {
model.ragconnectJavaPush(TOPIC_RECEIVE_NTA, ExposingASTNode.INSTANCE.aToBytes(createA("12")));
checker.put(TOPIC_RECEIVE_NTA, "12").check();
}
@AfterEach
public void printEvaluationSummary() {
System.out.println(model.ragconnectEvaluationCounterSummary());
}
......
package org.jastadd.ragconnect.tests;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Paths;
/**
* Use cases that just need to compile.
*
* @author rschoene - Initial contribution
*/
public class PassingTest extends AbstractCompilerTest {
@Override
protected String getDirectoryName() {
return "passing";
}
@Override
protected String getDefaultGrammarName() {
return "Test";
}
protected void run(String inputDirectoryName, String rootNode) throws IOException {
super.test(Paths.get("passing", inputDirectoryName).toString(),
0, rootNode, getDefaultGrammarName());
}
@Test
public void testInheritance() throws IOException {
run("inheritance", "Root");
}
}
package org.jastadd.ragconnect.tests;
import org.jastadd.ragconnect.tests.utils.TestChecker;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import restClientServer.ast.*;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Testing RestClient.
*
* @author rschoene - Initial contribution
*/
public class RestClientServerTest extends RagConnectTest {
private Root root;
private TestChecker checker;
private static final String TOPIC_NT_A_VALUE = "nt/a/value";
private static final String TOPIC_NT_A_INNER_VALUE = "nt/a/inner/value";
@Test
public void testSimpleSenderRest() throws IOException {
root.getSenderRoot().setSimpleValue(1);
assertThat(root.getReceiverRoot().connectReceivedValue("restClient://localhost:4567/serve-simple")).isTrue();
assertThat(root.getSenderRoot().connectSimpleValue("rest://localhost:4567/serve-simple", true)).isTrue();
assertThat(root.getReceiverRoot().getReceivedValue()).isEqualTo(1);
root.getSenderRoot().setSimpleValue(2);
assertThat(root.getReceiverRoot().getReceivedValue()).isEqualTo(2);
}
@Test
public void testSimpleSenderRestClient() throws IOException {
root.getSenderRoot().setSimpleValue(1);
assertThat(root.getReceiverRoot().connectReceivedValue("rest://localhost:4567/put-simple")).isTrue();
assertThat(root.getSenderRoot().connectSimpleValue("restClient://localhost:4567/put-simple", true)).isTrue();
assertThat(root.getReceiverRoot().getReceivedValue()).isEqualTo(1);
root.getSenderRoot().setSimpleValue(2);
assertThat(root.getReceiverRoot().getReceivedValue()).isEqualTo(2);
}
@Test
public void testNonterminalSenderRest() throws IOException {
A a = new A().setValue("a1");
a.setInner(new Inner().setInnerValue("1"));
root.getSenderRoot().setSingleA(a);
checker.put(TOPIC_NT_A_VALUE, "a1")
.put(TOPIC_NT_A_INNER_VALUE, "1");
assertThat(root.getReceiverRoot().connectSomeA("rest://localhost:4567/put-nt")).isTrue();
assertThat(root.getSenderRoot().connectSingleA("restClient://localhost:4567/put-nt", true)).isTrue();
communicateNonterminal();
}
@Test
@Disabled("Receiving nonterminals using restClient is not supported yet")
public void testNonterminalSenderRestClient() throws IOException {
A a = new A().setValue("a1");
a.setInner(new Inner().setInnerValue("1"));
root.getSenderRoot().setSingleA(a);
assertThat(root.getReceiverRoot().connectSomeA("restClient://localhost:4567/serve-nt")).isTrue();
assertThat(root.getSenderRoot().connectSingleA("rest://localhost:4567/serve-nt", true)).isTrue();
communicateNonterminal();
}
private void communicateNonterminal() {
A a = root.getSenderRoot().getSingleA();
checker.check();
a.setValue("a23");
checker.put(TOPIC_NT_A_VALUE, "a23").check();
a.getInner().setInnerValue("abc");
checker.put(TOPIC_NT_A_INNER_VALUE, "abc").check();
}
@BeforeEach
public void createModel() {
root = new Root();
root.setReceiverRoot(new ReceiverRoot());
root.setSenderRoot(new SenderRoot());
checker = new TestChecker().setActualNumberOfValues(() -> 0);
checker.setCheckForString(TOPIC_NT_A_VALUE, (name, expected) ->
assertThat(someAValue()).describedAs(name).isEqualTo(expected))
.setCheckForString(TOPIC_NT_A_INNER_VALUE, (name, expected) ->
assertThat(someAInnerValueOrNull()).describedAs(name).isEqualTo(expected))
;
}
private String someAValue() {
if (root.getReceiverRoot().getSomeA() == null) {
return null;
}
return root.getReceiverRoot().getSomeA().getValue();
}
private String someAInnerValueOrNull() {
if (root.getReceiverRoot().getSomeA() == null || root.getReceiverRoot().getSomeA().getInner() == null) {
return null;
}
return root.getReceiverRoot().getSomeA().getInner().getInnerValue();
}
@AfterEach
public void close() {
root.ragconnectCloseConnections();
}
}
......@@ -16,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.*;
* @author rschoene - Initial contribution
*/
@Tag("Tree")
@Tag("New")
public abstract class AbstractTreeTest extends AbstractMqttTest {
protected static final String TOPIC_ALFA = "alfa";
protected ReceiverData data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment