-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Werner <[email protected]>
- Loading branch information
Showing
27 changed files
with
941 additions
and
229 deletions.
There are no files selected for viewing
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,7 @@ | ||
testResults/ | ||
build | ||
.gradle/ | ||
.idea/ | ||
allure-results/ | ||
.venv/ | ||
testtool-out/ |
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
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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Skript to check proper licensing setup | ||
|
||
./gradlew clean checkLicense | ||
|
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
#!/bin/bash | ||
|
||
./gradlew checkLicense | ||
|
||
echo TODO: start the below as screen sessions, stop after tests! | ||
echo "cd ../deployments/n61850-smqtt-ubuntu2004/ && docker-compose up" | ||
echo "cd ../hedera-61850-gateway/ && docker-compose up" | ||
echo mosquitto_sub -t fledge/south-schedule -i schedule-subscriber | ||
echo mosquitto_sub -t fledge/south-command -i cmd-subscriber | ||
|
||
./gradlew test | ||
echo "All tests run. Please see the logs in testResults/ directory for details" |
This file was deleted.
Oops, something went wrong.
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
111 changes: 0 additions & 111 deletions
111
conformance-tests/src/main/java/org/openmuc/fnn/steuerbox/ScheduleWriterExample.java
This file was deleted.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
conformance-tests/src/main/java/org/openmuc/fnn/steuerbox/mqtt/Command.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,60 @@ | ||
package org.openmuc.fnn.steuerbox.mqtt; | ||
|
||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.openmuc.fnn.steuerbox.mqtt.ParsingUtil.parseMqttMessages; | ||
|
||
/** | ||
* A command payload representing a control signal intended for the EMS. | ||
* <p> | ||
* Only relevant parameters will be parsed, most of the JSON fields are FLEDGE defaults and not relevant for the | ||
* ReLevENT use cases. | ||
*/ | ||
public class Command { | ||
public Command(long epochSecond, double controlValue) { | ||
this.epochSecond = epochSecond; | ||
this.controlValue = controlValue; | ||
} | ||
|
||
public final long epochSecond; | ||
public final double controlValue; | ||
|
||
public static Command fromJsonString(String command) | ||
throws ParserConfigurationException, IOException, SAXException { | ||
List<Map.Entry<Instant, Double>> entries = parseMqttMessages(command); | ||
if (entries.size() != 1) { | ||
throw new IllegalArgumentException( | ||
"Expected exactly 1 element to be returned. Are you trying to parse a schedule as a command?"); | ||
} | ||
Map.Entry<Instant, Double> instantDoubleEntry = entries.get(0); | ||
return new Command(instantDoubleEntry.getKey().getEpochSecond(), instantDoubleEntry.getValue()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Command{" + "epochSecond=" + epochSecond + "(equivalent to " + Instant.ofEpochSecond(epochSecond) | ||
+ "), controlValue=" + controlValue + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
Command command = (Command) o; | ||
return epochSecond == command.epochSecond && Double.compare(controlValue, command.controlValue) == 0; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(epochSecond, controlValue); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
conformance-tests/src/main/java/org/openmuc/fnn/steuerbox/mqtt/ParsingUtil.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,71 @@ | ||
package org.openmuc.fnn.steuerbox.mqtt; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.openmuc.fnn.steuerbox.Context; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.AbstractMap; | ||
import java.util.Iterator; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Utilities to parse JSON messages | ||
*/ | ||
public class ParsingUtil { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(ParsingUtil.class); | ||
|
||
private ParsingUtil() { | ||
// prevent calling constructor: utility class with no members | ||
} | ||
|
||
/** | ||
* Deserialize a schedule for communication with HEDERA-61850-interface. | ||
* <p> | ||
* Will use a switch to not communicate the request to HEDERA but instead immediately forward it to the IEC 61850 | ||
* FLEDGE scheduling server | ||
*/ | ||
public static String scheduleToJson(List values, Duration interval, Instant start) { | ||
ScheduleResolution scheduleResolution = ScheduleResolution.from(interval); | ||
return String.format("{\"skipHedera\":true," // | ||
+ "\"direction\":\"IMPORT\","// | ||
+ "\"start\":{\"seconds\":%s,\"nanos\":%s},"// | ||
+ "\"resolution\":\"%s\"," // | ||
+ "\"values\":[%s]}", start.getEpochSecond(), start.getNano(), scheduleResolution.name(), | ||
values.stream().map(Object::toString).collect(Collectors.joining(","))); | ||
} | ||
|
||
/** | ||
* Utility to parse command or schedule parameters from a JSON message (command and schedules are very alike: a | ||
* schedule is like an array of commands) | ||
*/ | ||
static List<Map.Entry<Instant, Double>> parseMqttMessages(String commandOrScheduleJson) { | ||
List<Map.Entry<Instant, Double>> entities = new LinkedList<>(); | ||
try { | ||
Iterator<JsonNode> parameters = Context.getObjectMapper() | ||
.readTree(commandOrScheduleJson) | ||
.get("parameters") | ||
.elements(); | ||
while (parameters.hasNext()) { | ||
JsonNode parameter = parameters.next(); | ||
JsonNode apcTypNode = parameter.get("value").get("GTIC").get("ApcTyp"); | ||
JsonNode tNode = apcTypNode.get("t"); | ||
long epochSeconds = tNode.get("SecondSinceEpoch").longValue(); | ||
double controlValue = apcTypNode.get("ctlVal").asDouble(); | ||
long nanos = 0; // could be created from FractionOfSecond, but testing does not make sense on that base.. | ||
log.trace("Ignoring FractionOfSecond, testing on that base does not make sense"); | ||
entities.add(new AbstractMap.SimpleEntry<>(Instant.ofEpochSecond(epochSeconds, nanos), controlValue)); | ||
} | ||
return entities; | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
"Unable deserialize command from '" + commandOrScheduleJson + "': Required elements not found.", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.