-
Notifications
You must be signed in to change notification settings - Fork 10
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: Osman Hadzic <[email protected]>
- Loading branch information
1 parent
76471b9
commit bdbb2d0
Showing
21 changed files
with
1,529 additions
and
1 deletion.
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,76 @@ | ||
# | ||
# This file is part of Astarte. | ||
# | ||
# Copyright 2023 SECO Mind Srl | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
name: End to End test | ||
permissions: | ||
contents: read | ||
on: | ||
push: | ||
# Run on branch/tag creation | ||
create: | ||
# Run on pull requests | ||
pull_request: | ||
|
||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
env: | ||
CARGO_TERM_COLOR: always | ||
jobs: | ||
e2e-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Create Astarte Cluster | ||
id: astarte | ||
uses: astarte-platform/astarte-cluster-action@v1 | ||
with: | ||
astarte_version: "1.1.1" | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
- name: Install interface | ||
run: | | ||
astartectl realm-management interfaces sync $GITHUB_WORKSPACE/tests/e2etest/GenericTest/src/main/resources/standard-interfaces/*.json --non-interactive | ||
astartectl realm-management interfaces ls | ||
- name: Register device | ||
run: | | ||
echo "E2E_REALM=test" >> $GITHUB_ENV | ||
DEVICE_ID=$(astartectl utils device-id generate-random) | ||
echo "E2E_DEVICE_ID=$DEVICE_ID" >> $GITHUB_ENV | ||
CREDENTIALS_SECRET=$(astartectl pairing agent register --compact-output -- "$DEVICE_ID") | ||
echo "E2E_CREDENTIALS_SECRET=$CREDENTIALS_SECRET" >> $GITHUB_ENV | ||
echo "Java_LOG=debug" >> $GITHUB_ENV | ||
TOKEN=$(astartectl utils gen-jwt appengine) | ||
echo "E2E_TOKEN=$TOKEN" >> $GITHUB_ENV | ||
echo "E2E_API_URL=https://api.autotest.astarte-platform.org" >> $GITHUB_ENV | ||
- name: Set up JDK | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Generate SSL certificates | ||
run: | | ||
sudo openssl s_client -connect api.autotest.astarte-platform.org:443 -showcerts </dev/null 2>/dev/null|openssl x509 -outform PEM > ${GITHUB_WORKSPACE}/astarte-certificates.pem | ||
openssl x509 -outform der -in ${GITHUB_WORKSPACE}/astarte-certificates.pem -out ${GITHUB_WORKSPACE}/astarte-certificates.der | ||
echo $JAVA_HOME | ||
KEYSTORE_PATH=$JAVA_HOME/lib/security/cacerts | ||
sudo keytool -import -noprompt -trustcacerts -alias "astarteroot-cert" -file ${GITHUB_WORKSPACE}/astarte-certificates.der -keystore $KEYSTORE_PATH -storepass changeit | ||
sudo keytool -keystore $KEYSTORE_PATH -storepass changeit -list | grep astarteroot-cert | ||
- name: Build with Gradle | ||
run: ./gradlew :tests:e2etest:GenericTest:run |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'application' | ||
} | ||
|
||
application { | ||
mainClassName = 'org.astarteplatform.devicesdk.tests.e2etest.GenericDevice' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation project(path: ':DeviceSDKGeneric') | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' | ||
implementation 'commons-cli:commons-cli:1.4' | ||
implementation 'com.h2database:h2:1.4.200' | ||
} | ||
|
||
tasks.withType(Javadoc).all { enabled = false } |
94 changes: 94 additions & 0 deletions
94
...est/src/main/java/org/astarteplatform/devicesdk/tests/e2etest/GenericAggregateDevice.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,94 @@ | ||
package org.astarteplatform.devicesdk.tests.e2etest; | ||
|
||
import java.io.IOException; | ||
import java.util.*; | ||
import org.astarteplatform.devicesdk.AstarteDevice; | ||
import org.astarteplatform.devicesdk.protocol.*; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.AstarteHttpRequest; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericDeviceMockData; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericDeviceMockDataFactory; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericMockDevice; | ||
import org.astarteplatform.devicesdk.transport.AstarteTransportException; | ||
import org.joda.time.DateTime; | ||
|
||
public class GenericAggregateDevice implements AstarteAggregateDatastreamEventListener { | ||
private final GenericDeviceMockData m_deviceMockData; | ||
private final GenericMockDevice m_mockDevice; | ||
private final AstarteDevice m_astarteGenericDevice; | ||
|
||
private final AstarteHttpRequest astarteHttpRequest; | ||
|
||
public GenericAggregateDevice() throws Exception { | ||
m_deviceMockData = new GenericDeviceMockDataFactory(); | ||
m_astarteGenericDevice = m_deviceMockData.getAstarteDeviceSingleton(); | ||
m_mockDevice = m_deviceMockData.getMockData(); | ||
astarteHttpRequest = new AstarteHttpRequest(); | ||
} | ||
|
||
public void aggregateFromDeviceToServer() | ||
throws AstarteInvalidValueException, AstarteInterfaceMappingNotFoundException, | ||
AstarteTransportException, IOException, InterruptedException { | ||
|
||
System.out.println( | ||
"Test for aggregated object datastreams" + " in the direction from device to server."); | ||
String interfaceName = m_mockDevice.getInterfaceDeviceAggr(); | ||
|
||
AstarteDeviceAggregateDatastreamInterface astarteDeviceAggregateDatastream = | ||
(AstarteDeviceAggregateDatastreamInterface) | ||
m_astarteGenericDevice.getInterface(interfaceName); | ||
|
||
astarteDeviceAggregateDatastream.streamData( | ||
"/seco", m_mockDevice.getMockDataDictionary(), DateTime.now()); | ||
|
||
Thread.sleep(1000); | ||
|
||
List<Object> response = | ||
astarteHttpRequest | ||
.getServerInterface(interfaceName) | ||
.getJSONObject("data") | ||
.getJSONArray("seco") | ||
.toList(); | ||
|
||
if (response.isEmpty()) { | ||
System.exit(1); | ||
} | ||
|
||
Map<String, Object> object = (Map<String, Object>) response.get(0); | ||
|
||
object.remove("timestamp"); | ||
|
||
if (!m_mockDevice.compereHasMas(object)) { | ||
System.exit(1); | ||
} | ||
} | ||
|
||
public void aggregateFromServerToDevice() throws IOException { | ||
System.out.println( | ||
"Test for aggregated object datastreams" + " in the direction from server to device."); | ||
String interfaceName = m_mockDevice.getInterfaceServerAggr(); | ||
|
||
AstarteServerAggregateDatastreamInterface astarteServerAggregateDatastream = | ||
(AstarteServerAggregateDatastreamInterface) | ||
m_astarteGenericDevice.getInterface(interfaceName); | ||
|
||
astarteServerAggregateDatastream.addListener(this); | ||
|
||
Map<String, Object> data = m_mockDevice.getMockDataDictionary(); | ||
|
||
astarteHttpRequest.postServerInterface(interfaceName, "/seco", data); | ||
} | ||
|
||
@Override | ||
public void valueReceived(AstarteAggregateDatastreamEvent e) { | ||
|
||
System.out.println( | ||
"Received aggregate datastream value on interface " | ||
+ e.getInterfaceName() | ||
+ ", values: " | ||
+ e.getValues()); | ||
|
||
if (!m_mockDevice.compereHasMas(e.getValues())) { | ||
System.exit(1); | ||
} | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
...st/src/main/java/org/astarteplatform/devicesdk/tests/e2etest/GenericDatastreamDevice.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,149 @@ | ||
package org.astarteplatform.devicesdk.tests.e2etest; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.astarteplatform.devicesdk.AstarteDevice; | ||
import org.astarteplatform.devicesdk.protocol.*; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.AstarteHttpRequest; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericDeviceMockData; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericDeviceMockDataFactory; | ||
import org.astarteplatform.devicesdk.tests.e2etest.utilities.GenericMockDevice; | ||
import org.astarteplatform.devicesdk.transport.AstarteTransportException; | ||
import org.joda.time.DateTime; | ||
import org.json.JSONObject; | ||
|
||
public class GenericDatastreamDevice implements AstarteDatastreamEventListener { | ||
|
||
private GenericDeviceMockData m_deviceMockData; | ||
private GenericMockDevice m_mockDevice; | ||
private AstarteDevice m_astarteGenericDevice; | ||
private AstarteHttpRequest m_astarteHttpRequest; | ||
|
||
public GenericDatastreamDevice() throws Exception { | ||
m_deviceMockData = new GenericDeviceMockDataFactory(); | ||
m_astarteGenericDevice = m_deviceMockData.getAstarteDeviceSingleton(); | ||
m_mockDevice = m_deviceMockData.getMockData(); | ||
m_astarteHttpRequest = new AstarteHttpRequest(); | ||
} | ||
|
||
public void datastreamFromDeviceToServer() | ||
throws AstarteInvalidValueException, AstarteInterfaceMappingNotFoundException, | ||
AstarteTransportException, IOException, InterruptedException { | ||
|
||
System.out.println("Test for individual datastreams in the direction from device to server."); | ||
|
||
String interfaceName = m_mockDevice.getInterfaceDeviceData(); | ||
|
||
AstarteDeviceDatastreamInterface astarteDatastreamInterface = | ||
(AstarteDeviceDatastreamInterface) m_astarteGenericDevice.getInterface(interfaceName); | ||
|
||
for (Map.Entry<String, Object> entry : m_mockDevice.getMockDataDictionary().entrySet()) { | ||
astarteDatastreamInterface.streamData("/" + entry.getKey(), entry.getValue(), DateTime.now()); | ||
Thread.sleep(500); | ||
} | ||
|
||
JSONObject response = m_astarteHttpRequest.getServerInterface(interfaceName); | ||
|
||
if (response.isEmpty()) { | ||
System.exit(1); | ||
} | ||
|
||
JSONObject dataMap = response.getJSONObject("data"); | ||
|
||
Map<String, Object> object = new HashMap<>(); | ||
Map<String, Object> map = dataMap.toMap(); | ||
|
||
for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
HashMap<String, Object> temp = (HashMap<String, Object>) entry.getValue(); | ||
String key = entry.getKey(); | ||
for (Map.Entry<String, Object> e : temp.entrySet()) { | ||
if (e.getKey().equals("value")) { | ||
object.put(key, e.getValue()); | ||
} | ||
} | ||
} | ||
if (!m_mockDevice.compereHasMas(object)) { | ||
System.exit(1); | ||
} | ||
} | ||
|
||
public void datastreamFromServerToDevice() throws IOException { | ||
|
||
System.out.println("Test for individual datastreams in the direction from server to device."); | ||
|
||
String interfaceName = m_mockDevice.getInterfaceServerData(); | ||
|
||
AstarteServerDatastreamInterface astarteServerDatastreamInterface = | ||
(AstarteServerDatastreamInterface) m_astarteGenericDevice.getInterface(interfaceName); | ||
|
||
astarteServerDatastreamInterface.addListener(this); | ||
|
||
for (Map.Entry<String, Object> entry : m_mockDevice.getMockDataDictionary().entrySet()) { | ||
m_astarteHttpRequest.postServerInterface( | ||
interfaceName, "/" + entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public void valueReceived(AstarteDatastreamEvent e) { | ||
for (Map.Entry<String, Object> entry : m_mockDevice.getMockDataDictionary().entrySet()) { | ||
if (entry.getKey().equals(e.getPath().replace("/sensorUuid/", ""))) { | ||
if (e.getValue().getClass().isArray()) { | ||
if (e.getValue() instanceof Integer[]) { | ||
Integer[] dest = new Integer[((Integer[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((Integer[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (Integer[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof Double[]) { | ||
Double[] dest = new Double[((Double[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, (((Double[]) e.getValue()).length)); | ||
if (!Arrays.equals(dest, (Double[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof Long[]) { | ||
Long[] dest = new Long[((Long[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((Long[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (Long[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof String[]) { | ||
String[] dest = new String[((String[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((String[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (String[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof byte[]) { | ||
byte[] dest = new byte[((byte[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((byte[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (byte[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof DateTime[]) { | ||
DateTime[] dest = new DateTime[((DateTime[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((DateTime[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (DateTime[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} else if (e.getValue() instanceof Boolean[]) { | ||
Boolean[] dest = new Boolean[((Boolean[]) e.getValue()).length]; | ||
System.arraycopy(e.getValue(), 0, dest, 0, ((Boolean[]) e.getValue()).length); | ||
if (!Arrays.equals(dest, (Boolean[]) e.getValue())) { | ||
System.exit(1); | ||
} | ||
} | ||
} else if (e.getValue() instanceof DateTime) { | ||
if (!m_mockDevice.compareDates((DateTime) entry.getValue())) { | ||
System.exit(1); | ||
} | ||
} else { | ||
if (!e.getValue().equals(entry.getValue())) { | ||
System.exit(1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.