Skip to content

Commit

Permalink
♻️ [Test] Added new set of test cases to test JobEngine Device Manage…
Browse files Browse the repository at this point in the history
…ment Packages Target Processors

Signed-off-by: Alberto Codutti <[email protected]>
  • Loading branch information
Coduz committed Dec 23, 2024
1 parent 18e4fc5 commit 18bcb92
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"classpath:features/jobEngine/JobEngineServiceProcessorCommandI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorConfigurationI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorKeystoreI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorPackagesI9n.feature",
},
glue = {
"org.eclipse.kapua.service.job.steps",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
###############################################################################
# Copyright (c) 2024, 2024 Eurotech and/or its affiliates and others
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Eurotech - initial API and implementation
###############################################################################
@env_docker
@it
@jobEngine
@jobEngineTargetProcessors

Feature: Job Engine Service - Packages Step Processors
Tests for Device Management Packages Processor

@setup
Scenario: Setup test resources
Given Init Security Context
And Start Docker environment with resources
| db |
| events-broker |
| job-engine |
| message-broker |
| broker-auth-service |
| consumer-lifecycle |

Scenario: Package Install - XML

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Package Download / Install |
And I add job step to job with name "Test Step - Package Download and Install - XML" and with selected job step definition and properties
| name | type | value |
| packageDownloadRequest | org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest | <?xml version="1.0" encoding="UTF-8"?><downloadRequest><uri>http://download.eclipse.org/kura/releases/3.2.0/org.eclipse.kura.demo.heater_1.0.300.dp</uri><name>heater</name><version>1.0.300</version><install>true</install></downloadRequest> |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 5s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "AWAITING_COMPLETION"
Then I wait job target to finish processing and notify completion up to 10s
And I wait for another job start up to 10s
And I wait job to finish its execution up to 5s
And I confirm that job has 2 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

Scenario: Package Install - JSON

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Package Download / Install |
And I add job step to job with name "Test Step - Package Download and Install - JSON" and with selected job step definition and properties
| name | type | value |
| packageDownloadRequest | org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest | { "uri": "http://download.eclipse.org/kura/releases/3.2.0/org.eclipse.kura.demo.heater_1.0.300.dp", "name": "heater", "version": "1.0.300", "install": true } |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 5s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "AWAITING_COMPLETION"
Then I wait job target to finish processing and notify completion up to 10s
And I wait for another job start up to 10s
And I wait job to finish its execution up to 5s
And I confirm that job has 2 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

Scenario: Package Uninstall - XML

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Package Uninstall |
And I add job step to job with name "Test Step - Package Uninstall - XML" and with selected job step definition and properties
| name | type | value |
| packageUninstallRequest | org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest | <?xml version="1.0" encoding="UTF-8"?><uninstallRequest><name>heater</name><version>1.0.300</version><reboot>false</reboot><rebootDelay>30000</rebootDelay></uninstallRequest> |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 5s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "AWAITING_COMPLETION"
Then I wait job target to finish processing and notify completion up to 10s
And I wait for another job start up to 10s
And I wait job to finish its execution up to 5s
And I confirm that job has 2 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

Scenario: Package Uninstall - JSON

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Package Uninstall |
And I add job step to job with name "Test Step - Package Uninstall - JSON" and with selected job step definition and properties
| name | type | value |
| packageUninstallRequest | org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest | { "name": "org.eclipse.kura.demo.heater", "version": "1.0.500", "reboot": false, "rebootDelay": 30000 } |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 5s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "AWAITING_COMPLETION"
Then I wait job target to finish processing and notify completion up to 10s
And I wait for another job start up to 10s
And I wait job to finish its execution up to 5s
And I confirm that job has 2 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

@teardown
Scenario: Tear down test resources
Given I logout
And KuraMock is disconnected
And Stop Docker environment
And Clean Locator Instance
Original file line number Diff line number Diff line change
Expand Up @@ -453,79 +453,106 @@ else if (topic.equals(deployGetPackages)) {
mqttClient.publish(responseTopic, responsePayload, 0, false);
} else if (topic.equals(deployExecDownload)) {
callbackParam = extractCallback(requestPayload);
KuraPayload kuraPayloadInitial = new KuraPayload();
kuraPayloadInitial.readFromByteArray(requestPayload);

KuraPayload kuraRequestPayload = new KuraPayload();
kuraRequestPayload.readFromByteArray(requestPayload);

Check warning on line 458 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L457-L458

Added lines #L457 - L458 were not covered by tests

// Reply
responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_REPLY + callbackParam.getRequestId();
KuraPayload customKuraPayload1 = new KuraPayload();
customKuraPayload1.setTimestamp(new Date());
customKuraPayload1.getMetrics().put("response.code", 200);
responsePayload = customKuraPayload1.toByteArray();
mqttClient.publish(responseTopic, responsePayload, 0, false);
Thread.sleep(100);

responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/download";
KuraPayload customKuraPayload2 = new KuraPayload();
customKuraPayload2.setTimestamp(new Date());
customKuraPayload2.getMetrics().put(JOB_ID, kuraPayloadInitial.getMetrics().get(JOB_ID));
customKuraPayload2.getMetrics().put(CLIENT_ID, clientId);
customKuraPayload2.getMetrics().put("dp.download.progress", 50);
customKuraPayload2.getMetrics().put("dp.download.size", 20409);
customKuraPayload2.getMetrics().put("dp.download.status", "IN_PROGRESS");
customKuraPayload2.getMetrics().put("dp.download.index", 0);
responsePayload = customKuraPayload2.toByteArray();
mqttClient.publish(responseTopic, responsePayload, 0, false);
Thread.sleep(100);

responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/download";
KuraPayload customKuraPayload3 = new KuraPayload();
customKuraPayload3.setTimestamp(new Date());
customKuraPayload3.getMetrics().put(JOB_ID, kuraPayloadInitial.getMetrics().get(JOB_ID));
customKuraPayload3.getMetrics().put(CLIENT_ID, clientId);
customKuraPayload3.getMetrics().put("dp.download.progress", 100);
customKuraPayload3.getMetrics().put("dp.download.size", 20409);
customKuraPayload3.getMetrics().put("dp.download.status", COMPLETED);
customKuraPayload3.getMetrics().put("dp.download.index", 0);
responsePayload = customKuraPayload3.toByteArray();
mqttClient.publish(responseTopic, responsePayload, 0, false);
Thread.sleep(100);

responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/install";
KuraPayload customKuraPayload4 = new KuraPayload();
customKuraPayload4.setTimestamp(new Date());
customKuraPayload4.getMetrics().put("dp.name", "Example Publisher-1.0.300.dp");
customKuraPayload4.getMetrics().put(JOB_ID, kuraPayloadInitial.getMetrics().get(JOB_ID));
customKuraPayload4.getMetrics().put("dp.install.progress", 100);
customKuraPayload4.getMetrics().put("dp.install.status", COMPLETED);
customKuraPayload4.getMetrics().put(CLIENT_ID, clientId);
responsePayload = customKuraPayload4.toByteArray();

KuraPayload replyKuraResponsePayload = new KuraPayload();
replyKuraResponsePayload.setTimestamp(new Date());
replyKuraResponsePayload.getMetrics().put("response.code", 200);
responsePayload = replyKuraResponsePayload.toByteArray();

Check warning on line 466 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L463-L466

Added lines #L463 - L466 were not covered by tests

mqttClient.publish(responseTopic, responsePayload, 0, false);
Thread.sleep(1000);

Check warning on line 469 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L469

Added line #L469 was not covered by tests

// Download Notification 25%
String downloadNotifyTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/download";

Check warning on line 472 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L472

Added line #L472 was not covered by tests

KuraPayload downloadNotifyPayload = new KuraPayload();
downloadNotifyPayload.setTimestamp(new Date());
downloadNotifyPayload.getMetrics().put(CLIENT_ID, clientId);
downloadNotifyPayload.getMetrics().put(JOB_ID, kuraRequestPayload.getMetrics().get(JOB_ID));
downloadNotifyPayload.getMetrics().put("dp.download.progress", 25);
downloadNotifyPayload.getMetrics().put("dp.download.size", 20409);
downloadNotifyPayload.getMetrics().put("dp.download.status", "IN_PROGRESS");
downloadNotifyPayload.getMetrics().put("dp.download.index", 0);
responsePayload = downloadNotifyPayload.toByteArray();

Check warning on line 482 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L474-L482

Added lines #L474 - L482 were not covered by tests

mqttClient.publish(downloadNotifyTopic, responsePayload, 0, false);
Thread.sleep(1000);

Check warning on line 485 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L484-L485

Added lines #L484 - L485 were not covered by tests

// Download Notification 50%
downloadNotifyPayload.setTimestamp(new Date());
downloadNotifyPayload.getMetrics().put("dp.download.progress", 50);
responsePayload = downloadNotifyPayload.toByteArray();

Check warning on line 490 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L488-L490

Added lines #L488 - L490 were not covered by tests

mqttClient.publish(downloadNotifyTopic, responsePayload, 0, false);
Thread.sleep(1000);

Check warning on line 493 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L492-L493

Added lines #L492 - L493 were not covered by tests

// Download Notification 75%
downloadNotifyPayload.setTimestamp(new Date());
downloadNotifyPayload.getMetrics().put("dp.download.progress", 75);
responsePayload = downloadNotifyPayload.toByteArray();

Check warning on line 498 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L496-L498

Added lines #L496 - L498 were not covered by tests

mqttClient.publish(downloadNotifyTopic, responsePayload, 0, false);
Thread.sleep(1000);

Check warning on line 501 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L500-L501

Added lines #L500 - L501 were not covered by tests

// Download Notification 100%
downloadNotifyPayload.setTimestamp(new Date());
downloadNotifyPayload.getMetrics().put("dp.download.progress", 100);
downloadNotifyPayload.getMetrics().put("dp.download.status", COMPLETED);
responsePayload = downloadNotifyPayload.toByteArray();

Check warning on line 507 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L504-L507

Added lines #L504 - L507 were not covered by tests

mqttClient.publish(downloadNotifyTopic, responsePayload, 0, false);
Thread.sleep(1000);

Check warning on line 510 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L509-L510

Added lines #L509 - L510 were not covered by tests

// Install Notification 100%
String installNotifyTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/install";

Check warning on line 513 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L513

Added line #L513 was not covered by tests

KuraPayload installNotifyPayload = new KuraPayload();
installNotifyPayload.setTimestamp(new Date());
installNotifyPayload.getMetrics().put(CLIENT_ID, clientId);
installNotifyPayload.getMetrics().put(JOB_ID, kuraRequestPayload.getMetrics().get(JOB_ID));
installNotifyPayload.getMetrics().put("dp.name", "heater-1.0.300.dp");
installNotifyPayload.getMetrics().put("dp.install.progress", 100);
installNotifyPayload.getMetrics().put("dp.install.status", COMPLETED);
responsePayload = installNotifyPayload.toByteArray();

Check warning on line 522 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L515-L522

Added lines #L515 - L522 were not covered by tests

mqttClient.publish(installNotifyTopic, responsePayload, 0, false);

Check warning on line 524 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L524

Added line #L524 was not covered by tests

packageListChanged = true;
} else if (topic.equals(deployExecUninstall)) {
callbackParam = extractCallback(requestPayload);
KuraPayload kuraPayloadInitial = new KuraPayload();
kuraPayloadInitial.readFromByteArray(requestPayload);

KuraPayload kuraRequestPayload = new KuraPayload();
kuraRequestPayload.readFromByteArray(requestPayload);

Check warning on line 531 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L530-L531

Added lines #L530 - L531 were not covered by tests

// Reply topic
responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_REPLY + callbackParam.getRequestId();
KuraPayload customKuraPayload = new KuraPayload();

customKuraPayload.setTimestamp(new Date());
customKuraPayload.getMetrics().put("response.code", 200);
responsePayload = customKuraPayload.toByteArray();
KuraPayload replyResponsePayload = new KuraPayload();
replyResponsePayload.setTimestamp(new Date());
replyResponsePayload.getMetrics().put("response.code", 200);
responsePayload = replyResponsePayload.toByteArray();

Check warning on line 539 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L536-L539

Added lines #L536 - L539 were not covered by tests

mqttClient.publish(responseTopic, responsePayload, 0, false);
Thread.sleep(5000);
Thread.sleep(3000);

Check warning on line 542 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L542

Added line #L542 was not covered by tests

// Uninstall notification 100%
responseTopic = $EDC + CLIENT_ACCOUNT + "/" + callbackParam.getClientId() + DEPLOY_V2_NOTIFY + clientId + "/uninstall";
KuraPayload customKuraPayload2 = new KuraPayload();

customKuraPayload2.setTimestamp(new Date());
customKuraPayload2.getMetrics().put(JOB_ID, kuraPayloadInitial.getMetrics().get(JOB_ID));
customKuraPayload2.getMetrics().put("dp.name", "org.eclipse.kura.example.beacon");
customKuraPayload2.getMetrics().put("dp.uninstall.progress", 100);
customKuraPayload2.getMetrics().put("dp.uninstall.status", COMPLETED);
customKuraPayload2.getMetrics().put(CLIENT_ID, clientId);
responsePayload = customKuraPayload2.toByteArray();

KuraPayload uninstallNotifyPayload = new KuraPayload();
uninstallNotifyPayload.setTimestamp(new Date());
uninstallNotifyPayload.getMetrics().put(CLIENT_ID, clientId);
uninstallNotifyPayload.getMetrics().put(JOB_ID, kuraRequestPayload.getMetrics().get(JOB_ID));
uninstallNotifyPayload.getMetrics().put("dp.name", "org.eclipse.kura.demo.heater");
uninstallNotifyPayload.getMetrics().put("dp.uninstall.progress", 100);
uninstallNotifyPayload.getMetrics().put("dp.uninstall.status", COMPLETED);
responsePayload = uninstallNotifyPayload.toByteArray();

Check warning on line 554 in service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java

View check run for this annotation

Codecov / codecov/patch

service/device/registry/test-steps/src/main/java/org/eclipse/kapua/service/device/registry/steps/KuraDevice.java#L547-L554

Added lines #L547 - L554 were not covered by tests

mqttClient.publish(responseTopic, responsePayload, 0, false);

packageListChangedAfterUninstall = true;
Expand Down
Loading

0 comments on commit 18bcb92

Please sign in to comment.