Skip to content

Commit

Permalink
[#145] Restore cucumber acceptance tests (#177)
Browse files Browse the repository at this point in the history
* [#145] Moved OutputStreamOutStream to testing package

* [#145] Added IostreamChannel

* [#145] Renamed RawConnection->DirectConnection, IostreamChannel->LocalChannel

* [#145] Moved old accept tests and updated test dep versions / added BOMs

* [#145] Improved docs

* [#145] ByteString.toString more readable

* [#145] Moved testing components to src/test and added test deps

* [#145] Added reset to ByteStringBuilder

* [#145] Added indexOf, count, substring to ByteString

* [#145] Ensure logging works correctly in tests

* [#145] Improve logging across Z-Expressions

* [#145] ByteString.from() -> byteString(), to improve static imports

* [#145] First working Cucumber test, with LocalConnection and LocalChannel

* [#145] Fix test

* [#145] Improved logging

* [#145] Better buffer tokenization tools and exceptions

* [#145] Device acceptance tests

* [#145] Better debugging

* [#145] Full local device test capability

* [#145] ZscriptExpression.fields(), and field matching for tests

* [#145] Acceptance steps and general logic and device tests

* [#145] Extended tests for parsing and response matching

* [#145] Added more cucumber tests, and deleted experimental code

* [#145] Added more cucumber tests

* [#145] Added more cucumber tests

* [#145] Fixed LocalChannel test

* [#145] Fixed GCC (after upgrade to v13)

* [#145] Added more cucumber tests
  • Loading branch information
susanw1 authored Jan 10, 2025
1 parent 3273dcb commit 1786a18
Show file tree
Hide file tree
Showing 148 changed files with 4,018 additions and 765 deletions.
37 changes: 37 additions & 0 deletions acceptance-tests-old/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.zscript</groupId>
<artifactId>zscript-all</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>acceptance-tests-old</artifactId>
<name>Zscript Acceptance Tests (OLD)</name>

<dependencies>
<dependency>
<!-- Note: test dependencies are scoped here as "compile" because this is a test project -->
<groupId>net.zscript</groupId>
<artifactId>java-testing-deps</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.junit.vintage</groupId>-->
<!-- <artifactId>junit-vintage-engine</artifactId>-->
<!-- </dependency>-->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

public class AcceptanceTestAssert extends AcceptanceTestMessageAssert {
private final AcceptanceTestConnection connection;
private final byte[] toSend;
private final AcceptanceFuture future = new AcceptanceFuture();
private int otherMessagesInFlight;
private final byte[] toSend;
private final AcceptanceFuture future = new AcceptanceFuture();
private int otherMessagesInFlight;

public AcceptanceTestAssert(AcceptanceTestConnection connection, byte[] toSend, int otherMessagesInFlight) {
this.connection = connection;
Expand All @@ -41,10 +41,10 @@ public Future<?> send() {

private void acceptResponse(byte[] resp) {
try {
PushbackInputStream in = new PushbackInputStream(new ByteArrayInputStream(resp));
AcceptanceTestResponseSequence seq = new AcceptanceTestResponseSequence();
int c = in.read();
String current = "";
PushbackInputStream in = new PushbackInputStream(new ByteArrayInputStream(resp));
AcceptanceTestResponseSequence seq = new AcceptanceTestResponseSequence();
int c = in.read();
String current = "";
while (c != -1) {
in.unread(c);
AcceptanceTestResponse parsedResp = new AcceptanceTestResponse();
Expand All @@ -69,10 +69,10 @@ private void acceptResponse(byte[] resp) {
}

private class AcceptanceFuture implements Future<Void> {
private final ReentrantLock lock = new ReentrantLock();
private final Condition complete = lock.newCondition();
private Throwable failure = null;
private boolean comp = false;
private final ReentrantLock lock = new ReentrantLock();
private final Condition complete = lock.newCondition();
private Throwable failure = null;
private boolean comp = false;

public void complete() {
lock.lock();
Expand Down
76 changes: 73 additions & 3 deletions acceptance-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,87 @@
<type>pom</type>
</dependency>

<dependency>
<!-- Get devices and actual direct connections -->
<groupId>net.zscript</groupId>
<artifactId>zscript-java-client-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.zscript</groupId>
<artifactId>zscript-java-client-command-builders</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.zscript</groupId>
<artifactId>java-receiver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.zscript</groupId>
<artifactId>java-receiver</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<artifactId>cucumber-junit-platform-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<configuration>
<systemProperties>
<zscript.acceptance.conn.local.java>true</zscript.acceptance.conn.local.java>
</systemProperties>
</configuration>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<executions>
<execution>
<id>default</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Zscript Features</projectName>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.zscript.acceptance;

import java.util.concurrent.atomic.AtomicReference;

import static net.zscript.util.ByteString.byteString;
import static net.zscript.util.ByteString.byteStringUtf8;
import static org.assertj.core.api.Assertions.assertThat;

import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.zscript.javaclient.commandPaths.CommandExecutionPath;
import net.zscript.javaclient.commandPaths.ResponseExecutionPath;
import net.zscript.javaclient.sequence.ResponseSequence;
import net.zscript.javaclient.tokens.ExtendingTokenBuffer;

public class BasicSequenceSteps {
private static final Logger LOG = LoggerFactory.getLogger(BasicSequenceSteps.class);

private final DeviceSteps deviceSteps;
private ResponseExecutionPath actualExecutionPath;

public BasicSequenceSteps(DeviceSteps deviceSteps) {
this.deviceSteps = deviceSteps;
}

@When("the command sequence {string} is sent to the target")
public void sendCommandSequence(String commandSequenceAsText) {
final AtomicReference<ResponseExecutionPath> response = new AtomicReference<>();

final ExtendingTokenBuffer buffer = ExtendingTokenBuffer.tokenize(byteStringUtf8(commandSequenceAsText), true);
final CommandExecutionPath commandPath = CommandExecutionPath.parse(deviceSteps.getModel(), buffer.getTokenReader().getFirstReadToken());

deviceSteps.getTestDeviceHandle().send(commandPath, response::set);

deviceSteps.progressDeviceWhile(t -> response.get() == null);

actualExecutionPath = response.get();
}

@Then("the response sequence should match {string}")
public void responseSequenceShouldMatch(String responseSequenceAsText) {
final ExtendingTokenBuffer buffer = ExtendingTokenBuffer.tokenize(byteStringUtf8(responseSequenceAsText));
final ResponseSequence expectedResponseSeq = ResponseSequence.parse(buffer.getTokenReader().getFirstReadToken());

LOG.trace("sequence match: [actualExecutionPath={}, expectedResponseSeq = {}", actualExecutionPath, expectedResponseSeq);
assertThat(byteString(actualExecutionPath)).isEqualTo(byteString(expectedResponseSeq.getExecutionPath()));
}
}
Loading

0 comments on commit 1786a18

Please sign in to comment.