From 5a11764cc47e65e8b115bdf390dc71f804e380b1 Mon Sep 17 00:00:00 2001 From: Sergey Matvienko <79898499+smatvienko-tb@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:47:53 +0300 Subject: [PATCH 001/527] PR template: Crosslinks between PRs added Having crosslinks between PRs is much easier to navigate between editions for reviewers and developers investigating the old PRs. --- pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pull_request_template.md b/pull_request_template.md index 6e7c31967e..9d266abf7c 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -11,7 +11,7 @@ Put your PR description here instead of this sentence. - [ ] Description contains brief notes about what needs to be added to the documentation. - [ ] No merge conflicts, commented blocks of code, code formatting issues. - [ ] Changes are backward compatible or upgrade script is provided. -- [ ] Similar PR is opened for PE version to simplify merge. Required for internal contributors only. +- [ ] Similar PR is opened for PE version to simplify merge. Crosslinks between PRs added. Required for internal contributors only. ## Front-End feature checklist From 02d9fef0f1ab0302323e6e70c1a4fe1b56eed7b2 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Thu, 10 Nov 2022 17:55:31 +0200 Subject: [PATCH 002/527] Added Mqtt v5 reason codes for ack messages and tests --- application/pom.xml | 4 + .../server/edge/BaseDeviceEdgeTest.java | 4 +- .../mqtt/{ => mqttv3}/MqttTestCallback.java | 2 +- .../mqtt/{ => mqttv3}/MqttTestClient.java | 25 ++- ...AbstractMqttAttributesIntegrationTest.java | 7 +- ...tBackwardCompatibilityIntegrationTest.java | 4 +- .../MqttAttributesRequestIntegrationTest.java | 4 +- ...tAttributesRequestJsonIntegrationTest.java | 4 +- ...AttributesRequestProtoIntegrationTest.java | 4 +- ...sBackwardCompatibilityIntegrationTest.java | 4 +- .../MqttAttributesUpdatesIntegrationTest.java | 4 +- ...tAttributesUpdatesJsonIntegrationTest.java | 4 +- ...AttributesUpdatesProtoIntegrationTest.java | 4 +- ...tClaimBackwardCompatibilityDeviceTest.java | 2 +- .../claim/MqttClaimDeviceTest.java | 4 +- .../claim/MqttClaimJsonDeviceTest.java | 2 +- .../claim/MqttClaimProtoDeviceTest.java | 4 +- .../AbstractMqttClientConnectionTest.java | 59 +++++ .../client/MqttClientConnectionTest.java | 53 +++++ .../credentials/BasicMqttCredentialsTest.java | 4 +- .../MqttProvisionJsonDeviceTest.java | 6 +- .../MqttProvisionProtoDeviceTest.java | 6 +- ...tractMqttServerSideRpcIntegrationTest.java | 6 +- ...cBackwardCompatibilityIntegrationTest.java | 2 +- ...ttServerSideRpcDefaultIntegrationTest.java | 2 +- .../MqttServerSideRpcJsonIntegrationTest.java | 4 +- ...MqttServerSideRpcProtoIntegrationTest.java | 2 +- .../MqttAttributesIntegrationTest.java | 4 +- .../MqttAttributesJsonIntegrationTest.java | 2 +- .../MqttAttributesProtoIntegrationTest.java | 2 +- ...AbstractMqttTimeseriesIntegrationTest.java | 6 +- ...ractMqttTimeseriesJsonIntegrationTest.java | 6 +- ...actMqttTimeseriesProtoIntegrationTest.java | 6 +- .../MqttTimeseriesNoSqlIntegrationTest.java | 4 +- ...qttTimeseriesNoSqlJsonIntegrationTest.java | 4 +- ...ttTimeseriesNoSqlProtoIntegrationTest.java | 4 +- .../sql/MqttTimeseriesSqlIntegrationTest.java | 4 +- .../MqttTimeseriesSqlJsonIntegrationTest.java | 4 +- ...MqttTimeseriesSqlProtoIntegrationTest.java | 4 +- .../mqtt/mqttv5/AbstractMqttV5Test.java | 21 ++ .../mqtt/mqttv5/MqttV5TestCallback.java | 110 ++++++++++ .../mqtt/mqttv5/MqttV5TestClient.java | 175 +++++++++++++++ .../AbstractAttributesMqttV5Test.java | 161 ++++++++++++++ .../updates/AttributesUpdatesTest.java | 43 ++++ .../upload/AttributesPublishTest.java | 38 ++++ .../mqttv5/claim/AbstractMqttV5ClaimTest.java | 101 +++++++++ .../mqtt/mqttv5/claim/MqttV5ClaimTest.java | 39 ++++ .../AbstractMqttV5ClientConnectionTest.java | 111 ++++++++++ .../MqttV5ClientConnectionTest.java | 60 ++++++ .../AbstractMqttV5ClientPublishTest.java | 80 +++++++ .../publish/MqttV5ClientPublishTest.java | 49 +++++ .../AbstractMqttV5ClientSubscriptionTest.java | 72 +++++++ .../MqttV5ClientSubscriptionTest.java | 45 ++++ .../AbstractMqttV5ClientUnsubscribeTest.java | 61 ++++++ .../MqttV5ClientUnsubscribeTest.java | 44 ++++ .../MqttProvisionJsonDeviceTest.java | 94 ++++++++ .../mqttv5/rpc/AbstractMqttV5RpcTest.java | 98 +++++++++ .../mqtt/mqttv5/rpc/MqttV5RpcTest.java | 43 ++++ .../AbstractMqttV5TimeseriesTest.java | 132 ++++++++++++ .../timeseries/MqttV5TimeseriesTest.java | 37 ++++ .../transport/mqtt/MqttTransportHandler.java | 201 +++++++++++------- .../mqtt/session/DeviceSessionCtx.java | 7 + .../mqtt/session/GatewaySessionHandler.java | 13 +- .../transport/mqtt/util/ReturnCode.java | 104 +++++++++ .../mqtt/util/ReturnCodeResolver.java | 61 ++++++ pom.xml | 6 + 66 files changed, 2125 insertions(+), 161 deletions(-) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/MqttTestCallback.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/MqttTestClient.java (89%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/AbstractMqttAttributesIntegrationTest.java (99%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java (97%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/request/MqttAttributesRequestIntegrationTest.java (93%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/request/MqttAttributesRequestJsonIntegrationTest.java (93%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/request/MqttAttributesRequestProtoIntegrationTest.java (96%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java (96%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/updates/MqttAttributesUpdatesIntegrationTest.java (93%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java (93%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java (94%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/claim/MqttClaimBackwardCompatibilityDeviceTest.java (97%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/claim/MqttClaimDeviceTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/claim/MqttClaimJsonDeviceTest.java (97%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/claim/MqttClaimProtoDeviceTest.java (96%) create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/credentials/BasicMqttCredentialsTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/provision/MqttProvisionJsonDeviceTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/provision/MqttProvisionProtoDeviceTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/rpc/AbstractMqttServerSideRpcIntegrationTest.java (99%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java (99%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/rpc/MqttServerSideRpcDefaultIntegrationTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/rpc/MqttServerSideRpcJsonIntegrationTest.java (96%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/rpc/MqttServerSideRpcProtoIntegrationTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/attributes/MqttAttributesIntegrationTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/attributes/MqttAttributesJsonIntegrationTest.java (96%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/attributes/MqttAttributesProtoIntegrationTest.java (99%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java (98%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java (97%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java (99%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java (80%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java (80%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java (80%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java (80%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java (80%) rename application/src/test/java/org/thingsboard/server/transport/mqtt/{ => mqttv3}/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java (80%) create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/AbstractMqttV5Test.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestCallback.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestClient.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/AbstractAttributesMqttV5Test.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/updates/AttributesUpdatesTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/upload/AttributesPublishTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/AbstractMqttV5ClaimTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/MqttV5ClaimTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/AbstractMqttV5ClientConnectionTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/MqttV5ClientConnectionTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/MqttV5ClientPublishTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/MqttV5ClientUnsubscribeTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/AbstractMqttV5RpcTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/MqttV5RpcTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/AbstractMqttV5TimeseriesTest.java create mode 100644 application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java create mode 100644 common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCode.java create mode 100644 common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCodeResolver.java diff --git a/application/pom.xml b/application/pom.xml index 598d58c447..896c1134ea 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -140,6 +140,10 @@ org.eclipse.paho org.eclipse.paho.client.mqttv3 + + org.eclipse.paho + org.eclipse.paho.mqttv5.client + org.cassandraunit cassandra-unit diff --git a/application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java b/application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java index ffe21ae961..648675251e 100644 --- a/application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java +++ b/application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java @@ -57,8 +57,8 @@ import org.thingsboard.server.gen.edge.v1.UpdateMsgType; import org.thingsboard.server.gen.edge.v1.UplinkMsg; import org.thingsboard.server.gen.edge.v1.UplinkResponseMsg; import org.thingsboard.server.gen.transport.TransportProtos; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import java.util.List; import java.util.Map; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestCallback.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestCallback.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestCallback.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestCallback.java index 18815d1c38..8c2bc5d488 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestCallback.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestCallback.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt; +package org.thingsboard.server.transport.mqtt.mqttv3; import lombok.Data; import lombok.extern.slf4j.Slf4j; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestClient.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java similarity index 89% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestClient.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java index 96846f8678..7bd36aae4d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/MqttTestClient.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt; +package org.thingsboard.server.transport.mqtt.mqttv3; import io.netty.handler.codec.mqtt.MqttQoS; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; @@ -43,6 +43,10 @@ public class MqttTestClient { this.client = createClient(); } + public MqttTestClient(boolean generateClientId) throws MqttException { + this.client = createClient(generateClientId); + } + public MqttTestClient(String clientId) throws MqttException { this.client = createClient(clientId); } @@ -104,6 +108,10 @@ public class MqttTestClient { return client.subscribe(topic, qoS.value()); } + public boolean isConnected() { + return client.isConnected(); + } + public void enableManualAcks() { client.setManualAcks(true); } @@ -112,15 +120,20 @@ public class MqttTestClient { client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos()); } - private MqttAsyncClient createClient(String clientId) throws MqttException { - if (StringUtils.isEmpty(clientId)) { + private MqttAsyncClient createClient() throws MqttException { + return createClient(true); + } + + private MqttAsyncClient createClient(boolean generateClientId) throws MqttException { + String clientId = null; + if (generateClientId) { clientId = MqttAsyncClient.generateClientId(); } - return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); + return createClient(clientId); } - private MqttAsyncClient createClient() throws MqttException { - return createClient(null); + private MqttAsyncClient createClient(String clientId) throws MqttException { + return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); } } diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/AbstractMqttAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/AbstractMqttAttributesIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java index 56d9ef5e9e..8811767326 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/AbstractMqttAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/AbstractMqttAttributesIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes; import com.github.os72.protobuf.dynamic.DynamicSchema; import com.google.protobuf.Descriptors; @@ -22,7 +22,6 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.squareup.wire.schema.internal.parser.ProtoFileElement; import io.netty.handler.codec.mqtt.MqttQoS; import lombok.extern.slf4j.Slf4j; -import org.springframework.test.context.TestPropertySource; import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.DynamicProtoUtils; @@ -41,8 +40,8 @@ import org.thingsboard.server.gen.transport.TransportApiProtos; import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import java.util.ArrayList; import java.util.List; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java similarity index 97% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java index 2231cb89eb..e9337b5446 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestBackwardCompatibilityIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.request; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.request; import lombok.extern.slf4j.Slf4j; import org.junit.Test; @@ -22,7 +22,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import java.util.ArrayList; import java.util.List; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestIntegrationTest.java similarity index 93% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestIntegrationTest.java index c4da6b3184..a9dc90f3c7 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.request; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.request; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -21,7 +21,7 @@ import org.junit.Test; import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; @Slf4j @DaoSqlTest diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestJsonIntegrationTest.java similarity index 93% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestJsonIntegrationTest.java index a27c9391fd..d8e2f4428e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestJsonIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.request; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.request; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -22,7 +22,7 @@ import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; @Slf4j @DaoSqlTest diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestProtoIntegrationTest.java similarity index 96% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestProtoIntegrationTest.java index d330cdbbaf..ef8533e582 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/request/MqttAttributesRequestProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/request/MqttAttributesRequestProtoIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.request; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.request; import lombok.extern.slf4j.Slf4j; import org.junit.Test; @@ -22,7 +22,7 @@ import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.gen.transport.TransportProtos; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import java.util.ArrayList; import java.util.List; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java similarity index 96% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java index 05253cd969..3332b962e2 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesBackwardCompatibilityIntegrationTest.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.updates; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.updates; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesIntegrationTest.java similarity index 93% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesIntegrationTest.java index 01a33c5b5c..830c40aa91 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.updates; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.updates; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -21,7 +21,7 @@ import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java similarity index 93% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java index f35ce1e084..834a01fb03 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesJsonIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.updates; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.updates; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -21,7 +21,7 @@ import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java similarity index 94% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java index dc7e92a128..91c302f322 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/attributes/updates/MqttAttributesUpdatesProtoIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.attributes.updates; +package org.thingsboard.server.transport.mqtt.mqttv3.attributes.updates; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -21,7 +21,7 @@ import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; -import org.thingsboard.server.transport.mqtt.attributes.AbstractMqttAttributesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.attributes.AbstractMqttAttributesIntegrationTest; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimBackwardCompatibilityDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimBackwardCompatibilityDeviceTest.java similarity index 97% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimBackwardCompatibilityDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimBackwardCompatibilityDeviceTest.java index e7670b5170..00a77c2e2b 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimBackwardCompatibilityDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimBackwardCompatibilityDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.claim; +package org.thingsboard.server.transport.mqtt.mqttv3.claim; import lombok.extern.slf4j.Slf4j; import org.junit.Before; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimDeviceTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimDeviceTest.java index df3ac12e45..c46b78b77d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.claim; +package org.thingsboard.server.transport.mqtt.mqttv3.claim; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -28,7 +28,7 @@ import org.thingsboard.server.dao.device.claim.ClaimResult; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.gen.transport.TransportApiProtos; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import static org.junit.Assert.assertEquals; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimJsonDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimJsonDeviceTest.java similarity index 97% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimJsonDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimJsonDeviceTest.java index 05d4974f9d..3c90eda7ed 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimJsonDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimJsonDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.claim; +package org.thingsboard.server.transport.mqtt.mqttv3.claim; import lombok.extern.slf4j.Slf4j; import org.junit.Before; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimProtoDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimProtoDeviceTest.java similarity index 96% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimProtoDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimProtoDeviceTest.java index 89c8c5f231..0bfc057806 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/claim/MqttClaimProtoDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/claim/MqttClaimProtoDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.claim; +package org.thingsboard.server.transport.mqtt.mqttv3.claim; import lombok.extern.slf4j.Slf4j; import org.junit.Before; @@ -21,7 +21,7 @@ import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.gen.transport.TransportApiProtos; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; @Slf4j diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java new file mode 100644 index 0000000000..dd1da7ef34 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java @@ -0,0 +1,59 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv3.client; + +import org.eclipse.paho.client.mqttv3.MqttException; +import org.junit.Assert; +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; + +public abstract class AbstractMqttClientConnectionTest extends AbstractMqttIntegrationTest { + + protected void processClientWithCorrectAccessTokenTest() throws Exception { + MqttTestClient client = new MqttTestClient(); + client.connectAndWait(accessToken); + Assert.assertTrue(client.isConnected()); + client.disconnect(); + } + + protected void processClientWithWrongAccessTokenTest() throws Exception { + MqttTestClient client = new MqttTestClient(); + try { + client.connectAndWait("wrongAccessToken"); + } catch (MqttException e) { + Assert.assertEquals(MqttException.REASON_CODE_FAILED_AUTHENTICATION, e.getReasonCode()); + } + } + + protected void processClientWithWrongClientIdAndEmptyUsernamePasswordTest() throws Exception { + MqttTestClient client = new MqttTestClient("unknownClientId"); + try { + client.connectAndWait(); + } catch (MqttException e) { + Assert.assertEquals(MqttException.REASON_CODE_INVALID_CLIENT_ID, e.getReasonCode()); + } + } + + protected void processClientWithNoCredentialsTest() throws Exception { + MqttTestClient client = new MqttTestClient(false); + try { + client.connectAndWait(); + } catch (MqttException e) { + Assert.assertEquals(MqttException.REASON_CODE_NOT_AUTHORIZED, e.getReasonCode()); + } + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java new file mode 100644 index 0000000000..124521eaa2 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java @@ -0,0 +1,53 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv3.client; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttClientConnectionTest extends AbstractMqttClientConnectionTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test MqttV5 client device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testClientWithCorrectAccessToken() throws Exception { + processClientWithCorrectAccessTokenTest(); + } + + @Test + public void testClientWithWrongAccessToken() throws Exception { + processClientWithWrongAccessTokenTest(); + } + + @Test + public void testClientWithWrongClientIdAndEmptyUsernamePassword() throws Exception { + processClientWithWrongClientIdAndEmptyUsernamePasswordTest(); + } + + @Test + public void testClientWithNoCredentialsTest() throws Exception { + processClientWithNoCredentialsTest(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/credentials/BasicMqttCredentialsTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/credentials/BasicMqttCredentialsTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java index 0884f1457c..288d0ca45c 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/credentials/BasicMqttCredentialsTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.credentials; +package org.thingsboard.server.transport.mqtt.mqttv3.credentials; import com.fasterxml.jackson.core.type.TypeReference; import org.eclipse.paho.client.mqttv3.MqttSecurityException; @@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import java.util.Arrays; import java.util.HashSet; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionJsonDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionJsonDeviceTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionJsonDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionJsonDeviceTest.java index 0a06f99209..deb2685bf7 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionJsonDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionJsonDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.provision; +package org.thingsboard.server.transport.mqtt.mqttv3.provision; import com.fasterxml.jackson.databind.JsonNode; import io.netty.handler.codec.mqtt.MqttQoS; @@ -33,8 +33,8 @@ import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.concurrent.TimeUnit; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionProtoDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionProtoDeviceTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionProtoDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionProtoDeviceTest.java index 9e61b69ebf..ce994a3057 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/provision/MqttProvisionProtoDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/provision/MqttProvisionProtoDeviceTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.provision; +package org.thingsboard.server.transport.mqtt.mqttv3.provision; import io.netty.handler.codec.mqtt.MqttQoS; import lombok.extern.slf4j.Slf4j; @@ -41,8 +41,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCre import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg; import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.concurrent.TimeUnit; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/AbstractMqttServerSideRpcIntegrationTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/AbstractMqttServerSideRpcIntegrationTest.java index 2cdfb76645..483c2bb350 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/AbstractMqttServerSideRpcIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/AbstractMqttServerSideRpcIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.rpc; +package org.thingsboard.server.transport.mqtt.mqttv3.rpc; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -39,8 +39,8 @@ import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadCo import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; import org.thingsboard.server.gen.transport.TransportApiProtos; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import java.util.ArrayList; import java.util.List; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java index 5fb123666f..d8a896a83e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcBackwardCompatibilityIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.rpc; +package org.thingsboard.server.transport.mqtt.mqttv3.rpc; import lombok.extern.slf4j.Slf4j; import org.junit.Test; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcDefaultIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcDefaultIntegrationTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcDefaultIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcDefaultIntegrationTest.java index 95e3b7fde3..042e2808b3 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcDefaultIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcDefaultIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.rpc; +package org.thingsboard.server.transport.mqtt.mqttv3.rpc; import com.datastax.oss.driver.api.core.uuid.Uuids; import lombok.extern.slf4j.Slf4j; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcJsonIntegrationTest.java similarity index 96% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcJsonIntegrationTest.java index b3c3a994d1..508ce02fcd 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcJsonIntegrationTest.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.rpc; +package org.thingsboard.server.transport.mqtt.mqttv3.rpc; import lombok.extern.slf4j.Slf4j; import org.junit.Before; import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_JSON_TOPIC; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcProtoIntegrationTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcProtoIntegrationTest.java index e888f49ff4..0286c20f3f 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/rpc/MqttServerSideRpcProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/rpc/MqttServerSideRpcProtoIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.rpc; +package org.thingsboard.server.transport.mqtt.mqttv3.rpc; import lombok.extern.slf4j.Slf4j; import org.junit.Before; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesIntegrationTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesIntegrationTest.java index 1d986d0453..04cbbe9a30 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.attributes; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.attributes; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -24,7 +24,7 @@ import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.Arrays; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesJsonIntegrationTest.java similarity index 96% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesJsonIntegrationTest.java index f77885c0fd..17e0edb14c 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesJsonIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.attributes; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.attributes; import lombok.extern.slf4j.Slf4j; import org.junit.Before; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesProtoIntegrationTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesProtoIntegrationTest.java index 7b2fa1143d..da25f39def 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/attributes/MqttAttributesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/attributes/MqttAttributesProtoIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.attributes; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.attributes; import com.github.os72.protobuf.dynamic.DynamicSchema; import com.google.protobuf.Descriptors; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java index 5bb0d28a21..0a58804e92 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries; import com.fasterxml.jackson.core.type.TypeReference; import io.netty.handler.codec.mqtt.MqttQoS; @@ -23,8 +23,8 @@ import org.junit.Test; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.Arrays; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java similarity index 97% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java index 4a7037f6e8..dc94f53f38 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesJsonIntegrationTest.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries; import lombok.extern.slf4j.Slf4j; import org.junit.Before; import org.junit.Test; import org.thingsboard.server.common.data.TransportPayloadType; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.Arrays; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java index 9c92e3f4f0..0b67f0e48a 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/AbstractMqttTimeseriesProtoIntegrationTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries; import com.github.os72.protobuf.dynamic.DynamicSchema; import com.google.protobuf.Descriptors; @@ -31,8 +31,8 @@ import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadCo import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; import org.thingsboard.server.gen.transport.TransportApiProtos; import org.thingsboard.server.gen.transport.TransportProtos; -import org.thingsboard.server.transport.mqtt.MqttTestCallback; -import org.thingsboard.server.transport.mqtt.MqttTestClient; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; +import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; import java.util.Arrays; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java index 7006638eb1..1d9baa5b08 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.nosql; import org.thingsboard.server.dao.service.DaoNoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; @DaoNoSqlTest public class MqttTimeseriesNoSqlIntegrationTest extends AbstractMqttTimeseriesIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java index 8e6e2cf679..999e5717b4 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlJsonIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.nosql; import org.thingsboard.server.dao.service.DaoNoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; @DaoNoSqlTest public class MqttTimeseriesNoSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java index e91d5982d7..06f2bff3b5 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/nosql/MqttTimeseriesNoSqlProtoIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.nosql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.nosql; import org.thingsboard.server.dao.service.DaoNoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; @DaoNoSqlTest public class MqttTimeseriesNoSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java index de9a596d43..e317debabc 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.sql; import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesIntegrationTest; @DaoSqlTest public class MqttTimeseriesSqlIntegrationTest extends AbstractMqttTimeseriesIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java index 323dd751f1..bf991c0c06 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlJsonIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.sql; import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesJsonIntegrationTest; @DaoSqlTest public class MqttTimeseriesSqlJsonIntegrationTest extends AbstractMqttTimeseriesJsonIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java similarity index 80% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java index ebfc1d49cf..7e17d30844 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/telemetry/timeseries/sql/MqttTimeseriesSqlProtoIntegrationTest.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.transport.mqtt.telemetry.timeseries.sql; +package org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.sql; import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.transport.mqtt.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv3.telemetry.timeseries.AbstractMqttTimeseriesProtoIntegrationTest; @DaoSqlTest public class MqttTimeseriesSqlProtoIntegrationTest extends AbstractMqttTimeseriesProtoIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/AbstractMqttV5Test.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/AbstractMqttV5Test.java new file mode 100644 index 0000000000..4714184f0e --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/AbstractMqttV5Test.java @@ -0,0 +1,21 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5; + +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; + +public abstract class AbstractMqttV5Test extends AbstractMqttIntegrationTest { +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestCallback.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestCallback.java new file mode 100644 index 0000000000..7979936659 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestCallback.java @@ -0,0 +1,110 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.client.MqttCallback; +import org.eclipse.paho.mqttv5.client.MqttDisconnectResponse; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.MqttMessage; +import org.eclipse.paho.mqttv5.common.packet.MqttProperties; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; + +import java.util.concurrent.CountDownLatch; + +@Slf4j +@Data +public class MqttV5TestCallback implements MqttCallback { + + protected CountDownLatch subscribeLatch; + protected final CountDownLatch deliveryLatch; + protected int qoS; + protected byte[] payloadBytes; + protected String awaitSubTopic; + protected boolean pubAckReceived; + protected MqttMessage lastReceivedMessage; + + public MqttV5TestCallback() { + this.subscribeLatch = new CountDownLatch(1); + this.deliveryLatch = new CountDownLatch(1); + } + + public MqttV5TestCallback(int subscribeCount) { + this.subscribeLatch = new CountDownLatch(subscribeCount); + this.deliveryLatch = new CountDownLatch(1); + } + + public MqttV5TestCallback(String awaitSubTopic) { + this.subscribeLatch = new CountDownLatch(1); + this.deliveryLatch = new CountDownLatch(1); + this.awaitSubTopic = awaitSubTopic; + } + + @Override + public void disconnected(MqttDisconnectResponse mqttDisconnectResponse) { + if (mqttDisconnectResponse.getException() != null) { + log.warn("connectionLost: ", mqttDisconnectResponse.getException()); + deliveryLatch.countDown(); + } + log.warn("Disconnected with reason: {}", mqttDisconnectResponse.getReasonString()); + } + + @Override + public void mqttErrorOccurred(MqttException e) { + log.warn("Error occurred:", e); + } + + @Override + public void messageArrived(String requestTopic, MqttMessage mqttMessage) { + lastReceivedMessage = mqttMessage; + if (awaitSubTopic == null) { + log.warn("messageArrived on topic: {}", requestTopic); + qoS = mqttMessage.getQos(); + payloadBytes = mqttMessage.getPayload(); + subscribeLatch.countDown(); + } else { + messageArrivedOnAwaitSubTopic(requestTopic, mqttMessage); + } + } + + protected void messageArrivedOnAwaitSubTopic(String requestTopic, MqttMessage mqttMessage) { + log.warn("messageArrived on topic: {}, awaitSubTopic: {}", requestTopic, awaitSubTopic); + if (awaitSubTopic.equals(requestTopic)) { + qoS = mqttMessage.getQos(); + payloadBytes = mqttMessage.getPayload(); + subscribeLatch.countDown(); + } + } + + @Override + public void deliveryComplete(IMqttToken iMqttToken) { + log.warn("delivery complete: {}", iMqttToken.getResponse()); + pubAckReceived = iMqttToken.getResponse().getType() == MqttWireMessage.MESSAGE_TYPE_PUBACK; + deliveryLatch.countDown(); + } + + @Override + public void connectComplete(boolean reconnect, String serverURI) { + log.warn("Connect completed: reconnect - {}, serverURI - {}", reconnect, serverURI); + } + + @Override + public void authPacketArrived(int reasonCode, MqttProperties mqttProperties) { + log.warn("Auth package received: reasonCode - {}, mqtt properties - {}", reasonCode, mqttProperties); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestClient.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestClient.java new file mode 100644 index 0000000000..d7d75229f4 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/MqttV5TestClient.java @@ -0,0 +1,175 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5; + +import io.netty.handler.codec.mqtt.MqttQoS; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.client.MqttAsyncClient; +import org.eclipse.paho.mqttv5.client.MqttCallback; +import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; +import org.eclipse.paho.mqttv5.client.persist.MemoryPersistence; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.MqttMessage; +import org.thingsboard.server.common.data.StringUtils; + +import java.util.concurrent.TimeUnit; + +public class MqttV5TestClient { + + private static final String MQTT_URL = "tcp://localhost:1883"; + private static final int TIMEOUT = 30; // seconds + private static final long TIMEOUT_MS = TimeUnit.SECONDS.toMillis(TIMEOUT); + + private final MqttAsyncClient client; + + public void setCallback(MqttCallback callback) { + client.setCallback(callback); + } + + public MqttV5TestClient() throws MqttException { + this.client = createClient(); + } + + public MqttV5TestClient(String clientId) throws MqttException { + this.client = createClient(clientId); + } + + public MqttV5TestClient(boolean generateClientId) throws MqttException { + this.client = createClient(generateClientId); + } + + public IMqttToken connectAndWait(String userName, String password) throws MqttException { + IMqttToken connect = connect(userName, password); + connect.waitForCompletion(TIMEOUT_MS); + return connect; + } + + public IMqttToken connectAndWait(String userName) throws MqttException { + return connectAndWait(userName, null); + } + + public IMqttToken connectAndWait() throws MqttException { + return connectAndWait(null, null); + } + + public IMqttToken connectAndWait(MqttConnectionOptions options) throws MqttException { + IMqttToken iMqttToken = connect(options); + iMqttToken.waitForCompletion(TIMEOUT_MS); + return iMqttToken; + } + + private IMqttToken connect(String userName, String password) throws MqttException { + if (client == null) { + throw new RuntimeException("Failed to connect! MqttAsyncClient is not initialized!"); + } + MqttConnectionOptions options = new MqttConnectionOptions(); + if (StringUtils.isNotEmpty(userName)) { + options.setUserName(userName); + } + if (StringUtils.isNotEmpty(password)) { + options.setPassword(password.getBytes()); + } + return client.connect(options); + } + + public IMqttToken connect(MqttConnectionOptions options) throws MqttException { + if (client == null) { + throw new RuntimeException("Failed to connect! MqttAsyncClient is not initialized!"); + } + return client.connect(options); + } + + public void disconnectAndWait() throws MqttException { + disconnect().waitForCompletion(TIMEOUT_MS); + } + + public IMqttToken disconnect() throws MqttException { + return client.disconnect(); + } + + public void disconnectForcibly() throws MqttException { + client.disconnectForcibly(TIMEOUT_MS); + } + + public IMqttToken publishAndWait(String topic, byte[] payload) throws MqttException { + IMqttToken iMqttToken = publish(topic, payload); + iMqttToken.waitForCompletion(TIMEOUT_MS); + return iMqttToken; + } + + public IMqttToken publish(String topic, byte[] payload) throws MqttException { + MqttMessage message = new MqttMessage(); + message.setPayload(payload); + return publish(topic, message); + } + + public IMqttToken publish(String topic, MqttMessage message) throws MqttException { + return publish(topic, message.getPayload(), message.getQos(), message.isRetained()); + } + + public IMqttToken publish(String topic, byte[] payload, int qos, boolean retain) throws MqttException { + return client.publish(topic, payload, qos, retain); + } + + public IMqttToken subscribeAndWait(String topic, MqttQoS qoS) throws MqttException { + IMqttToken iMqttToken = subscribe(topic, qoS); + iMqttToken.waitForCompletion(TIMEOUT_MS); + return iMqttToken; + } + + public IMqttToken subscribe(String topic, MqttQoS qoS) throws MqttException { + return client.subscribe(topic, qoS.value()); + } + + public IMqttToken unsubscribeAndWait(String topic) throws MqttException { + IMqttToken iMqttToken = unsubscribe(topic); + iMqttToken.waitForCompletion(TIMEOUT_MS); + return iMqttToken; + } + + public IMqttToken unsubscribe(String topic) throws MqttException { + return client.unsubscribe(topic); + } + + public boolean isConnected() { + return client.isConnected(); + } + + public void enableManualAcks() { + client.setManualAcks(true); + } + + public void messageArrivedComplete(MqttMessage mqttMessage) throws MqttException { + client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos()); + } + + private MqttAsyncClient createClient() throws MqttException { + return createClient(true); + } + + private MqttAsyncClient createClient(boolean generateClientId) throws MqttException { + String clientId = null; + if (generateClientId) { + clientId = "test" + System.nanoTime(); + } + return createClient(clientId); + } + + private MqttAsyncClient createClient(String clientId) throws MqttException { + return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/AbstractAttributesMqttV5Test.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/AbstractAttributesMqttV5Test.java new file mode 100644 index 0000000000..204c66e597 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/AbstractAttributesMqttV5Test.java @@ -0,0 +1,161 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.attributes; + +import com.fasterxml.jackson.core.type.TypeReference; +import io.netty.handler.codec.mqtt.MqttQoS; +import org.junit.Before; +import org.thingsboard.common.util.JacksonUtil; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; +import org.thingsboard.server.transport.mqtt.mqttv5.AbstractMqttV5Test; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public abstract class AbstractAttributesMqttV5Test extends AbstractMqttV5Test { + + private static final String SHARED_ATTRIBUTES_PAYLOAD = "{\"sharedStr\":\"value1\",\"sharedBool\":true,\"sharedDbl\":42.0,\"sharedLong\":73," + + "\"sharedJson\":{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}}"; + + private static final String SHARED_ATTRIBUTES_DELETED_RESPONSE = "{\"deleted\":[\"sharedJson\"]}"; + + protected static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Post Attributes device") + .build(); + processBeforeTest(configProperties); + } + + protected void processAttributesPublishTest() throws Exception { + List expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5"); + + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + client.publishAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, PAYLOAD_VALUES_STR.getBytes()); + client.disconnectAndWait(); + + DeviceId deviceId = savedDevice.getId(); + + long start = System.currentTimeMillis(); + long end = System.currentTimeMillis() + 5000; + + List actualKeys = null; + while (start <= end) { + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/attributes/CLIENT_SCOPE", new TypeReference<>() { + }); + if (actualKeys.size() == expectedKeys.size()) { + break; + } + Thread.sleep(100); + start += 100; + } + assertNotNull(actualKeys); + + Set actualKeySet = new HashSet<>(actualKeys); + + Set expectedKeySet = new HashSet<>(expectedKeys); + + assertEquals(expectedKeySet, actualKeySet); + + String getAttributesValuesUrl = getAttributesValuesUrl(deviceId, actualKeySet); + List> values = doGetAsyncTyped(getAttributesValuesUrl, new TypeReference<>() { + }); + assertAttributesValues(values, actualKeySet); + String deleteAttributesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); + doDelete(deleteAttributesUrl); + } + + protected void processAttributesUpdatesTest() throws Exception { + + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + MqttV5TestCallback onUpdateCallback = new MqttV5TestCallback(); + client.setCallback(onUpdateCallback); + client.subscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttQoS.AT_MOST_ONCE); + + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", SHARED_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); + onUpdateCallback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + + validateUpdateAttributesResponse(onUpdateCallback, SHARED_ATTRIBUTES_PAYLOAD); + + MqttV5TestCallback onDeleteCallback = new MqttV5TestCallback(); + client.setCallback(onDeleteCallback); + doDelete("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/SHARED_SCOPE?keys=sharedJson", String.class); + onDeleteCallback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + + validateUpdateAttributesResponse(onDeleteCallback, SHARED_ATTRIBUTES_DELETED_RESPONSE); + + client.disconnect(); + } + + private String getAttributesValuesUrl(DeviceId deviceId, Set actualKeySet) { + return "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/attributes/CLIENT_SCOPE?keys=" + String.join(",", actualKeySet); + } + + protected void assertAttributesValues(List> deviceValues, Set keySet) { + for (Map map : deviceValues) { + String key = (String) map.get("key"); + Object value = map.get("value"); + assertTrue(keySet.contains(key)); + switch (key) { + case "key1": + assertEquals("value1", value); + break; + case "key2": + assertEquals(true, value); + break; + case "key3": + assertEquals(3.0, value); + break; + case "key4": + assertEquals(4, value); + break; + case "key5": + assertNotNull(value); + assertEquals(3, ((LinkedHashMap) value).size()); + assertEquals(42, ((LinkedHashMap) value).get("someNumber")); + assertEquals(Arrays.asList(1, 2, 3), ((LinkedHashMap) value).get("someArray")); + LinkedHashMap someNestedObject = (LinkedHashMap) ((LinkedHashMap) value).get("someNestedObject"); + assertEquals("value", someNestedObject.get("key")); + break; + } + } + } + + protected void validateUpdateAttributesResponse(MqttV5TestCallback callback, String expectedResponse) { + assertNotNull(callback.getPayloadBytes()); + assertEquals(JacksonUtil.toJsonNode(expectedResponse), JacksonUtil.fromBytes(callback.getPayloadBytes())); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/updates/AttributesUpdatesTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/updates/AttributesUpdatesTest.java new file mode 100644 index 0000000000..cd37ae4b9c --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/updates/AttributesUpdatesTest.java @@ -0,0 +1,43 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.attributes.updates; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.common.data.TransportPayloadType; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; +import org.thingsboard.server.transport.mqtt.mqttv5.attributes.AbstractAttributesMqttV5Test; + +@Slf4j +@DaoSqlTest +public class AttributesUpdatesTest extends AbstractAttributesMqttV5Test { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Subscribe to attribute updates") + .transportPayloadType(TransportPayloadType.JSON) + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testAttributeMqttV5SimpleClientUpdates() throws Exception { + processAttributesUpdatesTest(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/upload/AttributesPublishTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/upload/AttributesPublishTest.java new file mode 100644 index 0000000000..03b74a0819 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/attributes/upload/AttributesPublishTest.java @@ -0,0 +1,38 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.attributes.upload; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; +import org.thingsboard.server.transport.mqtt.mqttv5.attributes.AbstractAttributesMqttV5Test; + +@DaoSqlTest +public class AttributesPublishTest extends AbstractAttributesMqttV5Test { + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Post Attributes device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testMqttV5AttributePublishTest() throws Exception { + processAttributesPublishTest(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/AbstractMqttV5ClaimTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/AbstractMqttV5ClaimTest.java new file mode 100644 index 0000000000..4edfce992e --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/AbstractMqttV5ClaimTest.java @@ -0,0 +1,101 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.claim; + +import lombok.extern.slf4j.Slf4j; +import org.thingsboard.server.common.data.ClaimRequest; +import org.thingsboard.server.common.data.Customer; +import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.User; +import org.thingsboard.server.common.data.security.Authority; +import org.thingsboard.server.dao.device.claim.ClaimResponse; +import org.thingsboard.server.dao.device.claim.ClaimResult; +import org.thingsboard.server.transport.mqtt.mqttv5.AbstractMqttV5Test; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_CLAIM_TOPIC; + +@Slf4j +public abstract class AbstractMqttV5ClaimTest extends AbstractMqttV5Test { + protected static final String CUSTOMER_USER_PASSWORD = "customerUser123!"; + + protected User customerAdmin; + protected Customer savedCustomer; + + protected void processTestClaimingDevice() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + byte[] payloadBytes; + byte[] failurePayloadBytes; + payloadBytes = "{\"secretKey\":\"value\", \"durationMs\":60000}".getBytes(); + failurePayloadBytes = "{\"secretKey\":\"value\", \"durationMs\":1}".getBytes(); + validateClaimResponse(client, payloadBytes, failurePayloadBytes); + } + + protected void validateClaimResponse(MqttV5TestClient client, byte[] payloadBytes, byte[] failurePayloadBytes) throws Exception { + client.publishAndWait(DEVICE_CLAIM_TOPIC, failurePayloadBytes); + + loginUser(customerAdmin.getName(), CUSTOMER_USER_PASSWORD); + ClaimRequest claimRequest = new ClaimRequest("value"); + + ClaimResponse claimResponse = doExecuteWithRetriesAndInterval( + () -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()), + 20, + 100 + ); + + assertEquals(claimResponse, ClaimResponse.FAILURE); + + client.publishAndWait(DEVICE_CLAIM_TOPIC, payloadBytes); + client.disconnect(); + + ClaimResult claimResult = doExecuteWithRetriesAndInterval( + () -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResult.class, status().isOk()), + 20, + 100 + ); + assertEquals(claimResult.getResponse(), ClaimResponse.SUCCESS); + Device claimedDevice = claimResult.getDevice(); + assertNotNull(claimedDevice); + assertNotNull(claimedDevice.getCustomerId()); + assertEquals(customerAdmin.getCustomerId(), claimedDevice.getCustomerId()); + + claimResponse = doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()); + assertEquals(claimResponse, ClaimResponse.CLAIMED); + } + + protected void createCustomerAndUser() throws Exception { + Customer customer = new Customer(); + customer.setTenantId(tenantId); + customer.setTitle("Test Claiming Customer"); + savedCustomer = doPost("/api/customer", customer, Customer.class); + assertNotNull(savedCustomer); + assertEquals(tenantId, savedCustomer.getTenantId()); + + User user = new User(); + user.setAuthority(Authority.CUSTOMER_USER); + user.setTenantId(tenantId); + user.setCustomerId(savedCustomer.getId()); + user.setEmail("customer@thingsboard.org"); + + customerAdmin = createUser(user, CUSTOMER_USER_PASSWORD); + assertNotNull(customerAdmin); + assertEquals(customerAdmin.getCustomerId(), savedCustomer.getId()); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/MqttV5ClaimTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/MqttV5ClaimTest.java new file mode 100644 index 0000000000..5111cbec56 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/claim/MqttV5ClaimTest.java @@ -0,0 +1,39 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.claim; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5ClaimTest extends AbstractMqttV5ClaimTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Claim device") + .build(); + processBeforeTest(configProperties); + createCustomerAndUser(); + } + + @Test + public void testClaimingDevice() throws Exception { + processTestClaimingDevice(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/AbstractMqttV5ClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/AbstractMqttV5ClientConnectionTest.java new file mode 100644 index 0000000000..875cf7a020 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/AbstractMqttV5ClientConnectionTest.java @@ -0,0 +1,111 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.connection; + +import io.netty.handler.codec.mqtt.MqttQoS; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.packet.MqttConnAck; +import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; +import org.junit.Assert; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.concurrent.TimeUnit; + +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_CONNACK; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public abstract class AbstractMqttV5ClientConnectionTest extends AbstractMqttIntegrationTest { + + protected void processClientWithCorrectAccessTokenTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + IMqttToken connectionResult = client.connectAndWait(accessToken); + MqttWireMessage response = connectionResult.getResponse(); + + Assert.assertEquals(MESSAGE_TYPE_CONNACK, response.getType()); + + MqttConnAck connAckMsg = (MqttConnAck) response; + + Assert.assertEquals(MqttReturnCode.RETURN_CODE_SUCCESS, connAckMsg.getReturnCode()); + client.disconnect(); + } + + protected void processClientWithWrongAccessTokenTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + try { + client.connectAndWait("wrongAccessToken"); + } catch (MqttException e) { + Assert.assertEquals(MqttReturnCode.RETURN_CODE_BAD_USERNAME_OR_PASSWORD, e.getReasonCode()); + } + } + + protected void processClientWithWrongClientIdAndEmptyUsernamePasswordTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient("unknownClientId"); + try { + client.connectAndWait(); + } catch (MqttException e) { + Assert.assertEquals(MqttReturnCode.RETURN_CODE_IDENTIFIER_NOT_VALID, e.getReasonCode()); + } + } + + protected void processClientWithNoCredentialsTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(false); + try { + client.connectAndWait(); + } catch (MqttException e) { + Assert.assertEquals(MqttReturnCode.RETURN_CODE_NOT_AUTHORIZED, e.getReasonCode()); + } + } + + protected void processClientWithPacketSizeLimitationTest() throws Exception { + int packetSizeLimit = 99; + MqttConnectionOptions options = new MqttConnectionOptions(); + options.setMaximumPacketSize((long) packetSizeLimit); + options.setUserName(accessToken); + + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(options); + + MqttV5TestCallback possibleSizeCallback = updateAttributeWithStringValue(client, packetSizeLimit / 2); + + Assert.assertTrue("Server should send messages if size less then limitation.", possibleSizeCallback.getPayloadBytes().length < packetSizeLimit); + + MqttV5TestCallback bigMessageCallback = updateAttributeWithStringValue(client, packetSizeLimit * 2); + + Assert.assertNull("Server should not send a message if the message size bigger then set limit.", bigMessageCallback.getLastReceivedMessage()); + + client.disconnect(); + + } + + private MqttV5TestCallback updateAttributeWithStringValue(MqttV5TestClient client, int valueLen) throws Exception { + MqttV5TestCallback onUpdateCallback = new MqttV5TestCallback(); + client.setCallback(onUpdateCallback); + client.subscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttQoS.AT_MOST_ONCE); + + String payload = "{\"sharedStr\":\"" + StringUtils.repeat("*", valueLen) + "\"}"; + + doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", payload, String.class, status().isOk()); + onUpdateCallback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + return onUpdateCallback; + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/MqttV5ClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/MqttV5ClientConnectionTest.java new file mode 100644 index 0000000000..87f9968b8b --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/connection/MqttV5ClientConnectionTest.java @@ -0,0 +1,60 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.connection; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5ClientConnectionTest extends AbstractMqttV5ClientConnectionTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test MqttV5 client device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testClientWithCorrectAccessToken() throws Exception { + processClientWithCorrectAccessTokenTest(); + } + + @Test + public void testClientWithWrongAccessToken() throws Exception { + processClientWithWrongAccessTokenTest(); + } + + @Test + public void testClientWithWrongClientIdAndEmptyUsernamePassword() throws Exception { + processClientWithWrongClientIdAndEmptyUsernamePasswordTest(); + } + + @Test + public void testClientWithNoCredentialsTest() throws Exception { + processClientWithNoCredentialsTest(); + } + + @Test + @Ignore("Not implemented on the server.") + public void testClientWithPacketSizeLimitation() throws Exception { + processClientWithPacketSizeLimitationTest(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java new file mode 100644 index 0000000000..4520cdcb26 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java @@ -0,0 +1,80 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.publish; + +import io.netty.handler.codec.mqtt.MqttQoS; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.common.packet.MqttPubAck; +import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; +import org.eclipse.paho.mqttv5.common.packet.MqttSubAck; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; +import org.junit.Assert; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_PUBACK; +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK; + +public abstract class AbstractMqttV5ClientPublishTest extends AbstractMqttIntegrationTest { + + protected static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; + + protected static final String INVALID_PAYLOAD_VALUES_STR = "\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; + + protected void processClientPublishToCorrectTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken publishResult = client.publishAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, PAYLOAD_VALUES_STR.getBytes()); + MqttWireMessage response = publishResult.getResponse(); + + Assert.assertEquals(MESSAGE_TYPE_PUBACK, response.getType()); + + MqttPubAck pubAckMsg = (MqttPubAck) response; + + Assert.assertEquals(MqttReturnCode.RETURN_CODE_SUCCESS, pubAckMsg.getReturnCode()); + + client.disconnect(); + } + + protected void processClientPublishToWrongTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken iMqttToken = client.publishAndWait("wrong/topic/", PAYLOAD_VALUES_STR.getBytes()); + Assert.assertEquals(MESSAGE_TYPE_PUBACK,iMqttToken.getResponse().getType()); + MqttPubAck pubAck = (MqttPubAck) iMqttToken.getResponse(); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_TOPIC_NAME_INVALID, pubAck.getReturnCode()); + + client.disconnect(); + } + + protected void processClientPublishWithInvalidPayloadTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken iMqttToken = client.publishAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, INVALID_PAYLOAD_VALUES_STR.getBytes()); + Assert.assertEquals(MESSAGE_TYPE_PUBACK,iMqttToken.getResponse().getType()); + MqttPubAck pubAck = (MqttPubAck) iMqttToken.getResponse(); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_PAYLOAD_FORMAT_INVALID, pubAck.getReturnCode()); + + client.disconnect(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/MqttV5ClientPublishTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/MqttV5ClientPublishTest.java new file mode 100644 index 0000000000..0fad9d8a13 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/MqttV5ClientPublishTest.java @@ -0,0 +1,49 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.publish; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5ClientPublishTest extends AbstractMqttV5ClientPublishTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test MqttV5 client device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testClientPublishToCorrectTopic() throws Exception { + processClientPublishToCorrectTopicTest(); + } + + @Test + public void testClientPublishToWrongTopic() throws Exception { + processClientPublishToWrongTopicTest(); + } + + @Test + public void testClientPublishWithInvalidPayload() throws Exception { + processClientPublishWithInvalidPayloadTest(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java new file mode 100644 index 0000000000..d2a11072a2 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java @@ -0,0 +1,72 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe; + +import io.netty.handler.codec.mqtt.MqttQoS; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.packet.MqttConnAck; +import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; +import org.eclipse.paho.mqttv5.common.packet.MqttSubAck; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; +import org.junit.Assert; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.concurrent.TimeUnit; + +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_CONNACK; +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public abstract class AbstractMqttV5ClientSubscriptionTest extends AbstractMqttIntegrationTest { + + protected void processClientSubscriptionToCorrectTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken subscriptionResult = client.subscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttQoS.AT_MOST_ONCE); + + MqttWireMessage response = subscriptionResult.getResponse(); + + Assert.assertEquals(MESSAGE_TYPE_SUBACK, response.getType()); + + MqttSubAck subAckMsg = (MqttSubAck) response; + + Assert.assertEquals(1, subAckMsg.getReturnCodes().length); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_SUCCESS, subAckMsg.getReturnCodes()[0]); + + client.disconnect(); + } + + protected void processClientSubscriptionToWrongTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken iMqttToken = client.subscribeAndWait("wrong/topic/+", MqttQoS.AT_MOST_ONCE); + Assert.assertEquals(MESSAGE_TYPE_SUBACK,iMqttToken.getResponse().getType()); + MqttSubAck subAck = (MqttSubAck) iMqttToken.getResponse(); + Assert.assertEquals(1, subAck.getReturnCodes().length); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_TOPIC_FILTER_NOT_VALID, subAck.getReturnCodes()[0]); + + client.disconnect(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java new file mode 100644 index 0000000000..37404a8911 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java @@ -0,0 +1,45 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5ClientSubscriptionTest extends AbstractMqttV5ClientSubscriptionTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test MqttV5 client device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testClientSubscriptionToCorrectTopic() throws Exception { + processClientSubscriptionToCorrectTopicTest(); + } + + @Test + public void testClientSubscriptionToWrongTopic() throws Exception { + processClientSubscriptionToWrongTopicTest(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java new file mode 100644 index 0000000000..f2088e704d --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java @@ -0,0 +1,61 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.unsubscribe; + +import io.netty.handler.codec.mqtt.MqttQoS; +import org.eclipse.paho.mqttv5.client.IMqttToken; +import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; +import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; +import org.eclipse.paho.mqttv5.common.packet.MqttUnsubAck; +import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; +import org.junit.Assert; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_UNSUBACK; + +public abstract class AbstractMqttV5ClientUnsubscribeTest extends AbstractMqttIntegrationTest { + + protected void processClientUnsubscribeFromCorrectTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + client.subscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC, MqttQoS.AT_MOST_ONCE); + IMqttToken unsubscribeResult = client.unsubscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC); + MqttWireMessage response = unsubscribeResult.getResponse(); + Assert.assertEquals(MESSAGE_TYPE_UNSUBACK, response.getType()); + MqttUnsubAck unsubAckMsg = (MqttUnsubAck) response; + Assert.assertEquals(1, unsubAckMsg.getReturnCodes().length); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_SUCCESS, unsubAckMsg.getReturnCodes()[0]); + + client.disconnect(); + } + + protected void processClientUnsubscribeWithoutSubscribeTopicTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + + IMqttToken iMqttToken = client.unsubscribeAndWait(MqttTopics.DEVICE_ATTRIBUTES_TOPIC); + Assert.assertEquals(MESSAGE_TYPE_UNSUBACK, iMqttToken.getResponse().getType()); + MqttUnsubAck unsubAck = (MqttUnsubAck) iMqttToken.getResponse(); + Assert.assertEquals(1, unsubAck.getReturnCodes().length); + Assert.assertEquals(MqttReturnCode.RETURN_CODE_NO_SUBSCRIPTION_EXISTED, unsubAck.getReturnCodes()[0]); + + client.disconnect(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/MqttV5ClientUnsubscribeTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/MqttV5ClientUnsubscribeTest.java new file mode 100644 index 0000000000..83c9843923 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/MqttV5ClientUnsubscribeTest.java @@ -0,0 +1,44 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.client.unsubscribe; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5ClientUnsubscribeTest extends AbstractMqttV5ClientUnsubscribeTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test MqttV5 client device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testClientUnsubscribeFromCorrectTopic() throws Exception { + processClientUnsubscribeFromCorrectTopicTest(); + } + + @Test + public void testClientUnsubscribeWithoutSubscribeTopic() throws Exception { + processClientUnsubscribeWithoutSubscribeTopicTest(); + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java new file mode 100644 index 0000000000..942befc2f1 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java @@ -0,0 +1,94 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.provision; + +import com.fasterxml.jackson.databind.JsonNode; +import io.netty.handler.codec.mqtt.MqttQoS; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.thingsboard.common.util.JacksonUtil; +import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.DeviceProfileProvisionType; +import org.thingsboard.server.common.data.TransportPayloadType; +import org.thingsboard.server.common.data.security.DeviceCredentials; +import org.thingsboard.server.dao.device.DeviceCredentialsService; +import org.thingsboard.server.dao.device.DeviceService; +import org.thingsboard.server.dao.device.provision.ProvisionResponseStatus; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; +import org.thingsboard.server.transport.mqtt.mqttv5.AbstractMqttV5Test; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.concurrent.TimeUnit; + +import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_PROVISION_REQUEST_TOPIC; +import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_PROVISION_RESPONSE_TOPIC; + +@Slf4j +@DaoSqlTest +public class MqttProvisionJsonDeviceTest extends AbstractMqttV5Test { + + @Autowired + DeviceCredentialsService deviceCredentialsService; + + @Autowired + DeviceService deviceService; + + @Test + public void testProvisioningCreateNewDeviceWithoutCredentials() throws Exception { + processTestProvisioningCreateNewDeviceWithoutCredentials(); + } + + protected void processTestProvisioningCreateNewDeviceWithoutCredentials() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Provision device3") + .transportPayloadType(TransportPayloadType.JSON) + .provisionType(DeviceProfileProvisionType.ALLOW_CREATE_NEW_DEVICES) + .provisionKey("testProvisionKey") + .provisionSecret("testProvisionSecret") + .build(); + super.processBeforeTest(configProperties); + byte[] result = createMqttClientAndPublish(); + JsonNode response = JacksonUtil.fromBytes(result); + Assert.assertTrue(response.hasNonNull("credentialsType")); + Assert.assertTrue(response.hasNonNull("status")); + + Device createdDevice = deviceService.findDeviceByTenantIdAndName(tenantId, "Test Provision device"); + + Assert.assertNotNull(createdDevice); + + DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, createdDevice.getId()); + + Assert.assertEquals(deviceCredentials.getCredentialsType().name(), response.get("credentialsType").asText()); + Assert.assertEquals(ProvisionResponseStatus.SUCCESS.name(), response.get("status").asText()); + } + + protected byte[] createMqttClientAndPublish() throws Exception { + String provisionRequestMsg = "{\"deviceName\":\"Test Provision device\",\"provisionDeviceKey\":\"testProvisionKey\", \"provisionDeviceSecret\":\"testProvisionSecret\"}"; + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait("provision"); + MqttV5TestCallback onProvisionCallback = new MqttV5TestCallback(DEVICE_PROVISION_RESPONSE_TOPIC); + client.setCallback(onProvisionCallback); + client.subscribe(DEVICE_PROVISION_RESPONSE_TOPIC, MqttQoS.AT_MOST_ONCE); + client.publishAndWait(DEVICE_PROVISION_REQUEST_TOPIC, provisionRequestMsg.getBytes()); + onProvisionCallback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + client.disconnect(); + return onProvisionCallback.getPayloadBytes(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/AbstractMqttV5RpcTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/AbstractMqttV5RpcTest.java new file mode 100644 index 0000000000..98c42c39fe --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/AbstractMqttV5RpcTest.java @@ -0,0 +1,98 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.rpc; + +import com.nimbusds.jose.util.StandardCharset; +import io.netty.handler.codec.mqtt.MqttQoS; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.MqttMessage; +import org.thingsboard.common.util.JacksonUtil; +import org.thingsboard.server.common.data.StringUtils; +import org.thingsboard.server.transport.mqtt.mqttv5.AbstractMqttV5Test; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC; + +@Slf4j +public abstract class AbstractMqttV5RpcTest extends AbstractMqttV5Test { + + private static final String DEVICE_RESPONSE = "{\"value1\":\"A\",\"value2\":\"B\"}"; + + + protected void processOneWayRpcTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + MqttV5TestCallback callback = new MqttV5TestCallback(DEVICE_RPC_REQUESTS_SUB_TOPIC.replace("+", "0")); + client.setCallback(callback); + client.subscribeAndWait(DEVICE_RPC_REQUESTS_SUB_TOPIC, MqttQoS.AT_MOST_ONCE); + + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"23\",\"value\": 1}}"; + String result = doPostAsync("/api/rpc/oneway/" + savedDevice.getId(), setGpioRequest, String.class, status().isOk()); + assertTrue(StringUtils.isEmpty(result)); + callback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + assertEquals(JacksonUtil.toJsonNode(setGpioRequest), JacksonUtil.fromBytes(callback.getPayloadBytes())); + assertEquals(MqttQoS.AT_MOST_ONCE.value(), callback.getQoS()); + client.disconnect(); + } + + protected void processJsonTwoWayRpcTest() throws Exception { + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + client.subscribeAndWait(DEVICE_RPC_REQUESTS_SUB_TOPIC, MqttQoS.AT_LEAST_ONCE); + MqttV5TestRpcCallback callback = new MqttV5TestRpcCallback(client, DEVICE_RPC_REQUESTS_SUB_TOPIC.replace("+", "0")); + client.setCallback(callback); + String setGpioRequest = "{\"method\":\"setGpio\",\"params\":{\"pin\": \"26\",\"value\": 1}}"; + String actualRpcResponse = doPostAsync("/api/rpc/twoway/" + savedDevice.getId(), setGpioRequest, String.class, status().isOk()); + callback.getSubscribeLatch().await(3, TimeUnit.SECONDS); + assertEquals(JacksonUtil.toJsonNode(setGpioRequest), JacksonUtil.fromBytes(callback.getPayloadBytes())); + assertEquals("{\"value1\":\"A\",\"value2\":\"B\"}", actualRpcResponse); + client.disconnect(); + } + + protected class MqttV5TestRpcCallback extends MqttV5TestCallback { + + private final MqttV5TestClient client; + + public MqttV5TestRpcCallback(MqttV5TestClient client, String awaitSubTopic) { + super(awaitSubTopic); + this.client = client; + } + + @Override + protected void messageArrivedOnAwaitSubTopic(String requestTopic, MqttMessage mqttMessage) { + log.warn("messageArrived on topic: {}, awaitSubTopic: {}", requestTopic, awaitSubTopic); + if (awaitSubTopic.equals(requestTopic)) { + qoS = mqttMessage.getQos(); + payloadBytes = mqttMessage.getPayload(); + String responseTopic = requestTopic.replace("request", "response"); + try { + client.publish(responseTopic, DEVICE_RESPONSE.getBytes(StandardCharset.UTF_8)); + } catch (MqttException e) { + log.warn("Failed to publish response on topic: {} due to: ", responseTopic, e); + } + subscribeLatch.countDown(); + } + } + } + +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/MqttV5RpcTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/MqttV5RpcTest.java new file mode 100644 index 0000000000..caf188381b --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/rpc/MqttV5RpcTest.java @@ -0,0 +1,43 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.rpc; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +@DaoSqlTest +public class MqttV5RpcTest extends AbstractMqttV5RpcTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("RPC test device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testServerMqttV5SimpleClientOneWayRpc() throws Exception { + processOneWayRpcTest(); + } + + @Test + public void testServerMqttV5SimpleClientTwoWayRpc() throws Exception { + processJsonTwoWayRpcTest(); + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/AbstractMqttV5TimeseriesTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/AbstractMqttV5TimeseriesTest.java new file mode 100644 index 0000000000..4b08926d8d --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/AbstractMqttV5TimeseriesTest.java @@ -0,0 +1,132 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.timeseries; + +import com.fasterxml.jackson.core.type.TypeReference; +import org.thingsboard.server.common.data.device.profile.MqttTopics; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.transport.mqtt.mqttv5.AbstractMqttV5Test; +import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public abstract class AbstractMqttV5TimeseriesTest extends AbstractMqttV5Test { + + protected static final String PAYLOAD_VALUES_STR = "{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4," + + " \"key5\": {\"someNumber\": 42, \"someArray\": [1,2,3], \"someNestedObject\": {\"key\": \"value\"}}}"; + + protected void processTimeseriesMqttV5UploadTest() throws Exception { + + List expectedKeys = Arrays.asList("key1", "key2", "key3", "key4", "key5"); + + MqttV5TestClient client = new MqttV5TestClient(); + client.connectAndWait(accessToken); + client.publishAndWait(MqttTopics.DEVICE_TELEMETRY_TOPIC, PAYLOAD_VALUES_STR.getBytes()); + client.disconnect(); + + DeviceId deviceId = savedDevice.getId(); + + List actualKeys = getActualKeysList(deviceId, expectedKeys); + assertNotNull(actualKeys); + + Set actualKeySet = new HashSet<>(actualKeys); + Set expectedKeySet = new HashSet<>(expectedKeys); + + assertEquals(expectedKeySet, actualKeySet); + + String getTelemetryValuesUrl; + getTelemetryValuesUrl = "/api/plugins/telemetry/DEVICE/" + deviceId + "/values/timeseries?keys=" + String.join(",", actualKeySet); + long start = System.currentTimeMillis(); + long end = System.currentTimeMillis() + 5000; + Map>> values = null; + while (start <= end) { + values = doGetAsyncTyped(getTelemetryValuesUrl, new TypeReference<>() { + }); + boolean valid = values.size() == expectedKeys.size(); + if (valid) { + for (String key : expectedKeys) { + List> tsValues = values.get(key); + if (tsValues != null && tsValues.size() > 0) { + Object ts = tsValues.get(0).get("ts"); + if (ts == null) { + valid = false; + break; + } + } else { + valid = false; + break; + } + } + } + if (valid) { + break; + } + Thread.sleep(100); + start += 100; + } + assertNotNull(values); + assertValues(values); + } + + private List getActualKeysList(DeviceId deviceId, List expectedKeys) throws Exception { + long start = System.currentTimeMillis(); + long end = System.currentTimeMillis() + 3000; + + List actualKeys = null; + while (start <= end) { + actualKeys = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + deviceId + "/keys/timeseries", new TypeReference<>() { + }); + if (actualKeys.size() == expectedKeys.size()) { + break; + } + Thread.sleep(100); + start += 100; + } + return actualKeys; + } + + private void assertValues(Map>> deviceValues) { + for (Map.Entry>> entry : deviceValues.entrySet()) { + String key = entry.getKey(); + List> tsKv = entry.getValue(); + String value = (String) tsKv.get(0).get("value"); + switch (key) { + case "key1": + assertEquals("value1", value); + break; + case "key2": + assertEquals("true", value); + break; + case "key3": + assertEquals("3.0", value); + break; + case "key4": + assertEquals("4", value); + break; + case "key5": + assertEquals("{\"someNumber\":42,\"someArray\":[1,2,3],\"someNestedObject\":{\"key\":\"value\"}}", value); + break; + } + } + } +} diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java new file mode 100644 index 0000000000..83cf469f79 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java @@ -0,0 +1,37 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.mqttv5.timeseries; + +import org.junit.Before; +import org.junit.Test; +import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; + +public class MqttV5TimeseriesTest extends AbstractMqttV5TimeseriesTest { + + @Before + public void beforeTest() throws Exception { + MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() + .deviceName("Test Post Telemetry device") + .build(); + processBeforeTest(configProperties); + } + + @Test + public void testTimeseriesMqttV5SimpleClientUpload() throws Exception { + processTimeseriesMqttV5UploadTest(); + } + +} diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java index 2a320cc2ac..2b038097a0 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java @@ -26,6 +26,7 @@ import io.netty.handler.codec.mqtt.MqttConnectMessage; import io.netty.handler.codec.mqtt.MqttConnectReturnCode; import io.netty.handler.codec.mqtt.MqttFixedHeader; import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.codec.mqtt.MqttMessageBuilders; import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; import io.netty.handler.codec.mqtt.MqttPubAckMessage; import io.netty.handler.codec.mqtt.MqttPublishMessage; @@ -35,17 +36,18 @@ import io.netty.handler.codec.mqtt.MqttSubAckPayload; import io.netty.handler.codec.mqtt.MqttSubscribeMessage; import io.netty.handler.codec.mqtt.MqttTopicSubscription; import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; +import io.netty.handler.codec.mqtt.MqttVersion; import io.netty.handler.ssl.SslHandler; import io.netty.util.CharsetUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import lombok.extern.slf4j.Slf4j; -import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceTransportType; +import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.TransportPayloadType; import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.common.data.id.DeviceId; @@ -72,6 +74,8 @@ import org.thingsboard.server.transport.mqtt.adaptors.MqttTransportAdaptor; import org.thingsboard.server.transport.mqtt.session.DeviceSessionCtx; import org.thingsboard.server.transport.mqtt.session.GatewaySessionHandler; import org.thingsboard.server.transport.mqtt.session.MqttTopicMatcher; +import org.thingsboard.server.transport.mqtt.util.ReturnCode; +import org.thingsboard.server.transport.mqtt.util.ReturnCodeResolver; import javax.net.ssl.SSLPeerUnverifiedException; import java.io.IOException; @@ -79,6 +83,7 @@ import java.net.InetSocketAddress; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -90,17 +95,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.amazonaws.util.StringUtils.UTF8; -import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_ACCEPTED; -import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; import static io.netty.handler.codec.mqtt.MqttMessageType.CONNACK; import static io.netty.handler.codec.mqtt.MqttMessageType.CONNECT; import static io.netty.handler.codec.mqtt.MqttMessageType.PINGRESP; -import static io.netty.handler.codec.mqtt.MqttMessageType.PUBACK; import static io.netty.handler.codec.mqtt.MqttMessageType.SUBACK; import static io.netty.handler.codec.mqtt.MqttMessageType.UNSUBACK; import static io.netty.handler.codec.mqtt.MqttQoS.AT_LEAST_ONCE; import static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE; -import static io.netty.handler.codec.mqtt.MqttQoS.FAILURE; import static org.thingsboard.server.common.transport.service.DefaultTransportService.SESSION_EVENT_MSG_CLOSED; import static org.thingsboard.server.common.transport.service.DefaultTransportService.SESSION_EVENT_MSG_OPEN; @@ -355,10 +356,11 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement gatewaySessionHandler.onDeviceDisconnect(mqttMsg); break; default: - ack(ctx, msgId); + ack(ctx, msgId, ReturnCode.TOPIC_NAME_INVALID); } } catch (RuntimeException e) { log.warn("[{}] Failed to process publish msg [{}][{}]", sessionId, topicName, msgId, e); + ack(ctx, msgId, ReturnCode.IMPLEMENTATION_SPECIFIC); ctx.close(); } catch (AdaptorException e) { log.debug("[{}] Failed to process publish msg [{}][{}]", sessionId, topicName, msgId, e); @@ -447,7 +449,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement attrReqTopicType = TopicType.V2; } else { transportService.reportActivity(deviceSessionCtx.getSessionInfo()); - ack(ctx, msgId); + ack(ctx, msgId, ReturnCode.TOPIC_NAME_INVALID); } } catch (AdaptorException e) { log.debug("[{}] Failed to process publish msg [{}][{}]", sessionId, topicName, msgId, e); @@ -456,9 +458,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement } private void sendAckOrCloseSession(ChannelHandlerContext ctx, String topicName, int msgId) { - if (deviceSessionCtx.isSendAckOnValidationException() && msgId > 0) { + if ((deviceSessionCtx.isSendAckOnValidationException() || MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) && msgId > 0) { log.debug("[{}] Send pub ack on invalid publish msg [{}][{}]", sessionId, topicName, msgId); - ctx.writeAndFlush(createMqttPubAckMsg(msgId)); + ctx.writeAndFlush(createMqttPubAckMsg(deviceSessionCtx, msgId, ReturnCode.PAYLOAD_FORMAT_INVALID)); } else { log.info("[{}] Closing current session due to invalid publish msg [{}][{}]", sessionId, topicName, msgId); ctx.close(); @@ -500,9 +502,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement } } - private void ack(ChannelHandlerContext ctx, int msgId) { + private void ack(ChannelHandlerContext ctx, int msgId, ReturnCode returnCode) { if (msgId > 0) { - ctx.writeAndFlush(createMqttPubAckMsg(msgId)); + ctx.writeAndFlush(createMqttPubAckMsg(deviceSessionCtx, msgId, returnCode)); } } @@ -511,7 +513,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @Override public void onSuccess(Void dummy) { log.trace("[{}] Published msg: {}", sessionId, msg); - ack(ctx, msgId); + ack(ctx, msgId, ReturnCode.SUCCESS); } @Override @@ -536,7 +538,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @Override public void onSuccess(TransportProtos.ProvisionDeviceResponseMsg provisionResponseMsg) { log.trace("[{}] Published msg: {}", sessionId, msg); - ack(ctx, msgId); + ack(ctx, msgId, ReturnCode.SUCCESS); try { if (deviceSessionCtx.getProvisionPayloadType().equals(TransportPayloadType.JSON)) { deviceSessionCtx.getContext().getJsonMqttAdaptor().convertToPublish(deviceSessionCtx, provisionResponseMsg).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush); @@ -545,13 +547,14 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement } scheduler.schedule((Callable) ctx::close, 60, TimeUnit.SECONDS); } catch (Exception e) { - log.trace("[{}] Failed to convert device attributes response to MQTT msg", sessionId, e); + log.trace("[{}] Failed to convert device provision response to MQTT msg", sessionId, e); } } @Override public void onError(Throwable e) { log.trace("[{}] Failed to publish msg: {}", sessionId, msg, e); + ack(ctx, msgId, ReturnCode.IMPLEMENTATION_SPECIFIC); ctx.close(); } } @@ -593,7 +596,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void sendOtaPackage(ChannelHandlerContext ctx, int msgId, String firmwareId, String requestId, int chunkSize, int chunk, OtaPackageType type) { log.trace("[{}] Send firmware [{}] to device!", sessionId, firmwareId); - ack(ctx, msgId); + ack(ctx, msgId, ReturnCode.SUCCESS); try { byte[] firmwareChunk = context.getOtaPackageDataCache().get(firmwareId, chunkSize, chunk); deviceSessionCtx.getPayloadAdaptor() @@ -614,6 +617,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void processSubscribe(ChannelHandlerContext ctx, MqttSubscribeMessage mqttMsg) { if (!checkConnected(ctx, mqttMsg)) { + int returnCode = ReturnCodeResolver.getSubscriptionReturnCode(deviceSessionCtx.getMqttVersion(), ReturnCode.NOT_AUTHORIZED_5); + ctx.writeAndFlush(createSubAckMessage(mqttMsg.variableHeader().messageId(), Collections.singletonList(returnCode))); return; } log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId()); @@ -684,12 +689,12 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement break; default: log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topic, reqQoS); - grantedQoSList.add(FAILURE.value()); + grantedQoSList.add(ReturnCodeResolver.getSubscriptionReturnCode(deviceSessionCtx.getMqttVersion(), ReturnCode.TOPIC_FILTER_INVALID)); break; } } catch (Exception e) { log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topic, reqQoS, e); - grantedQoSList.add(FAILURE.value()); + grantedQoSList.add(ReturnCodeResolver.getSubscriptionReturnCode(deviceSessionCtx.getMqttVersion(), ReturnCode.IMPLEMENTATION_SPECIFIC)); } } if (!activityReported) { @@ -717,76 +722,93 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void processUnsubscribe(ChannelHandlerContext ctx, MqttUnsubscribeMessage mqttMsg) { if (!checkConnected(ctx, mqttMsg)) { + ctx.writeAndFlush(createUnSubAckMessage(mqttMsg.variableHeader().messageId(), Collections.singletonList(ReturnCode.NOT_AUTHORIZED_5.shortValue()))); return; } boolean activityReported = false; + List unSubResults = new ArrayList<>(); log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId()); for (String topicName : mqttMsg.payload().topics()) { - mqttQoSMap.remove(new MqttTopicMatcher(topicName)); - try { - switch (topicName) { - case MqttTopics.DEVICE_ATTRIBUTES_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC: { - transportService.process(deviceSessionCtx.getSessionInfo(), - TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().setUnsubscribe(true).build(), null); - activityReported = true; - break; - } - case MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC: - case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC: - case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_JSON_TOPIC: - case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC: { - transportService.process(deviceSessionCtx.getSessionInfo(), - TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(), null); - activityReported = true; - break; - } - case MqttTopics.DEVICE_RPC_RESPONSE_SUB_TOPIC: - case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_TOPIC: - case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_JSON_TOPIC: - case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_PROTO_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_JSON_TOPIC: - case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_PROTO_TOPIC: - case MqttTopics.GATEWAY_ATTRIBUTES_TOPIC: - case MqttTopics.GATEWAY_RPC_TOPIC: - case MqttTopics.GATEWAY_ATTRIBUTES_RESPONSE_TOPIC: - case MqttTopics.DEVICE_PROVISION_RESPONSE_TOPIC: - case MqttTopics.DEVICE_FIRMWARE_RESPONSES_TOPIC: - case MqttTopics.DEVICE_FIRMWARE_ERROR_TOPIC: - case MqttTopics.DEVICE_SOFTWARE_RESPONSES_TOPIC: - case MqttTopics.DEVICE_SOFTWARE_ERROR_TOPIC: { - activityReported = true; - break; + MqttTopicMatcher matcher = new MqttTopicMatcher(topicName); + if (mqttQoSMap.containsKey(matcher)) { + mqttQoSMap.remove(matcher); + try { + short resultValue = ReturnCode.SUCCESS.shortValue(); + switch (topicName) { + case MqttTopics.DEVICE_ATTRIBUTES_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_SHORT_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_SHORT_PROTO_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_SHORT_JSON_TOPIC: { + transportService.process(deviceSessionCtx.getSessionInfo(), + TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().setUnsubscribe(true).build(), null); + activityReported = true; + break; + } + case MqttTopics.DEVICE_RPC_REQUESTS_SUB_TOPIC: + case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_TOPIC: + case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_JSON_TOPIC: + case MqttTopics.DEVICE_RPC_REQUESTS_SUB_SHORT_PROTO_TOPIC: { + transportService.process(deviceSessionCtx.getSessionInfo(), + TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(), null); + activityReported = true; + break; + } + case MqttTopics.DEVICE_RPC_RESPONSE_SUB_TOPIC: + case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_TOPIC: + case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_JSON_TOPIC: + case MqttTopics.DEVICE_RPC_RESPONSE_SUB_SHORT_PROTO_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_JSON_TOPIC: + case MqttTopics.DEVICE_ATTRIBUTES_RESPONSES_SHORT_PROTO_TOPIC: + case MqttTopics.GATEWAY_ATTRIBUTES_TOPIC: + case MqttTopics.GATEWAY_RPC_TOPIC: + case MqttTopics.GATEWAY_ATTRIBUTES_RESPONSE_TOPIC: + case MqttTopics.DEVICE_PROVISION_RESPONSE_TOPIC: + case MqttTopics.DEVICE_FIRMWARE_RESPONSES_TOPIC: + case MqttTopics.DEVICE_FIRMWARE_ERROR_TOPIC: + case MqttTopics.DEVICE_SOFTWARE_RESPONSES_TOPIC: + case MqttTopics.DEVICE_SOFTWARE_ERROR_TOPIC: { + activityReported = true; + break; + } + default: + log.trace("[{}] Failed to process unsubscription [{}] to [{}]", sessionId, mqttMsg.variableHeader().messageId(), topicName); + resultValue = ReturnCode.TOPIC_FILTER_INVALID.shortValue(); } + unSubResults.add(resultValue); + } catch (Exception e) { + log.debug("[{}] Failed to process unsubscription [{}] to [{}]", sessionId, mqttMsg.variableHeader().messageId(), topicName); + unSubResults.add(ReturnCode.IMPLEMENTATION_SPECIFIC.shortValue()); } - } catch (Exception e) { - log.debug("[{}] Failed to process unsubscription [{}] to [{}]", sessionId, mqttMsg.variableHeader().messageId(), topicName); + } else { + log.debug("[{}] Failed to process unsubscription [{}] to [{}] - Subscription not found", sessionId, mqttMsg.variableHeader().messageId(), topicName); + unSubResults.add(ReturnCode.NO_SUBSCRIPTION_EXISTED.shortValue()); } } if (!activityReported) { transportService.reportActivity(deviceSessionCtx.getSessionInfo()); } - ctx.writeAndFlush(createUnSubAckMessage(mqttMsg.variableHeader().messageId())); + ctx.writeAndFlush(createUnSubAckMessage(mqttMsg.variableHeader().messageId(), unSubResults)); } - private MqttMessage createUnSubAckMessage(int msgId) { - MqttFixedHeader mqttFixedHeader = - new MqttFixedHeader(UNSUBACK, false, AT_MOST_ONCE, false, 0); - MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId); - return new MqttMessage(mqttFixedHeader, mqttMessageIdVariableHeader); + private MqttMessage createUnSubAckMessage(int msgId, List resultCodes) { + MqttMessageBuilders.UnsubAckBuilder unsubAckBuilder = MqttMessageBuilders.unsubAck(); + unsubAckBuilder.packetId(msgId); + if (MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) { + unsubAckBuilder.addReasonCodes(resultCodes.toArray(Short[]::new)); + } + return unsubAckBuilder.build(); } void processConnect(ChannelHandlerContext ctx, MqttConnectMessage msg) { log.debug("[{}][{}] Processing connect msg for client: {}!", address, sessionId, msg.payload().clientIdentifier()); String userName = msg.payload().userName(); String clientId = msg.payload().clientIdentifier(); + deviceSessionCtx.setMqttVersion(getMqttVersion(msg.variableHeader().version())); if (DataConstants.PROVISION.equals(userName) || DataConstants.PROVISION.equals(clientId)) { deviceSessionCtx.setProvisionOnly(true); - ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED, msg)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.SUCCESS, msg)); } else { X509Certificate cert; if (sslHandler != null && (cert = getX509Certificate()) != null) { @@ -820,7 +842,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @Override public void onError(Throwable e) { log.trace("[{}] Failed to process credentials: {}", address, userName, e); - ctx.writeAndFlush(createMqttConnAckMsg(MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE, connectMessage)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.SERVER_UNAVAILABLE_5, connectMessage)); ctx.close(); } }); @@ -843,13 +865,13 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @Override public void onError(Throwable e) { log.trace("[{}] Failed to process credentials: {}", address, sha3Hash, e); - ctx.writeAndFlush(createMqttConnAckMsg(MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE, connectMessage)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.SERVER_UNAVAILABLE_5, connectMessage)); ctx.close(); } }); } catch (Exception e) { context.onAuthFailure(address); - ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_REFUSED_NOT_AUTHORIZED, connectMessage)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.NOT_AUTHORIZED_5, connectMessage)); log.trace("[{}] X509 auth failure: {}", sessionId, address, e); ctx.close(); } @@ -868,11 +890,12 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement return null; } - private MqttConnAckMessage createMqttConnAckMsg(MqttConnectReturnCode returnCode, MqttConnectMessage msg) { + private MqttConnAckMessage createMqttConnAckMsg(ReturnCode returnCode, MqttConnectMessage msg) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(CONNACK, false, AT_MOST_ONCE, false, 0); + MqttConnectReturnCode finalReturnCode = ReturnCodeResolver.getConnectionReturnCode(deviceSessionCtx.getMqttVersion(), returnCode); MqttConnAckVariableHeader mqttConnAckVariableHeader = - new MqttConnAckVariableHeader(returnCode, !msg.variableHeader().isCleanSession()); + new MqttConnAckVariableHeader(finalReturnCode, !msg.variableHeader().isCleanSession()); return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); } @@ -918,12 +941,24 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement return Math.min(reqQoS.value(), MAX_SUPPORTED_QOS_LVL.value()); } - public static MqttPubAckMessage createMqttPubAckMsg(int requestId) { - MqttFixedHeader mqttFixedHeader = - new MqttFixedHeader(PUBACK, false, AT_MOST_ONCE, false, 0); - MqttMessageIdVariableHeader mqttMsgIdVariableHeader = - MqttMessageIdVariableHeader.from(requestId); - return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader); + private static MqttVersion getMqttVersion(int versionCode) { + switch (versionCode) { + case 3: + return MqttVersion.MQTT_3_1; + case 5: + return MqttVersion.MQTT_5; + default: + case 4: + return MqttVersion.MQTT_3_1_1; + } + } + + public static MqttMessage createMqttPubAckMsg(DeviceSessionCtx deviceSessionCtx, int requestId, ReturnCode returnCode) { + MqttMessageBuilders.PubAckBuilder pubAckMsgBuilder = MqttMessageBuilders.pubAck().packetId(requestId); + if (MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) { + pubAckMsgBuilder.reasonCode(returnCode.byteValue()); + } + return pubAckMsgBuilder.build(); } private boolean checkConnected(ChannelHandlerContext ctx, MqttMessage msg) { @@ -976,7 +1011,15 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void onValidateDeviceResponse(ValidateDeviceCredentialsResponse msg, ChannelHandlerContext ctx, MqttConnectMessage connectMessage) { if (!msg.hasDeviceInfo()) { context.onAuthFailure(address); - ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_REFUSED_NOT_AUTHORIZED, connectMessage)); + ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5; + if (sslHandler == null || getX509Certificate() == null) { + if (connectMessage.payload().userName() == null ^ connectMessage.payload().passwordInBytes() == null) { + returnCode = ReturnCode.BAD_USERNAME_OR_PASSWORD; + } else if (!StringUtils.isBlank(connectMessage.payload().clientIdentifier())) { + returnCode = ReturnCode.CLIENT_IDENTIFIER_NOT_VALID; + } + } + ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage)); ctx.close(); } else { context.onAuthSuccess(address); @@ -988,7 +1031,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement public void onSuccess(Void msg) { SessionMetaData sessionMetaData = transportService.registerAsyncSession(deviceSessionCtx.getSessionInfo(), MqttTransportHandler.this); checkGatewaySession(sessionMetaData); - ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED, connectMessage)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.SUCCESS, connectMessage)); deviceSessionCtx.setConnected(true); log.debug("[{}] Client connected!", sessionId); transportService.getCallbackExecutor().execute(() -> processMsgQueue(ctx)); //this callback will execute in Producer worker thread and hard or blocking work have to be submitted to the separate thread. @@ -1001,7 +1044,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement } else { log.warn("[{}] Failed to submit session event", sessionId, e); } - ctx.writeAndFlush(createMqttConnAckMsg(MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE, connectMessage)); + ctx.writeAndFlush(createMqttConnAckMsg(ReturnCode.SERVER_UNAVAILABLE_5, connectMessage)); ctx.close(); } }); diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java index 2163610b38..e1077600f0 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/DeviceSessionCtx.java @@ -19,6 +19,7 @@ import com.google.protobuf.Descriptors; import com.google.protobuf.DynamicMessage; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.codec.mqtt.MqttVersion; import io.netty.util.ReferenceCountUtil; import lombok.Getter; import lombok.Setter; @@ -74,6 +75,12 @@ public class DeviceSessionCtx extends MqttDeviceAwareSessionContext { @Setter private boolean provisionOnly = false; + @Getter + @Setter + private MqttVersion mqttVersion; + + + private volatile MqttTopicFilter telemetryTopicFilter = MqttTopicFilterFactory.getDefaultTelemetryFilter(); private volatile MqttTopicFilter attributesTopicFilter = MqttTopicFilterFactory.getDefaultAttributesFilter(); private volatile TransportPayloadType payloadType = TransportPayloadType.JSON; diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionHandler.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionHandler.java index fad67470ba..c3c4e91d0a 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionHandler.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/session/GatewaySessionHandler.java @@ -53,6 +53,7 @@ import org.thingsboard.server.transport.mqtt.MqttTransportHandler; import org.thingsboard.server.transport.mqtt.adaptors.JsonMqttAdaptor; import org.thingsboard.server.transport.mqtt.adaptors.MqttTransportAdaptor; import org.thingsboard.server.transport.mqtt.adaptors.ProtoMqttAdaptor; +import org.thingsboard.server.transport.mqtt.util.ReturnCode; import javax.annotation.Nullable; import java.util.Collections; @@ -220,7 +221,7 @@ public class GatewaySessionHandler { Futures.addCallback(onDeviceConnect(deviceName, deviceType), new FutureCallback() { @Override public void onSuccess(@Nullable GatewayDeviceSessionCtx result) { - ack(msg); + ack(msg, ReturnCode.SUCCESS); log.trace("[{}] onDeviceConnectOk: {}", sessionId, deviceName); } @@ -336,7 +337,7 @@ public class GatewaySessionHandler { private void processOnDisconnect(MqttPublishMessage msg, String deviceName) { deregisterSession(deviceName); - ack(msg); + ack(msg, ReturnCode.SUCCESS); } private void onDeviceTelemetryJson(int msgId, ByteBuf payload) throws AdaptorException { @@ -663,7 +664,7 @@ public class GatewaySessionHandler { @Override public void onFailure(Throwable t) { - ack(mqttMsg); + ack(mqttMsg, ReturnCode.IMPLEMENTATION_SPECIFIC); log.debug("[{}] Failed to process device attributes request command: {}", sessionId, deviceName, t); } }, context.getExecutor()); @@ -716,10 +717,10 @@ public class GatewaySessionHandler { return ProtoMqttAdaptor.toBytes(payload); } - private void ack(MqttPublishMessage msg) { + private void ack(MqttPublishMessage msg, ReturnCode returnCode) { int msgId = getMsgId(msg); if (msgId > 0) { - writeAndFlush(MqttTransportHandler.createMqttPubAckMsg(msgId)); + writeAndFlush(MqttTransportHandler.createMqttPubAckMsg(deviceSessionCtx, msgId, returnCode)); } } @@ -735,7 +736,7 @@ public class GatewaySessionHandler { public void onSuccess(Void dummy) { log.trace("[{}][{}] Published msg: {}", sessionId, deviceName, msg); if (msgId > 0) { - ctx.writeAndFlush(MqttTransportHandler.createMqttPubAckMsg(msgId)); + ctx.writeAndFlush(MqttTransportHandler.createMqttPubAckMsg(deviceSessionCtx, msgId, ReturnCode.SUCCESS)); } } diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCode.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCode.java new file mode 100644 index 0000000000..f7b9218d69 --- /dev/null +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCode.java @@ -0,0 +1,104 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.util; + +public enum ReturnCode { + SUCCESS((byte) 0x00), + //MQTT 3 codes + UNACCEPTABLE_PROTOCOL_VERSION((byte) 0X01), + IDENTIFIER_REJECTED((byte) 0x02), + SERVER_UNAVAILABLE((byte) 0x03), + BAD_USER_NAME_OR_PASSWORD((byte) 0x04), + NOT_AUTHORIZED((byte) 0x05), + //MQTT 5 codes + NO_MATCHING_SUBSCRIBERS((byte) 0x10), + NO_SUBSCRIPTION_EXISTED((byte) 0x11), + CONTINUE_AUTHENTICATION((byte) 0x18), + REAUTHENTICATE((byte) 0x19), + UNSPECIFIED_ERROR((byte) 0x80), + MALFORMED_PACKET((byte) 0x81), + PROTOCOL_ERROR((byte) 0x82), + IMPLEMENTATION_SPECIFIC((byte) 0x83), + UNSUPPORTED_PROTOCOL_VERSION((byte) 0x84), + CLIENT_IDENTIFIER_NOT_VALID((byte) 0x85), + BAD_USERNAME_OR_PASSWORD((byte) 0x86), + NOT_AUTHORIZED_5((byte) 0x87), + SERVER_UNAVAILABLE_5((byte) 0x88), + SERVER_BUSY((byte) 0x89), + BANNED((byte) 0x8A), + SERVER_SHUTTING_DOWN((byte) 0x8B), + BAD_AUTHENTICATION_METHOD((byte) 0x8C), + KEEP_ALIVE_TIMEOUT((byte) 0x8D), + SESSION_TAKEN_OVER((byte) 0x8E), + TOPIC_FILTER_INVALID((byte) 0x8F), + TOPIC_NAME_INVALID((byte) 0x90), + PACKET_IDENTIFIER_IN_USE((byte) 0x91), + PACKET_IDENTIFIER_NOT_FOUND((byte) 0x92), + RECEIVE_MAXIMUM_EXCEEDED((byte) 0x93), + TOPIC_ALIAS_INVALID((byte) 0x94), + PACKET_TOO_LARGE((byte) 0x95), + MESSAGE_RATE_TOO_HIGH((byte) 0x96), + QUOTA_EXCEEDED((byte) 0x97), + ADMINISTRATIVE_ACTION((byte) 0x98), + PAYLOAD_FORMAT_INVALID((byte) 0x99), + RETAIN_NOT_SUPPORTED((byte) 0x9A), + QOS_NOT_SUPPORTED((byte) 0x9B), + USE_ANOTHER_SERVER((byte) 0x9C), + SERVER_MOVED((byte) 0x9D), + SHARED_SUBSCRIPTION_NOT_SUPPORTED((byte) 0x9E), + CONNECTION_RATE_EXCEEDED((byte) 0x9F), + MAXIMUM_CONNECT_TIME((byte) 0xA0), + SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED((byte) 0xA1), + WILDCARD_SUBSCRIPTION_NOT_SUPPORTED((byte) 0xA2); + + private static final ReturnCode[] VALUES; + + static { + ReturnCode[] values = values(); + VALUES = new ReturnCode[163]; + for (ReturnCode code : values) { + final int unsignedByte = code.byteValue & 0xFF; + // Suppress a warning about out of bounds access since the enum contains only correct values + VALUES[unsignedByte] = code; // lgtm [java/index-out-of-bounds] + } + } + + private final byte byteValue; + + ReturnCode(byte byteValue) { + this.byteValue = byteValue; + } + + public byte byteValue() { + return byteValue; + } + + public short shortValue(){return byteValue;} + + public static ReturnCode valueOf(byte b) { + final int unsignedByte = b & 0xFF; + ReturnCode mqttConnectReturnCode = null; + try { + mqttConnectReturnCode = VALUES[unsignedByte]; + } catch (ArrayIndexOutOfBoundsException ignored) { + // no op + } + if (mqttConnectReturnCode == null) { + throw new IllegalArgumentException("unknown connect return code: " + unsignedByte); + } + return mqttConnectReturnCode; + } +} \ No newline at end of file diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCodeResolver.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCodeResolver.java new file mode 100644 index 0000000000..a187dd71f5 --- /dev/null +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/util/ReturnCodeResolver.java @@ -0,0 +1,61 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.transport.mqtt.util; + +import io.netty.handler.codec.mqtt.MqttConnectReturnCode; +import io.netty.handler.codec.mqtt.MqttQoS; +import io.netty.handler.codec.mqtt.MqttVersion; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ReturnCodeResolver { + + public static MqttConnectReturnCode getConnectionReturnCode(MqttVersion mqttVersion, ReturnCode returnCode) { + if (!MqttVersion.MQTT_5.equals(mqttVersion) && !ReturnCode.SUCCESS.equals(returnCode)) { + switch (returnCode) { + case BAD_USERNAME_OR_PASSWORD: + return MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; + case NOT_AUTHORIZED_5: + return MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED; + case SERVER_UNAVAILABLE_5: + return MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; + case CLIENT_IDENTIFIER_NOT_VALID: + return MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; + default: + log.warn("Unknown return code for conversion: {}", returnCode.name()); + } + } + return MqttConnectReturnCode.valueOf(returnCode.byteValue()); + } + + public static int getSubscriptionReturnCode(MqttVersion mqttVersion, ReturnCode returnCode) { + if (!MqttVersion.MQTT_5.equals(mqttVersion) && !ReturnCode.SUCCESS.equals(returnCode)) { + switch (returnCode) { + case UNSPECIFIED_ERROR: + case TOPIC_FILTER_INVALID: + case IMPLEMENTATION_SPECIFIC: + case NOT_AUTHORIZED_5: + case PACKET_IDENTIFIER_IN_USE: + case QUOTA_EXCEEDED: + case SHARED_SUBSCRIPTION_NOT_SUPPORTED: + case SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED: + case WILDCARD_SUBSCRIPTION_NOT_SUPPORTED: + return MqttQoS.FAILURE.value(); + } + } + return returnCode.byteValue(); + } +} diff --git a/pom.xml b/pom.xml index 60e8783bca..903b9a7b08 100755 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ 2.4.23TB 1.18.18 1.2.4 + 1.2.5 4.1.75.Final 2.0.51.Final 1.7.0 @@ -1657,6 +1658,11 @@ org.eclipse.paho.client.mqttv3 ${paho.client.version} + + org.eclipse.paho + org.eclipse.paho.mqttv5.client + ${paho.mqttv5.client.version} + org.apache.curator curator-x-discovery From 885c1c3d8838ca77b1453ba88cbb13b631c8d20e Mon Sep 17 00:00:00 2001 From: imbeacon Date: Thu, 10 Nov 2022 18:31:34 +0200 Subject: [PATCH 003/527] Updated ConAck message building --- .../transport/mqtt/mqttv3/MqttTestClient.java | 15 +++------------ .../client/AbstractMqttClientConnectionTest.java | 9 --------- .../mqttv3/client/MqttClientConnectionTest.java | 5 ----- .../transport/mqtt/MqttTransportHandler.java | 9 ++++----- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java index 7bd36aae4d..c4ae91a2b5 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java @@ -43,10 +43,6 @@ public class MqttTestClient { this.client = createClient(); } - public MqttTestClient(boolean generateClientId) throws MqttException { - this.client = createClient(generateClientId); - } - public MqttTestClient(String clientId) throws MqttException { this.client = createClient(clientId); } @@ -121,18 +117,13 @@ public class MqttTestClient { } private MqttAsyncClient createClient() throws MqttException { - return createClient(true); + return createClient(null); } - private MqttAsyncClient createClient(boolean generateClientId) throws MqttException { - String clientId = null; - if (generateClientId) { + private MqttAsyncClient createClient(String clientId) throws MqttException { + if (clientId == null) { clientId = MqttAsyncClient.generateClientId(); } - return createClient(clientId); - } - - private MqttAsyncClient createClient(String clientId) throws MqttException { return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); } diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java index dd1da7ef34..634458c07d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/AbstractMqttClientConnectionTest.java @@ -47,13 +47,4 @@ public abstract class AbstractMqttClientConnectionTest extends AbstractMqttInteg } } - protected void processClientWithNoCredentialsTest() throws Exception { - MqttTestClient client = new MqttTestClient(false); - try { - client.connectAndWait(); - } catch (MqttException e) { - Assert.assertEquals(MqttException.REASON_CODE_NOT_AUTHORIZED, e.getReasonCode()); - } - } - } diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java index 124521eaa2..5e6e6e0188 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/client/MqttClientConnectionTest.java @@ -45,9 +45,4 @@ public class MqttClientConnectionTest extends AbstractMqttClientConnectionTest { public void testClientWithWrongClientIdAndEmptyUsernamePassword() throws Exception { processClientWithWrongClientIdAndEmptyUsernamePasswordTest(); } - - @Test - public void testClientWithNoCredentialsTest() throws Exception { - processClientWithNoCredentialsTest(); - } } diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java index 2b038097a0..eee19b61a2 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java @@ -891,12 +891,11 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement } private MqttConnAckMessage createMqttConnAckMsg(ReturnCode returnCode, MqttConnectMessage msg) { - MqttFixedHeader mqttFixedHeader = - new MqttFixedHeader(CONNACK, false, AT_MOST_ONCE, false, 0); + MqttMessageBuilders.ConnAckBuilder connAckBuilder = MqttMessageBuilders.connAck(); + connAckBuilder.sessionPresent(!msg.variableHeader().isCleanSession()); MqttConnectReturnCode finalReturnCode = ReturnCodeResolver.getConnectionReturnCode(deviceSessionCtx.getMqttVersion(), returnCode); - MqttConnAckVariableHeader mqttConnAckVariableHeader = - new MqttConnAckVariableHeader(finalReturnCode, !msg.variableHeader().isCleanSession()); - return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); + connAckBuilder.returnCode(finalReturnCode); + return connAckBuilder.build(); } @Override From dfbf3a9cd8b27dfcc211a6649a17aadcee7c4cd9 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Fri, 11 Nov 2022 15:39:53 +0200 Subject: [PATCH 004/527] Test fixes, keep logic for auth for mqtt v3 --- .../transport/mqtt/mqttv3/MqttTestClient.java | 2 +- .../publish/AbstractMqttV5ClientPublishTest.java | 3 --- .../AbstractMqttV5ClientSubscriptionTest.java | 9 --------- .../subscribe/MqttV5ClientSubscriptionTest.java | 1 - .../AbstractMqttV5ClientUnsubscribeTest.java | 1 - ...eTest.java => MqttV5ProvisionDeviceTest.java} | 2 +- .../mqttv5/timeseries/MqttV5TimeseriesTest.java | 2 ++ .../transport/mqtt/MqttTransportHandler.java | 16 +++++++++------- 8 files changed, 13 insertions(+), 23 deletions(-) rename application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/{MqttProvisionJsonDeviceTest.java => MqttV5ProvisionDeviceTest.java} (98%) diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java index c4ae91a2b5..a0aa1905eb 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/MqttTestClient.java @@ -121,7 +121,7 @@ public class MqttTestClient { } private MqttAsyncClient createClient(String clientId) throws MqttException { - if (clientId == null) { + if (StringUtils.isEmpty(clientId)) { clientId = MqttAsyncClient.generateClientId(); } return new MqttAsyncClient(MQTT_URL, clientId, new MemoryPersistence()); diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java index 4520cdcb26..bd4c6b4bb8 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/publish/AbstractMqttV5ClientPublishTest.java @@ -15,11 +15,9 @@ */ package org.thingsboard.server.transport.mqtt.mqttv5.client.publish; -import io.netty.handler.codec.mqtt.MqttQoS; import org.eclipse.paho.mqttv5.client.IMqttToken; import org.eclipse.paho.mqttv5.common.packet.MqttPubAck; import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; -import org.eclipse.paho.mqttv5.common.packet.MqttSubAck; import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; import org.junit.Assert; import org.thingsboard.server.common.data.device.profile.MqttTopics; @@ -27,7 +25,6 @@ import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_PUBACK; -import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK; public abstract class AbstractMqttV5ClientPublishTest extends AbstractMqttIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java index d2a11072a2..edab7b5b8d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/AbstractMqttV5ClientSubscriptionTest.java @@ -16,25 +16,16 @@ package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe; import io.netty.handler.codec.mqtt.MqttQoS; -import org.apache.commons.lang3.StringUtils; import org.eclipse.paho.mqttv5.client.IMqttToken; -import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; -import org.eclipse.paho.mqttv5.common.MqttException; -import org.eclipse.paho.mqttv5.common.packet.MqttConnAck; import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; import org.eclipse.paho.mqttv5.common.packet.MqttSubAck; import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; import org.junit.Assert; import org.thingsboard.server.common.data.device.profile.MqttTopics; import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; -import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestCallback; import org.thingsboard.server.transport.mqtt.mqttv5.MqttV5TestClient; -import java.util.concurrent.TimeUnit; - -import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_CONNACK; import static org.eclipse.paho.mqttv5.common.packet.MqttWireMessage.MESSAGE_TYPE_SUBACK; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; public abstract class AbstractMqttV5ClientSubscriptionTest extends AbstractMqttIntegrationTest { diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java index 37404a8911..e40363357a 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/subscribe/MqttV5ClientSubscriptionTest.java @@ -16,7 +16,6 @@ package org.thingsboard.server.transport.mqtt.mqttv5.client.subscribe; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java index f2088e704d..79f529fa0d 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/client/unsubscribe/AbstractMqttV5ClientUnsubscribeTest.java @@ -17,7 +17,6 @@ package org.thingsboard.server.transport.mqtt.mqttv5.client.unsubscribe; import io.netty.handler.codec.mqtt.MqttQoS; import org.eclipse.paho.mqttv5.client.IMqttToken; -import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; import org.eclipse.paho.mqttv5.common.packet.MqttReturnCode; import org.eclipse.paho.mqttv5.common.packet.MqttUnsubAck; import org.eclipse.paho.mqttv5.common.packet.MqttWireMessage; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttV5ProvisionDeviceTest.java similarity index 98% rename from application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java rename to application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttV5ProvisionDeviceTest.java index 942befc2f1..3fc41e83e2 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttProvisionJsonDeviceTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/provision/MqttV5ProvisionDeviceTest.java @@ -42,7 +42,7 @@ import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVIC @Slf4j @DaoSqlTest -public class MqttProvisionJsonDeviceTest extends AbstractMqttV5Test { +public class MqttV5ProvisionDeviceTest extends AbstractMqttV5Test { @Autowired DeviceCredentialsService deviceCredentialsService; diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java index 83cf469f79..60b935e661 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv5/timeseries/MqttV5TimeseriesTest.java @@ -17,8 +17,10 @@ package org.thingsboard.server.transport.mqtt.mqttv5.timeseries; import org.junit.Before; import org.junit.Test; +import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; +@DaoSqlTest public class MqttV5TimeseriesTest extends AbstractMqttV5TimeseriesTest { @Before diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java index eee19b61a2..c03a7dd441 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java @@ -1010,15 +1010,17 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void onValidateDeviceResponse(ValidateDeviceCredentialsResponse msg, ChannelHandlerContext ctx, MqttConnectMessage connectMessage) { if (!msg.hasDeviceInfo()) { context.onAuthFailure(address); - ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5; - if (sslHandler == null || getX509Certificate() == null) { - if (connectMessage.payload().userName() == null ^ connectMessage.payload().passwordInBytes() == null) { - returnCode = ReturnCode.BAD_USERNAME_OR_PASSWORD; - } else if (!StringUtils.isBlank(connectMessage.payload().clientIdentifier())) { - returnCode = ReturnCode.CLIENT_IDENTIFIER_NOT_VALID; + if (MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) { + ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5; + if (sslHandler == null || getX509Certificate() == null) { + if (connectMessage.payload().userName() == null ^ connectMessage.payload().passwordInBytes() == null) { + returnCode = ReturnCode.BAD_USERNAME_OR_PASSWORD; + } else if (!StringUtils.isBlank(connectMessage.payload().clientIdentifier())) { + returnCode = ReturnCode.CLIENT_IDENTIFIER_NOT_VALID; + } } + ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage)); } - ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage)); ctx.close(); } else { context.onAuthSuccess(address); From 05f92d7222b63c9bf1699056641aaf35478e6bc8 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Fri, 11 Nov 2022 17:28:00 +0200 Subject: [PATCH 005/527] Updated BasicMqttCredentials processing --- .../credentials/BasicMqttCredentialsTest.java | 11 +++++++--- .../transport/mqtt/MqttTransportHandler.java | 20 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java index 288d0ca45c..496a13ad70 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java @@ -16,7 +16,8 @@ package org.thingsboard.server.transport.mqtt.mqttv3.credentials; import com.fasterxml.jackson.core.type.TypeReference; -import org.eclipse.paho.client.mqttv3.MqttSecurityException; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.thingsboard.common.util.JacksonUtil; @@ -114,11 +115,15 @@ public class BasicMqttCredentialsTest extends AbstractMqttIntegrationTest { testTelemetryIsDelivered(accessToken2Device, mqttTestClient5); } - @Test(expected = MqttSecurityException.class) + @Test public void testCorrectClientIdAndUserNameButWrongPassword() throws Exception { // Not correct. Correct clientId and username, but wrong password MqttTestClient mqttTestClient = new MqttTestClient(CLIENT_ID); - mqttTestClient.connectAndWait(USER_NAME3, "WRONG PASSWORD"); + try { + mqttTestClient.connectAndWait(USER_NAME3, "WRONG PASSWORD"); + } catch (MqttException e) { + Assert.assertEquals(4, e.getReasonCode()); // 4 - Reason code for bad username or password in MQTT v3 + } testTelemetryIsNotDelivered(clientIdAndUserNameAndPasswordDevice3, mqttTestClient); } diff --git a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java index c03a7dd441..2c3ac45326 100644 --- a/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java +++ b/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java @@ -1010,17 +1010,19 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement private void onValidateDeviceResponse(ValidateDeviceCredentialsResponse msg, ChannelHandlerContext ctx, MqttConnectMessage connectMessage) { if (!msg.hasDeviceInfo()) { context.onAuthFailure(address); - if (MqttVersion.MQTT_5.equals(deviceSessionCtx.getMqttVersion())) { - ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5; - if (sslHandler == null || getX509Certificate() == null) { - if (connectMessage.payload().userName() == null ^ connectMessage.payload().passwordInBytes() == null) { - returnCode = ReturnCode.BAD_USERNAME_OR_PASSWORD; - } else if (!StringUtils.isBlank(connectMessage.payload().clientIdentifier())) { - returnCode = ReturnCode.CLIENT_IDENTIFIER_NOT_VALID; - } + ReturnCode returnCode = ReturnCode.NOT_AUTHORIZED_5; + if (sslHandler == null || getX509Certificate() == null) { + String username = connectMessage.payload().userName(); + byte[] passwordBytes = connectMessage.payload().passwordInBytes(); + String clientId = connectMessage.payload().clientIdentifier(); + if ((username != null && passwordBytes != null && clientId != null) + || (username == null ^ passwordBytes == null)) { + returnCode = ReturnCode.BAD_USERNAME_OR_PASSWORD; + } else if (!StringUtils.isBlank(clientId)) { + returnCode = ReturnCode.CLIENT_IDENTIFIER_NOT_VALID; } - ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage)); } + ctx.writeAndFlush(createMqttConnAckMsg(returnCode, connectMessage)); ctx.close(); } else { context.onAuthSuccess(address); From d4ea6461744baf25aa78e2a1ff31487ad2484c13 Mon Sep 17 00:00:00 2001 From: zbeacon Date: Mon, 14 Nov 2022 13:02:29 +0200 Subject: [PATCH 006/527] Changed expected exception such as we have not connected client --- .../mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java index 496a13ad70..9e22a226d4 100644 --- a/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/mqtt/mqttv3/credentials/BasicMqttCredentialsTest.java @@ -115,7 +115,7 @@ public class BasicMqttCredentialsTest extends AbstractMqttIntegrationTest { testTelemetryIsDelivered(accessToken2Device, mqttTestClient5); } - @Test + @Test(expected = MqttException.class) public void testCorrectClientIdAndUserNameButWrongPassword() throws Exception { // Not correct. Correct clientId and username, but wrong password MqttTestClient mqttTestClient = new MqttTestClient(CLIENT_ID); From be1acd219b588e55ebef79f84fbe6577f8fa00f2 Mon Sep 17 00:00:00 2001 From: Serafym Tuhai Date: Tue, 22 Nov 2022 13:17:01 +0200 Subject: [PATCH 007/527] add ui tests --- msa/black-box-tests/pom.xml | 24 ++ .../server/msa/ui/base/AbstractBasePage.java | 129 +++++++++ .../msa/ui/base/AbstractDiverBaseTest.java | 74 +++++ .../msa/ui/listeners/RetryAnalyzer.java | 20 ++ .../msa/ui/listeners/RetryTestListener.java | 18 ++ .../server/msa/ui/listeners/TestListener.java | 62 ++++ .../msa/ui/pages/CustomerPageElements.java | 262 +++++++++++++++++ .../msa/ui/pages/CustomerPageHelper.java | 161 +++++++++++ .../msa/ui/pages/DashboardPageElements.java | 38 +++ .../msa/ui/pages/DashboardPageHelper.java | 25 ++ .../msa/ui/pages/LoginPageElements.java | 28 ++ .../server/msa/ui/pages/LoginPageHelper.java | 16 ++ .../ui/pages/OpenRuleChainPageElements.java | 33 +++ .../msa/ui/pages/OpenRuleChainPageHelper.java | 23 ++ .../msa/ui/pages/OtherPageElements.java | 228 +++++++++++++++ .../msa/ui/pages/OtherPageElementsHelper.java | 98 +++++++ .../msa/ui/pages/RuleChainsPageElements.java | 113 ++++++++ .../msa/ui/pages/RuleChainsPageHelper.java | 180 ++++++++++++ .../msa/ui/pages/SideBarMenuViewElements.java | 27 ++ .../customerSmoke/CreateCustomerTest.java | 164 +++++++++++ .../customerSmoke/CustomerEditMenuTest.java | 270 ++++++++++++++++++ .../customerSmoke/DeleteCustomerTest.java | 83 ++++++ .../DeleteSeveralCustomerTest.java | 81 ++++++ .../ManageCustomersAssetsTest.java | 54 ++++ .../ManageCustomersDashboardsTest.java | 53 ++++ .../ManageCustomersDevicesTest.java | 53 ++++ .../ManageCustomersEdgesTest.java | 54 ++++ .../ManageCustomersUsersTest.java | 54 ++++ .../customerSmoke/SearchCustomerTest.java | 56 ++++ .../tests/customerSmoke/SortByNameTest.java | 121 ++++++++ .../CreateRuleChainImportTest.java | 110 +++++++ .../ruleChainsSmoke/CreateRuleChainTest.java | 139 +++++++++ .../ruleChainsSmoke/DeleteRuleChainTest.java | 148 ++++++++++ .../DeleteSeveralRuleChainsTest.java | 92 ++++++ .../MakeRuleChainRootTest.java | 75 +++++ .../ruleChainsSmoke/OpenRuleChainTest.java | 71 +++++ .../RuleChainEditMenuTest.java | 130 +++++++++ .../ruleChainsSmoke/SearchRuleChainTest.java | 52 ++++ .../tests/ruleChainsSmoke/SortByNameTest.java | 122 ++++++++ .../tests/ruleChainsSmoke/SortByTimeTest.java | 70 +++++ .../server/msa/ui/utils/Const.java | 21 ++ .../msa/ui/utils/DataProviderCredential.java | 62 ++++ .../server/msa/ui/utils/EntityPrototypes.java | 19 ++ .../src/test/resources/connectivity.xml | 0 .../src/test/resources/forImport.json | 20 ++ .../src/test/resources/forImport.txt | 0 .../src/test/resources/smokeTests.xml | 26 ++ .../src/test/resources/smokesCustomer.xml | 137 +++++++++ .../src/test/resources/smokesRuleChain.xml | 138 +++++++++ 49 files changed, 4034 insertions(+) create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java create mode 100644 msa/black-box-tests/src/test/resources/connectivity.xml create mode 100644 msa/black-box-tests/src/test/resources/forImport.json create mode 100644 msa/black-box-tests/src/test/resources/forImport.txt create mode 100644 msa/black-box-tests/src/test/resources/smokeTests.xml create mode 100644 msa/black-box-tests/src/test/resources/smokesCustomer.xml create mode 100644 msa/black-box-tests/src/test/resources/smokesRuleChain.xml diff --git a/msa/black-box-tests/pom.xml b/msa/black-box-tests/pom.xml index 49f4c959e9..c6952f05ba 100644 --- a/msa/black-box-tests/pom.xml +++ b/msa/black-box-tests/pom.xml @@ -160,7 +160,31 @@ snmp docker-info + + org.seleniumhq.selenium + selenium-java + 4.5.3 + + + io.github.bonigarcia + webdrivermanager + 5.3.0 + + + io.qameta.allure + allure-testng + 2.19.0 + + + + + com.google.guava + guava + 31.0.1-jre + + + diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java new file mode 100644 index 0000000000..8e8a15c5af --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java @@ -0,0 +1,129 @@ +package org.thingsboard.server.msa.ui.base; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.thingsboard.rest.client.RestClient; +import org.thingsboard.server.common.data.page.PageLink; +import org.thingsboard.server.msa.ui.utils.Const; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +abstract public class BasePage extends Base { + protected WebDriver driver; + protected WebDriverWait wait; + protected Actions actions; + protected RestClient client; + protected PageLink pageLink; + + public BasePage(WebDriver driver) { + this.driver = driver; + this.wait = new WebDriverWait(driver, Duration.ofMillis(5000)); + this.actions = new Actions(driver); + try { + client = new RestClient(Const.URL); + client.login(Const.TENANT_EMAIL, Const.TENANT_PASSWORD); + pageLink = new PageLink(10); + } catch (Exception e) { + log.info("Can't login"); + } + } + + @SneakyThrows + protected static void sleep(double second) { + Thread.sleep((long) (second * 1000L)); + } + + protected WebElement waitUntilVisibilityOfElementLocated(String locator) { + try { + return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); + } catch (WebDriverException e) { + log.error("No visibility element: " + locator); + return null; + } + } + + protected WebElement waitUntilElementToBeClickable(String locator) { + try { + return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); + } catch (WebDriverException e) { + log.error("No clickable element: " + locator); + return null; + } + } + + protected List waitUntilVisibilityOfElementsLocated(String locator) { + try { + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator))); + return driver.findElements(By.xpath(locator)); + } catch (WebDriverException e) { + log.error("No visibility elements: " + locator); + return null; + } + } + + protected List waitUntilElementsToBeClickable(String locator) { + try { + wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locator))); + return driver.findElements(By.xpath(locator)); + } catch (WebDriverException e) { + log.error("No clickable elements: " + locator); + return null; + } + } + + public void waitUntilUrlContainsText(String urlPath) { + try { + wait.until(ExpectedConditions.urlContains(urlPath)); + } catch (WebDriverException e) { + log.error("This URL path is missing"); + } + } + + protected void moveCursor(WebElement element) { + actions.moveToElement(element).perform(); + } + + protected void doubleClick(WebElement element) { + actions.doubleClick(element).build().perform(); + } + + public boolean elementIsNotPresent(String locator) { + try { + return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)))); + } catch (WebDriverException e) { + throw new AssertionError("Element is present"); + } + } + + public boolean elementsIsNotPresent(String locator) { + try { + return wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(locator)))); + } catch (WebDriverException e) { + throw new AssertionError("Elements is present"); + } + } + + public void waitUntilNumberOfTabToBe(int tabNumber) { + try { + wait.until(ExpectedConditions.numberOfWindowsToBe(tabNumber)); + } catch (WebDriverException e) { + log.error("No tabs with this number"); + } + } + + public void goToNextTab(int tabNumber) { + waitUntilNumberOfTabToBe(tabNumber); + ArrayList tabs = new ArrayList<>(driver.getWindowHandles()); + driver.switchTo().window(tabs.get(tabNumber - 1)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java new file mode 100644 index 0000000000..4e5d0d5ead --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java @@ -0,0 +1,74 @@ +package org.thingsboard.server.msa.ui.base; + +import io.github.bonigarcia.wdm.WebDriverManager; +import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; +import org.thingsboard.server.msa.TestListener; +import org.thingsboard.server.msa.ui.listeners.RetryTestListener; + +import java.time.Duration; + +@Slf4j +@Listeners({TestListener.class, RetryTestListener.class}) +abstract public class DiverBaseTest extends Base { + protected WebDriver driver; + + private final Dimension dimension = new Dimension(WIDTH, HEIGHT); + private static final int WIDTH = 1680; + private static final int HEIGHT = 1050; + private static final boolean HEADLESS = false; + + @BeforeMethod + public void openBrowser() { + log.info("*----------------------* Setup driver *----------------------*"); + if (HEADLESS == true) { + ChromeOptions options = new ChromeOptions(); + options.addArguments("--no-sandbox"); + options.addArguments("--disable-dev-shm-usage"); + options.addArguments("--headless"); + WebDriverManager.chromedriver().setup(); + driver = new ChromeDriver(options); + } else { + WebDriverManager.chromedriver().setup(); + driver = new ChromeDriver(); + } + driver.manage().window().setSize(dimension); + } + + @AfterMethod + public void closeBrowser() { + log.info("*----------------------* Teardown *----------------------*"); + driver.quit(); + } + + public void openUrl(String url) { + driver.get(url); + } + + public String getUrl() { + return driver.getCurrentUrl(); + } + + public WebDriver getDriver() { + return driver; + } + + protected boolean urlContains(String urlPath) { + WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(10000)); + try { + wait.until(ExpectedConditions.urlContains(urlPath)); + } catch (WebDriverException e) { + log.error("This URL path is missing"); + } + return driver.getCurrentUrl().contains(urlPath); + } +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java new file mode 100644 index 0000000000..30b157f13d --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java @@ -0,0 +1,20 @@ +package listeners; + +import org.testng.IRetryAnalyzer; +import org.testng.ITestResult; + +public class RetryAnalyzer implements IRetryAnalyzer { + + private int retryCount = 0; + private static final int MAX_RETRY_COUNT = 2; + + @Override + public boolean retry(ITestResult result) { + if (retryCount < MAX_RETRY_COUNT) { + System.out.printf("Retrying test %s for the %d time(s).%n", result.getName(), retryCount + 1); + retryCount++; + return true; + } + return false; + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java new file mode 100644 index 0000000000..6083781820 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java @@ -0,0 +1,18 @@ +package listeners; + +import org.testng.IAnnotationTransformer; +import org.testng.annotations.ITestAnnotation; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +public class RetryTestListener implements IAnnotationTransformer { + + @Override + public void transform(ITestAnnotation annotation, + Class testClass, + Constructor testConstructor, + Method testMethod) { + annotation.setRetryAnalyzer(RetryAnalyzer.class); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java new file mode 100644 index 0000000000..dec83f374b --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java @@ -0,0 +1,62 @@ +package listeners; + +import base.Base; +import base.TestInit; +import io.qameta.allure.Allure; +import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.WebDriver; +import org.testng.ITestContext; +import org.testng.ITestListener; +import org.testng.ITestResult; + +@Slf4j +public class TestListener extends Base implements ITestListener { + + WebDriver driver; + + public void onTestSuccess(ITestResult tr) { + String str = "Test " + tr.getMethod().getMethodName() + " success"; + log.info("*----------------------* " + str + " *----------------------*"); + Allure.getLifecycle().updateTestCase((t) -> { + t.setStatusDetails(t.getStatusDetails().setMessage(str)); + }); + driver = ((TestInit) tr.getInstance()).getDriver(); + captureScreen(driver, "success"); + } + + public void onTestFailure(ITestResult tr) { + String str = "Test " + tr.getMethod().getMethodName() + " failure"; + String str1 = "Failed because of - " + tr.getThrowable(); + log.info("*----------------------* " + str + " *----------------------*"); + log.info("*----------------------* " + str1 + " *----------------------*"); + Allure.getLifecycle().updateTestCase((t) -> { + t.setStatusDetails(t.getStatusDetails().setMessage(str)); + t.setStatusDetails(t.getStatusDetails().setMessage(str1)); + }); + driver = ((TestInit) tr.getInstance()).getDriver(); + captureScreen(driver, "failure"); + } + + public void onTestSkipped(ITestResult tr) { + String str = "Test " + tr.getMethod().getMethodName() + " skipped"; + String str1 = "Skipped because of - " + tr.getThrowable(); + log.info("*----------------------* " + str + " *----------------------*"); + log.info("*----------------------* " + str1 + " *----------------------*"); + Allure.getLifecycle().updateTestCase((t) -> { + t.setStatusDetails(t.getStatusDetails().setMessage(str)); + t.setStatusDetails(t.getStatusDetails().setMessage(str1)); + }); + driver = ((TestInit) tr.getInstance()).getDriver(); + captureScreen(driver, "skipped"); + } + + public void onStart(ITestContext testContext) { + String str = "Test " + testContext.getCurrentXmlTest().getName() + " start"; + log.info("*----------------------* " + str + " *----------------------*"); + } + + public void onFinish(ITestContext testContext) { + String str = "Test " + testContext.getCurrentXmlTest().getName() + " finish"; + log.info("*----------------------* " + str + " *----------------------*"); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java new file mode 100644 index 0000000000..dcb513ab71 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java @@ -0,0 +1,262 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class CustomerPageElementsAbstract extends OtherPageElementsHelperAbstract { + public CustomerPageElementsAbstract(WebDriver driver) { + super(driver); + } + + private static final String CUSTOMER = "//mat-row//span[contains(text(),'%s')]"; + private static final String EMAIL = ENTITY + "/../..//mat-cell[contains(@class,'email')]/span"; + private static final String COUNTRY = ENTITY + "/../..//mat-cell[contains(@class,'country')]/span"; + private static final String CITY = ENTITY + "/../..//mat-cell[contains(@class,'city')]/span"; + private static final String TITLES = "//mat-cell[contains(@class,'cdk-column-title')]/span"; + protected static final String EDIT_MENU_DASHBOARD_FIELD = "//input[@formcontrolname='dashboard']"; + private static final String EDIT_MENU_DASHBOARD = "//div[@class='cdk-overlay-pane']//span/span"; + private static final String MANAGE_CUSTOMERS_USERS_BTN = ENTITY + "/../..//mat-icon[contains(text(),' account_circle')]/../.."; + private static final String MANAGE_CUSTOMERS_ASSETS_BTN = ENTITY + "/../..//mat-icon[contains(text(),' domain')]/../.."; + private static final String MANAGE_CUSTOMERS_DEVICES_BTN = ENTITY + "/../..//mat-icon[contains(text(),' devices_other')]/../.."; + private static final String MANAGE_CUSTOMERS_DASHBOARDS_BTN = ENTITY + "/../..//mat-icon[contains(text(),' dashboard')]/../.."; + private static final String MANAGE_CUSTOMERS_EDGE_BTN = ENTITY + "/../..//mat-icon[contains(text(),' router')]/../.."; + private static final String ADD_USER_EMAIL = "//tb-add-user-dialog//input[@formcontrolname='email']"; + private static final String ACTIVATE_WINDOW_OK_BTN = "//span[contains(text(),'OK')]"; + private static final String USER_LOGIN_BTN = "//mat-icon[@data-mat-icon-name='login']"; + private static final String USERS_WIDGET = "//tb-widget"; + private static final String SELECT_COUNTRY_MENU = "//mat-form-field//mat-select[@formcontrolname='country']"; + private static final String COUNTRIES = "//span[@class='mat-option-text']"; + protected static final String INPUT_FIELD = "//input[@formcontrolname='%s']"; + protected static final String INPUT_FIELD_NAME_TITLE = "title"; + private static final String INPUT_FIELD_NAME_CITY = "city"; + private static final String INPUT_FIELD_NAME_STATE = "state"; + private static final String INPUT_FIELD_NAME_ZIP = "zip"; + private static final String INPUT_FIELD_NAME_ADDRESS = "address"; + private static final String INPUT_FIELD_NAME_ADDRESS2 = "address2"; + private static final String INPUT_FIELD_NAME_EMAIL = "email"; + private static final String INPUT_FIELD_NAME_NUMBER = "phoneNumber"; + private static final String INPUT_FIELD_NAME_ASSIGNED_LIST = "entity"; + private static final String ASSIGNED_BTN = "//button[@type='submit']"; + private static final String HIDE_HOME_DASHBOARD_TOOLBAR = "//mat-checkbox[@formcontrolname='homeDashboardHideToolbar']/label"; + private static final String FILTER_BTN = "//tb-filters-edit"; + private static final String TIME_BTN = "//tb-timewindow"; + private static final String CUSTOMER_ICON_HEADER = "//tb-breadcrumb//span[contains(text(),'Customer %s')]"; + private static final String CUSTOMER_USER_ICON_HEADER = "Users"; + private static final String CUSTOMER_ASSETS_ICON_HEADER = "Assets"; + private static final String CUSTOMER_DEVICES_ICON_HEADER = "Devices"; + private static final String CUSTOMER_DASHBOARD_ICON_HEADER = "Dashboards"; + private static final String CUSTOMER_EDGE_ICON_HEADER = "edge instances"; + private static final String CUSTOMER_USER_ICON_HEAD = "(//mat-drawer-content//span[contains(@class,'tb-entity-table')])[1]"; + private static final String MANAGE_BTN_VIEW = "//span[contains(text(),'%s')]"; + private static final String MANAGE_CUSTOMERS_USERS_BTN_VIEW = "Manage users"; + private static final String MANAGE_CUSTOMERS_ASSETS_BTN_VIEW = "Manage assets"; + private static final String MANAGE_CUSTOMERS_DEVICE_BTN_VIEW = "Manage devices"; + private static final String MANAGE_CUSTOMERS_DASHBOARD_BTN_VIEW = "Manage dashboards"; + private static final String MANAGE_CUSTOMERS_EDGE_BTN_VIEW = "Manage edges "; + + public WebElement titleFieldAddEntityView() { + return waitUntilElementToBeClickable(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_TITLE)); + } + + public WebElement titleFieldEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_TITLE)); + } + + public WebElement customer(String entityName) { + return waitUntilElementToBeClickable(String.format(CUSTOMER, entityName)); + } + + public WebElement email(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(EMAIL, entityName)); + } + + public WebElement country(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(COUNTRY, entityName)); + } + + public WebElement city(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(CITY, entityName)); + } + + public List entityTitles() { + return waitUntilVisibilityOfElementsLocated(TITLES); + } + + public WebElement editMenuDashboardField() { + return waitUntilVisibilityOfElementLocated(EDIT_MENU_DASHBOARD_FIELD); + } + + public WebElement editMenuDashboard() { + return waitUntilElementToBeClickable(EDIT_MENU_DASHBOARD); + } + + public WebElement phoneNumberEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_NUMBER)); + } + + public WebElement phoneNumberAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_NUMBER)); + } + + public WebElement manageCustomersUserBtn(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_CUSTOMERS_USERS_BTN, title)); + } + + public WebElement manageCustomersAssetsBtn(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_CUSTOMERS_ASSETS_BTN, title)); + } + + public WebElement manageCustomersDevicesBtn(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_CUSTOMERS_DEVICES_BTN, title)); + } + + public WebElement manageCustomersDashboardsBtn(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_CUSTOMERS_DASHBOARDS_BTN, title)); + } + + public WebElement manageCustomersEdgeBtn(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_CUSTOMERS_EDGE_BTN, title)); + } + + public WebElement addUserEmailField() { + return waitUntilElementToBeClickable(ADD_USER_EMAIL); + } + + public WebElement activateWindowOkBtn() { + return waitUntilElementToBeClickable(ACTIVATE_WINDOW_OK_BTN); + } + + public WebElement userLoginBtn() { + return waitUntilElementToBeClickable(USER_LOGIN_BTN); + } + + public WebElement usersWidget() { + return waitUntilVisibilityOfElementLocated(USERS_WIDGET); + } + + public WebElement countrySelectMenuEntityView() { + return waitUntilElementToBeClickable(SELECT_COUNTRY_MENU); + } + + public WebElement countrySelectMenuAddEntityView() { + return waitUntilElementToBeClickable(ADD_ENTITY_VIEW + SELECT_COUNTRY_MENU); + } + + public List countries() { + return waitUntilElementsToBeClickable(COUNTRIES); + } + + public WebElement cityEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_CITY)); + } + + public WebElement cityAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_CITY)); + } + + public WebElement stateEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_STATE)); + } + + public WebElement stateAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_STATE)); + } + + public WebElement zipEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_ZIP)); + } + + public WebElement zipAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_ZIP)); + } + + public WebElement addressEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_ADDRESS)); + } + + public WebElement addressAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_ADDRESS)); + } + + public WebElement address2EntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_ADDRESS2)); + } + + public WebElement address2AddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_ADDRESS2)); + } + + public WebElement emailEntityView() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_EMAIL)); + } + + public WebElement emailAddEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW + String.format(INPUT_FIELD, INPUT_FIELD_NAME_EMAIL)); + } + + public WebElement assignedField() { + return waitUntilVisibilityOfElementLocated(String.format(INPUT_FIELD, INPUT_FIELD_NAME_ASSIGNED_LIST)); + } + + public WebElement submitAssignedBtn() { + return waitUntilElementToBeClickable(ASSIGNED_BTN); + } + + public WebElement hideHomeDashboardToolbarCheckbox() { + return waitUntilElementToBeClickable(HIDE_HOME_DASHBOARD_TOOLBAR); + } + + public WebElement filterBtn() { + return waitUntilVisibilityOfElementLocated(FILTER_BTN); + } + + public WebElement timeBtn() { + return waitUntilVisibilityOfElementLocated(TIME_BTN); + } + + public WebElement customerUserIconHeader() { + return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_ICON_HEADER, CUSTOMER_USER_ICON_HEADER)); + } + + public WebElement customerAssetsIconHeader() { + return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_ICON_HEADER, CUSTOMER_ASSETS_ICON_HEADER)); + } + + public WebElement customerDevicesIconHeader() { + return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_ICON_HEADER, CUSTOMER_DEVICES_ICON_HEADER)); + } + + public WebElement customerDashboardIconHeader() { + return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_ICON_HEADER, CUSTOMER_DASHBOARD_ICON_HEADER)); + } + + public WebElement customerEdgeIconHeader() { + return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_ICON_HEADER, CUSTOMER_EDGE_ICON_HEADER)); + } + + public WebElement customerManageWindowIconHead() { + return waitUntilVisibilityOfElementLocated(CUSTOMER_USER_ICON_HEAD); + } + + public WebElement manageCustomersUserBtnView() { + return waitUntilElementToBeClickable(String.format(MANAGE_BTN_VIEW, MANAGE_CUSTOMERS_USERS_BTN_VIEW)); + } + + public WebElement manageCustomersAssetsBtnView() { + return waitUntilElementToBeClickable(String.format(MANAGE_BTN_VIEW, MANAGE_CUSTOMERS_ASSETS_BTN_VIEW)); + } + + public WebElement manageCustomersDeviceBtnView() { + return waitUntilElementToBeClickable(String.format(MANAGE_BTN_VIEW, MANAGE_CUSTOMERS_DEVICE_BTN_VIEW)); + } + + public WebElement manageCustomersDashboardsBtnView() { + return waitUntilElementToBeClickable(String.format(MANAGE_BTN_VIEW, MANAGE_CUSTOMERS_DASHBOARD_BTN_VIEW)); + } + + public WebElement manageCustomersEdgeBtnView() { + return waitUntilElementToBeClickable(String.format(MANAGE_BTN_VIEW, MANAGE_CUSTOMERS_EDGE_BTN_VIEW)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java new file mode 100644 index 0000000000..13d6a26077 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java @@ -0,0 +1,161 @@ +package org.thingsboard.server.msa.ui.pages; + +import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.thingsboard.server.common.data.Customer; +import org.thingsboard.server.common.data.page.PageData; + +import java.util.stream.Collectors; + +@Slf4j +public class CustomerPageHelperAbstract extends CustomerPageElementsAbstract { + public CustomerPageHelperAbstract(WebDriver driver) { + super(driver); + } + + private String customerName; + private String country; + private String dashboard; + private String dashboardFromView; + + private String customerEmail; + private String customerCountry; + private String customerCity; + + public void setCustomerName() { + this.customerName = entityTitles().get(0).getText(); + } + + public void setCustomerName(int number) { + this.customerName = entityTitles().get(number).getText(); + } + + public String getCustomerName() { + return customerName; + } + + public void setCountry() { + this.country = countries().get(0).getText(); + } + + public String getCountry() { + return country; + } + + public void setDashboard() { + this.dashboard = listOfEntity().get(0).getText(); + } + + public void setDashboardFromView() { + this.dashboardFromView = editMenuDashboardField().getAttribute("value"); + } + + public String getDashboard() { + return dashboard; + } + + public String getDashboardFromView() { + return dashboardFromView; + } + + public void setCustomerEmail(String title) { + this.customerEmail = email(title).getText(); + } + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerCountry(String title) { + this.customerCountry = country(title).getText(); + } + + public String getCustomerCountry() { + return customerCountry; + } + + public void setCustomerCity(String title) { + this.customerCity = city(title).getText(); + } + + public String getCustomerCity() { + return customerCity; + } + + public void createCustomer(String entityName) { + try { + PageData tenantCustomer; + tenantCustomer = client.getCustomers(pageLink); + Customer customer = new Customer(); + customer.setTitle(entityName); + client.saveCustomer(customer); + tenantCustomer.getData().add(customer); + } catch (Exception e) { + log.info("Can't create!"); + } + } + + public void deleteCustomer(String entityName) { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getCustomers(pageLink); + try { + client.deleteCustomer(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); + } catch (Exception e) { + client.deleteCustomer(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(1).getId()); + } + } catch (Exception e) { + log.info("Can't delete!"); + } + } + + public void changeTitleEditMenu(String newTitle) { + titleFieldEntityView().clear(); + wait.until(ExpectedConditions.textToBe(By.xpath(String.format(INPUT_FIELD, INPUT_FIELD_NAME_TITLE)), "")); + titleFieldEntityView().sendKeys(newTitle); + } + + public void chooseDashboard() { + editMenuDashboardField().click(); + sleep(0.5); + editMenuDashboard().click(); + sleep(0.5); + } + + public void createCustomersUser() { + plusBtn().click(); + addUserEmailField().sendKeys(getRandomNumber() + "@gmail.com"); + addBtnC().click(); + activateWindowOkBtn().click(); + } + + public void selectCountryEntityView() { + countrySelectMenuEntityView().click(); + setCountry(); + countries().get(0).click(); + } + + public void selectCountryAddEntityView() { + countrySelectMenuAddEntityView().click(); + setCountry(); + countries().get(0).click(); + } + + public void assignedDashboard() { + plusBtn().click(); + assignedField().click(); + setDashboard(); + listOfEntity().get(0).click(); + submitAssignedBtn().click(); + } + + public boolean customerIsNotPresent(String title) { + return elementsIsNotPresent(getEntity(title)); + } + + public void sortByNameDown() { + doubleClick(sortByTitleBtn()); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java new file mode 100644 index 0000000000..9e2595ed3c --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java @@ -0,0 +1,38 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class DashboardPageElementsAbstract extends OtherPageElementsHelperAbstract { + public DashboardPageElementsAbstract(WebDriver driver) { + super(driver); + } + + private static final String TITLES = "//mat-cell[contains(@class,'cdk-column-title')]/span"; + private static final String ASSIGNED_BTN = ENTITY + "/../..//mat-icon[contains(text(),' assignment_ind')]/../.."; + private static final String MANAGE_ASSIGNED_ENTITY_LIST_FIELD = "//input[@formcontrolname='entity']"; + private static final String MANAGE_ASSIGNED_ENTITY = "//mat-option//span[contains(text(),'%s')]"; + private static final String MANAGE_ASSIGNED_UPDATE_BTN = "//button[@type='submit']"; + + public List entityTitles() { + return waitUntilVisibilityOfElementsLocated(TITLES); + } + + public WebElement assignedBtn(String title) { + return waitUntilElementToBeClickable(String.format(ASSIGNED_BTN, title)); + } + + public WebElement manageAssignedEntityListField() { + return waitUntilElementToBeClickable(MANAGE_ASSIGNED_ENTITY_LIST_FIELD); + } + + public WebElement manageAssignedEntity(String title) { + return waitUntilElementToBeClickable(String.format(MANAGE_ASSIGNED_ENTITY, title)); + } + + public WebElement manageAssignedUpdateBtn() { + return waitUntilElementToBeClickable(MANAGE_ASSIGNED_UPDATE_BTN); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java new file mode 100644 index 0000000000..7bf8956542 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java @@ -0,0 +1,25 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class DashboardPageHelperAbstract extends DashboardPageElementsAbstract { + public DashboardPageHelperAbstract(WebDriver driver) { + super(driver); + } + + private String dashboardTitle; + + public void setDashboardTitle() { + this.dashboardTitle = entityTitles().get(0).getText(); + } + + public String getDashboardTitle() { + return dashboardTitle; + } + + public void assignedCustomer(String title) { + manageAssignedEntityListField().click(); + manageAssignedEntity(title).click(); + manageAssignedUpdateBtn().click(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java new file mode 100644 index 0000000000..54239e2971 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java @@ -0,0 +1,28 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.thingsboard.server.msa.ui.base.AbstractBasePage; + +public class LoginPageElementsAbstract extends AbstractBasePage { + public LoginPageElementsAbstract(WebDriver driver) { + super(driver); + } + + private static final String EMAIL_FIELD = "//input[@id='username-input']"; + private static final String PASSWORD_FIELD = "//input[@id='password-input']"; + private static final String SUBMIT_BTN = "//button[@type='submit']"; + + public WebElement emailField() { + return waitUntilElementToBeClickable(EMAIL_FIELD); + } + + public WebElement passwordField() { + return waitUntilElementToBeClickable(PASSWORD_FIELD); + } + + public WebElement submitBtn() { + return waitUntilElementToBeClickable(SUBMIT_BTN); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java new file mode 100644 index 0000000000..a39b507882 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java @@ -0,0 +1,16 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.thingsboard.server.msa.ui.utils.Const; + +public class LoginPageHelperAbstract extends LoginPageElementsAbstract { + public LoginPageHelperAbstract(WebDriver driver) { + super(driver); + } + + public void authorizationTenant() { + emailField().sendKeys(Const.TENANT_EMAIL); + passwordField().sendKeys(Const.TENANT_PASSWORD); + submitBtn().click(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java new file mode 100644 index 0000000000..521758ea41 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java @@ -0,0 +1,33 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.thingsboard.server.msa.ui.base.AbstractBasePage; + +public class OpenRuleChainPageElementsAbstract extends AbstractBasePage { + public OpenRuleChainPageElementsAbstract(WebDriver driver) { + super(driver); + } + + private static final String DONE_BTN = "//mat-icon[contains(text(),'done')]/../.."; + private static final String DONE_BTN_DISABLE = "//mat-icon[contains(text(),'done')]/../parent::button[@disabled='true']"; + private static final String INPUT_NODE = "//div[@class='tb-rule-node tb-input-type']"; + private static final String HEAD_RULE_CHAIN_NAME = "//div[@class='tb-breadcrumb']/span[2]"; + + public WebElement inputNode() { + return waitUntilVisibilityOfElementLocated(INPUT_NODE); + } + + public WebElement headRuleChainName() { + return waitUntilVisibilityOfElementLocated(HEAD_RULE_CHAIN_NAME); + } + + public String getDoneBtnDisable() { + return DONE_BTN_DISABLE; + } + + public WebElement doneBtn() { + return waitUntilElementToBeClickable(DONE_BTN); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java new file mode 100644 index 0000000000..ccaaedab28 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java @@ -0,0 +1,23 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; + +public class OpenRuleChainPageHelperAbstract extends OpenRuleChainPageElementsAbstract { + public OpenRuleChainPageHelperAbstract(WebDriver driver) { + super(driver); + } + + private String headName; + + public void setHeadName() { + this.headName = headRuleChainName().getText().split(" ")[1]; + } + + public String getHeadName() { + return headName; + } + + public void waitUntilDoneBtnDisable() { + waitUntilVisibilityOfElementLocated(getDoneBtnDisable()); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java new file mode 100644 index 0000000000..bf4be2dae2 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java @@ -0,0 +1,228 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.thingsboard.server.msa.ui.base.AbstractBasePage; + +import java.util.List; + +public class OtherPageElementsAbstract extends AbstractBasePage { + public OtherPageElementsAbstract(WebDriver driver) { + super(driver); + } + + protected static final String ENTITY = "//mat-row//span[contains(text(),'%s')]"; + protected static final String DELETE_BTN = ENTITY + "/../..//mat-icon[contains(text(),' delete')]/../.."; + private static final String ENTITY_COUNT = "//div[@class='mat-paginator-range-label']"; + private static final String WARNING_DELETE_POPUP_YES = "//tb-confirm-dialog//button[2]"; + private static final String WARNING_DELETE_POPUP_TITLE = "//tb-confirm-dialog/h2"; + private static final String REFRESH_BTN = "//mat-icon[contains(text(),'refresh')]/.."; + private static final String HELP_BTN = "//mat-icon[contains(text(),'help')]/.."; + private static final String CHECKBOX = "//mat-row//span[contains(text(),'%s')]/../..//mat-checkbox"; + private static final String CHECKBOXES = "//tbody//mat-checkbox"; + private static final String DELETE_SELECTED_BTN = "//span[contains(text(),'selected')]//..//mat-icon/../.."; + private static final String DELETE_BTNS = "//mat-icon[contains(text(),' delete')]/../.."; + private static final String MARKS_CHECKBOX = "//mat-row[contains (@class,'mat-selected')]//mat-checkbox[contains(@class, 'checked')]"; + private static final String SELECT_ALL_CHECKBOX = "//thead//mat-checkbox"; + private static final String ALL_ENTITY = "//mat-row[@class='mat-row cdk-row mat-row-select ng-star-inserted']"; + private static final String EDIT_PENCIL_BTN = "//mat-icon[contains(text(),'edit')]/ancestor::button"; + private static final String NAME_FIELD_EDIT_VIEW = "//input[@formcontrolname='name']"; + private static final String HEADER_NAME_VIEW = "//header//div[@class='tb-details-title']/span"; + private static final String DONE_BTN_EDIT_VIEW = "//mat-icon[contains(text(),'done')]/ancestor::button"; + private static final String DESCRIPTION_ENTITY_VIEW = "//textarea"; + private static final String DESCRIPTION_ADD_ENTITY_VIEW = "//tb-add-entity-dialog//textarea"; + private static final String DEBUG_CHECKBOX_EDIT = "//mat-checkbox[@formcontrolname='debugMode']"; + private static final String DEBUG_CHECKBOX_VIEW = "//mat-checkbox[@formcontrolname='debugMode']//input"; + private static final String CLOSE_ENTITY_VIEW_BTN = "//header//mat-icon[contains(text(),'close')]/../.."; + private static final String SEARCH_BTN = "//mat-toolbar//mat-icon[contains(text(),'search')]/.." + + "/parent::button[@class='mat-focus-indicator mat-tooltip-trigger mat-icon-button mat-button-base ng-star-inserted']"; + private static final String SORT_BY_NAME_BTN = "//div[contains(text(),'Name')]"; + private static final String SORT_BY_TITLE_BTN = "//div[contains(text(),'Title')]"; + private static final String SORT_BY_TIME_BTN = "//div[contains(text(),'Created time')]/.."; + private static final String CREATED_TIME = "//tbody[@role='rowgroup']//mat-cell[2]/span"; + private static final String PLUS_BTN = "//mat-icon[contains(text(),'add')]/../parent::button"; + private static final String CREATE_VIEW_ADD_BTN = "//span[contains(text(),'Add')]/.."; + private static final String WARNING_MESSAGE = "//tb-snack-bar-component/div/div"; + private static final String ERROR_MESSAGE = "//mat-error"; + private static final String ENTITY_VIEW_TITLE = "//div[@class='tb-details-title']//span"; + private static final String LIST_OF_ENTITY = "//div[@role='listbox']/mat-option"; + protected static final String ADD_ENTITY_VIEW = "//tb-add-entity-dialog"; + protected static final String STATE_CONTROLLER = "//tb-entity-state-controller"; + private static final String SEARCH_FIELD = "//input[contains (@data-placeholder,'Search')]"; + + public String getEntity(String entityName) { + return String.format(ENTITY, entityName); + } + + public String getWarningMessage() { + return WARNING_MESSAGE; + } + + public String getDeleteBtns() { + return DELETE_BTNS; + } + + public String getCheckbox(String entityName) { + return String.format(CHECKBOX, entityName); + } + + public String getCheckboxes() { + return String.format(CHECKBOXES); + } + + public WebElement warningPopUpYesBtn() { + return waitUntilElementToBeClickable(WARNING_DELETE_POPUP_YES); + } + + public WebElement warningPopUpTitle() { + return waitUntilElementToBeClickable(WARNING_DELETE_POPUP_TITLE); + } + + public WebElement entityCount() { + return waitUntilVisibilityOfElementLocated(ENTITY_COUNT); + } + + public WebElement refreshBtn() { + return waitUntilElementToBeClickable(REFRESH_BTN); + } + + public WebElement helpBtn() { + return waitUntilElementToBeClickable(HELP_BTN); + } + + public WebElement checkBox(String entityName) { + return waitUntilElementToBeClickable(String.format(CHECKBOX, entityName)); + } + + public WebElement deleteSelectedBtn() { + return waitUntilElementToBeClickable(DELETE_SELECTED_BTN); + } + + public WebElement selectAllCheckBox() { + return waitUntilElementToBeClickable(SELECT_ALL_CHECKBOX); + } + + public WebElement editPencilBtn() { + return waitUntilElementToBeClickable(EDIT_PENCIL_BTN); + } + + public WebElement nameFieldEditMenu() { + return waitUntilElementToBeClickable(NAME_FIELD_EDIT_VIEW); + } + + public WebElement headerNameView() { + return waitUntilVisibilityOfElementLocated(HEADER_NAME_VIEW); + } + + public WebElement doneBtnEditView() { + return waitUntilElementToBeClickable(DONE_BTN_EDIT_VIEW); + } + + public WebElement descriptionEntityView() { + return waitUntilVisibilityOfElementLocated(DESCRIPTION_ENTITY_VIEW); + } + + public WebElement descriptionAddEntityView() { + return waitUntilVisibilityOfElementLocated(DESCRIPTION_ADD_ENTITY_VIEW); + } + + public WebElement debugCheckboxEdit() { + return waitUntilElementToBeClickable(DEBUG_CHECKBOX_EDIT); + } + + public WebElement debugCheckboxView() { + return waitUntilVisibilityOfElementLocated(DEBUG_CHECKBOX_VIEW); + } + + public WebElement closeEntityViewBtn() { + return waitUntilElementToBeClickable(CLOSE_ENTITY_VIEW_BTN); + } + + public WebElement searchBtn() { + return waitUntilElementToBeClickable(SEARCH_BTN); + } + + public List deleteBtns() { + return waitUntilVisibilityOfElementsLocated(DELETE_BTNS); + } + + public List checkBoxes() { + return waitUntilElementsToBeClickable(CHECKBOXES); + } + + public List markCheckbox() { + return waitUntilVisibilityOfElementsLocated(MARKS_CHECKBOX); + } + + public List allEntity() { + return waitUntilVisibilityOfElementsLocated(ALL_ENTITY); + } + + public WebElement doneBtnEditViewVisible() { + return waitUntilVisibilityOfElementLocated(DONE_BTN_EDIT_VIEW); + } + + public WebElement sortByNameBtn() { + return waitUntilElementToBeClickable(SORT_BY_NAME_BTN); + } + + public WebElement sortByTitleBtn() { + return waitUntilElementToBeClickable(SORT_BY_TITLE_BTN); + } + + public WebElement sortByTimeBtn() { + return waitUntilElementToBeClickable(SORT_BY_TIME_BTN); + } + + public List createdTime() { + return waitUntilVisibilityOfElementsLocated(CREATED_TIME); + } + + public WebElement plusBtn() { + return waitUntilElementToBeClickable(PLUS_BTN); + } + + public WebElement addBtnC() { + return waitUntilElementToBeClickable(CREATE_VIEW_ADD_BTN); + } + + public WebElement addBtnV() { + return waitUntilVisibilityOfElementLocated(CREATE_VIEW_ADD_BTN); + } + + public WebElement warningMessage() { + return waitUntilVisibilityOfElementLocated(WARNING_MESSAGE); + } + + public WebElement deleteBtn(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(DELETE_BTN, entityName)); + } + + public WebElement entity(String entityName) { + return waitUntilElementToBeClickable(String.format(ENTITY, entityName)); + } + + public WebElement errorMessage() { + return waitUntilVisibilityOfElementLocated(ERROR_MESSAGE); + } + + public WebElement entityViewTitle() { + return waitUntilVisibilityOfElementLocated(ENTITY_VIEW_TITLE); + } + + public List listOfEntity() { + return waitUntilElementsToBeClickable(LIST_OF_ENTITY); + } + + public WebElement addEntityView() { + return waitUntilVisibilityOfElementLocated(ADD_ENTITY_VIEW); + } + + public WebElement stateController() { + return waitUntilVisibilityOfElementLocated(STATE_CONTROLLER); + } + + public WebElement searchField() { + return waitUntilElementToBeClickable(SEARCH_FIELD); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java new file mode 100644 index 0000000000..dc4a41e9b9 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java @@ -0,0 +1,98 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; + +public class OtherPageElementsHelperAbstract extends OtherPageElementsAbstract { + public OtherPageElementsHelperAbstract(WebDriver driver) { + super(driver); + } + + private String headerName; + + public void setHeaderName() { + this.headerName = headerNameView().getText(); + } + + public String getHeaderName() { + return headerName; + } + + public boolean entityIsNotPresent(String entityName) { + return elementIsNotPresent(getEntity(entityName)); + } + + public void goToHelpPage() { + helpBtn().click(); + goToNextTab(2); + } + + public void clickOnCheckBoxes(int count) { + for (int i = 0; i < count; i++) { + checkBoxes().get(i).click(); + } + } + + public void changeNameEditMenu(String newName) { + nameFieldEditMenu().sendKeys(Keys.CONTROL + "a" + Keys.BACK_SPACE); + nameFieldEditMenu().sendKeys(newName); + } + + public void changeDescription(String newDescription) { + descriptionEntityView().sendKeys(Keys.CONTROL + "a" + Keys.BACK_SPACE); + descriptionEntityView().sendKeys(newDescription); + } + + public String deleteRuleChainTrash(String entityName) { + String s = ""; + if (deleteBtn(entityName) != null) { + deleteBtn(entityName).click(); + warningPopUpYesBtn().click(); + return entityName; + } else { + for (int i = 0; i < deleteBtns().size(); i++) { + if (deleteBtns().get(i).isEnabled()) { + deleteBtns().get(i).click(); + warningPopUpYesBtn().click(); + if (elementIsNotPresent(getWarningMessage())) { + s = driver.findElements(By.xpath(getDeleteBtns() + + "/../../../mat-cell/following-sibling::mat-cell/following-sibling::mat-cell[contains(@class,'cdk-column-name')]/span")).get(i).getText(); + break; + } + } + } + return s; + } + } + + public String deleteSelected(String entityName) { + String s = ""; + if (deleteBtn(entityName) != null) { + checkBox(entityName).click(); + deleteSelectedBtn().click(); + warningPopUpYesBtn().click(); + return entityName; + } else { + for (int i = 0; i < checkBoxes().size(); i++) { + if (checkBoxes().get(i).isDisplayed()) { + s = driver.findElements(By.xpath(getCheckboxes() + "/../../mat-cell/following-sibling::mat-cell/following-sibling::mat-cell[contains(@class,'cdk-column-name')]/span")).get(i).getText(); + checkBox(s).click(); + deleteSelectedBtn().click(); + warningPopUpYesBtn().click(); + if (elementIsNotPresent(getWarningMessage())) { + break; + } + } + } + return s; + } + } + + public void searchEntity(String namePath) { + searchBtn().click(); + searchField().sendKeys(namePath); + sleep(0.5); + } +} + diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java new file mode 100644 index 0000000000..4a378bb1c3 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java @@ -0,0 +1,113 @@ +package org.thingsboard.server.msa.ui.pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class RuleChainsPageElementsAbstract extends OtherPageElementsHelperAbstract { + public RuleChainsPageElementsAbstract(WebDriver driver) { + super(driver); + } + + private static final String MAKE_ROOT_BTN = ENTITY + "/../..//mat-icon[contains(text(),' flag')]/../.."; + private static final String ROOT = ENTITY + "/../..//mat-icon[text() = 'check_box']"; + private static final String ROOT_DISABLE = ENTITY + "/../..//mat-icon[text() = 'check_box_outline_blank']"; + private static final String CREATED_TIME = ENTITY + "/../..//mat-cell/span[contains(text(),'%s')]"; + private static final String CREATE_RULE_CHAIN_BTN = "//span[contains(text(),'Create new rule chain')]"; + private static final String CREATE_RULE_CHAIN_NAME_FIELD = "//form[@class='ng-untouched ng-pristine ng-invalid']//input[@formcontrolname='name']"; + private static final String RULE_CHAINS_NAMES_WITHOUT_ROOT = "//mat-icon[contains(text(),'check_box_outline_blank')]/../../../mat-cell[contains(@class,'name')]/span"; + private static final String DELETE_RULE_CHAIN_FROM_VIEW_BTN = "//span[contains(text(),' Delete')]"; + private static final String IMPORT_RULE_CHAIN_BTN = "//span[contains(text(),'Import rule chain')]"; + private static final String BROWSE_FILE = "//input[@class='file-input']"; + private static final String IMPORT_BROWSE_FILE = "//mat-dialog-container//span[contains(text(),'Import')]/.."; + private static final String IMPORTING_FILE = "//div[contains(text(),'%s')]"; + private static final String CLEAR_IMPORT_FILE_BTN = "//div[@class='tb-file-clear-container']//button"; + private static final String OPEN_RULE_CHAIN = ENTITY + "/../..//mat-icon[contains(text(),' settings_ethernet')]"; + private static final String OPEN_RULE_CHAIN_FROM_VIEW = "//span[contains(text(),'Open rule chain')]"; + private static final String MAKE_ROOT_FROM_VIEW = "(//span[contains(text(),' Make rule chain root ')]/..)[1]"; + private static final String ROOT_ACTIVE_CHECKBOXES = "//mat-icon[text() = 'check_box']"; + private static final String ALL_NAMES = "//mat-icon[contains(text(),'check')]/../../../mat-cell[contains(@class,'name')]/span"; + + public String getDeleteRuleChainFromViewBtn() { + return DELETE_RULE_CHAIN_FROM_VIEW_BTN; + } + + public WebElement makeRootBtn(String entityName) { + return waitUntilElementToBeClickable(String.format(MAKE_ROOT_BTN, entityName)); + } + + public List rootCheckBoxesEnable() { + return waitUntilVisibilityOfElementsLocated(ROOT_ACTIVE_CHECKBOXES); + } + + public WebElement rootCheckBoxEnable(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(ROOT, entityName)); + } + + public WebElement rootCheckBoxDisable(String entityName) { + return waitUntilVisibilityOfElementLocated(String.format(ROOT_DISABLE, entityName)); + } + + public WebElement createRuleChainBtn() { + return waitUntilElementToBeClickable(CREATE_RULE_CHAIN_BTN); + } + + public WebElement importRuleChainBtn() { + return waitUntilElementToBeClickable(IMPORT_RULE_CHAIN_BTN); + } + + public WebElement nameField() { + return waitUntilElementToBeClickable(CREATE_RULE_CHAIN_NAME_FIELD); + } + + public List notRootRuleChainsNames() { + return waitUntilVisibilityOfElementsLocated(RULE_CHAINS_NAMES_WITHOUT_ROOT); + } + + public WebElement deleteBtnFromView() { + return waitUntilElementToBeClickable(DELETE_RULE_CHAIN_FROM_VIEW_BTN); + } + + public WebElement browseFile() { + waitUntilElementToBeClickable(BROWSE_FILE + "/preceding-sibling::button"); + return driver.findElement(By.xpath(BROWSE_FILE)); + } + + public WebElement importBrowseFileBtn() { + return waitUntilElementToBeClickable(IMPORT_BROWSE_FILE); + } + + public WebElement importingFile(String fileName) { + return waitUntilVisibilityOfElementLocated(String.format(IMPORTING_FILE, fileName)); + } + + public WebElement clearImportFileBtn() { + return waitUntilElementToBeClickable(CLEAR_IMPORT_FILE_BTN); + } + + public WebElement openRuleChainFromViewBtn() { + return waitUntilElementToBeClickable(OPEN_RULE_CHAIN_FROM_VIEW); + } + + public WebElement openRuleChainBtn(String name) { + return waitUntilElementToBeClickable(String.format(OPEN_RULE_CHAIN, name)); + } + + public List entities(String name) { + return waitUntilVisibilityOfElementsLocated(String.format(ENTITY, name)); + } + + public WebElement makeRootFromViewBtn() { + return waitUntilElementToBeClickable(MAKE_ROOT_FROM_VIEW); + } + + public List allNames() { + return waitUntilVisibilityOfElementsLocated(ALL_NAMES); + } + + public WebElement createdTimeEntity(String name, String time) { + return waitUntilElementToBeClickable(String.format(CREATED_TIME, name, time)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java new file mode 100644 index 0000000000..9d23660b11 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java @@ -0,0 +1,180 @@ +package org.thingsboard.server.msa.ui.pages; + +import lombok.extern.slf4j.Slf4j; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.testng.Assert; +import org.thingsboard.server.common.data.page.PageData; +import org.thingsboard.server.common.data.rule.RuleChain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; +import java.util.stream.Collectors; + +@Slf4j +public class RuleChainsPageHelperAbstract extends RuleChainsPageElementsAbstract { + public RuleChainsPageHelperAbstract(WebDriver driver) { + super(driver); + } + + public void openCreateRuleChainView() { + plusBtn().click(); + createRuleChainBtn().click(); + } + + public void openImportRuleChainView() { + plusBtn().click(); + importRuleChainBtn().click(); + } + + private int getRandomNumberFromRuleChainsCount() { + Random random = new Random(); + return random.nextInt(notRootRuleChainsNames().size()); + } + + private String ruleChainName; + + public void setRuleChainNameWithoutRoot() { + this.ruleChainName = notRootRuleChainsNames().get(getRandomNumberFromRuleChainsCount()).getText(); + } + + public void setRuleChainNameWithoutRoot(int number) { + this.ruleChainName = notRootRuleChainsNames().get(number).getText(); + } + + public void setRuleChainName(int number) { + this.ruleChainName = allNames().get(number).getText(); + } + + public String getRuleChainName() { + return this.ruleChainName; + } + + public String getRuleChainId(String entityName) { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + return String.valueOf(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); + } + + public void deleteRuleChain(String entityName) { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + try { + client.deleteRuleChain(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); + } catch (Exception e) { + client.deleteRuleChain(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(1).getId()); + } + } catch (Exception e) { + log.info("Can't delete!"); + } + } + + public void deleteAllRuleChain(String entityName) { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).forEach(x -> client.deleteRuleChain(x.getId())); + } catch (Exception e) { + log.info("Can't delete!"); + } + } + + public void createRuleChain(String entityName) { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + RuleChain ruleChain = new RuleChain(); + ruleChain.setName(entityName); + client.saveRuleChain(ruleChain); + tenantRuleChains.getData().add(ruleChain); + } catch (Exception e) { + log.info("Can't create!"); + } + } + + public void makeRoot() { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + tenantRuleChains.getData().stream().filter(s -> s.getName().equals("Root Rule Chain")).collect(Collectors.toList()).forEach(x -> client.setRootRuleChain(x.getId())); + } catch (Exception e) { + log.info("Can't make root!"); + } + } + + public void createRuleChains(String entityName, int count) { + try { + PageData tenantRuleChains; + tenantRuleChains = client.getRuleChains(pageLink); + RuleChain ruleChain = new RuleChain(); + for (int i = 0; i < count; i++) { + ruleChain.setName(entityName); + client.saveRuleChain(ruleChain); + tenantRuleChains.getData().add(ruleChain); + } + } catch (Exception e) { + log.info("Can't create!"); + } + } + + public String deleteRuleChainFromView(String ruleChainName) { + String s = ""; + if (deleteBtnFromView() != null) { + deleteBtnFromView().click(); + warningPopUpYesBtn().click(); + if (elementIsNotPresent(getWarningMessage())) { + return getEntity(ruleChainName); + } + } else { + for (int i = 0; i < notRootRuleChainsNames().size(); i++) { + notRootRuleChainsNames().get(i).click(); + if (deleteBtnFromView() != null) { + deleteBtnFromView().click(); + warningPopUpYesBtn().click(); + if (elementIsNotPresent(getWarningMessage())) { + s = notRootRuleChainsNames().get(i).getText(); + break; + } + } + } + } + return s; + } + + public void assertCheckBoxIsNotDisplayed(String entityName) { + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//mat-checkbox)[2]"))); + Assert.assertFalse(driver.findElement(By.xpath(getCheckbox(entityName))).isDisplayed()); + } + + public void assertDeleteBtnInRootRuleChainIsNotDisplayed() { + Assert.assertFalse(driver.findElement(By.xpath(getDeleteRuleChainFromViewBtn())).isDisplayed()); + } + + public boolean ruleChainsIsNotPresent(String ruleChainName) { + return elementsIsNotPresent(getEntity(ruleChainName)); + } + + public void doubleClickOnRuleChain(String ruleChainName) { + doubleClick(entity(ruleChainName)); + } + + public void sortByNameDown() { + doubleClick(sortByNameBtn()); + } + + ArrayList sort; + + public void setSort() { + ArrayList createdTime = new ArrayList<>(); + createdTime().forEach(x -> createdTime.add(x.getText())); + Collections.sort(createdTime); + sort = createdTime; + } + + public ArrayList getSort() { + return sort; + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java new file mode 100644 index 0000000000..1e1484be7b --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java @@ -0,0 +1,27 @@ +package pages; + +import base.BasePage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class SideBarMenuViewElements extends BasePage { + public SideBarMenuViewElements(WebDriver driver) { + super(driver); + } + + private static final String RULE_CHAINS_BTN = "//mat-toolbar//a[@href='/ruleChains']"; + private static final String CUSTOMER_BTN = "//mat-toolbar//a[@href='/customers']"; + private static final String DASHBOARD_BTN = "//mat-toolbar//a[@href='/dashboards']"; + + public WebElement ruleChainsBtn() { + return waitUntilElementToBeClickable(RULE_CHAINS_BTN); + } + + public WebElement customerBtn() { + return waitUntilElementToBeClickable(CUSTOMER_BTN); + } + + public WebElement dashboardBtn() { + return waitUntilElementToBeClickable(DASHBOARD_BTN); + } +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java new file mode 100644 index 0000000000..c59b950862 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java @@ -0,0 +1,164 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private String customerName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (customerName != null) { + customerPage.deleteCustomer(customerName); + customerName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description("Can click on Add after specifying the name (text/numbers /special characters)") + public void createCustomer() { + String customerName = ENTITY_NAME; + + sideBarMenuView.customerBtn().click(); + customerPage.plusBtn().click(); + customerPage.titleFieldAddEntityView().sendKeys(customerName); + customerPage.addBtnC().click(); + customerPage.refreshBtn().click(); + this.customerName = customerName; + + Assert.assertNotNull(customerPage.customer(customerName)); + Assert.assertTrue(customerPage.customer(customerName).isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + public void createCustomerWithFullInformation() { + String customerName = ENTITY_NAME; + String text = "Text"; + String email = "email@mail.com"; + String number = "2015550123"; + + sideBarMenuView.customerBtn().click(); + customerPage.plusBtn().click(); + customerPage.titleFieldAddEntityView().sendKeys(customerName); + customerPage.selectCountryAddEntityView(); + customerPage.descriptionAddEntityView().sendKeys(text); + customerPage.cityAddEntityView().sendKeys(text); + customerPage.stateAddEntityView().sendKeys(text); + customerPage.zipAddEntityView().sendKeys(text); + customerPage.addressAddEntityView().sendKeys(text); + customerPage.address2AddEntityView().sendKeys(text); + customerPage.phoneNumberAddEntityView().sendKeys(number); + customerPage.emailAddEntityView().sendKeys(email); + customerPage.addBtnC().click(); + customerPage.setCustomerEmail(customerName); + customerPage.setCustomerCountry(customerName); + customerPage.setCustomerCity(customerName); + customerPage.entity(customerName).click(); + this.customerName = customerName; + + Assert.assertNotNull(customerPage.customer(customerName)); + Assert.assertEquals(customerPage.entityViewTitle().getText(), customerName); + Assert.assertEquals(customerPage.titleFieldEntityView().getAttribute("value"), customerName); + Assert.assertEquals(customerPage.countrySelectMenuEntityView().getText(), customerPage.getCountry()); + Assert.assertEquals(customerPage.descriptionEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.cityEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.stateEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.zipEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.addressEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.address2EntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.phoneNumberEntityView().getAttribute("value"), "+1" + number); + Assert.assertEquals(customerPage.emailEntityView().getAttribute("value"), email); + Assert.assertEquals(customerPage.getCustomerEmail(), email); + Assert.assertEquals(customerPage.getCustomerCountry(), customerPage.getCountry()); + Assert.assertEquals(customerPage.getCustomerCity(), text); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t add customer without the name (empty field or just space)") + public void createCustomerWithoutName() { + sideBarMenuView.customerBtn().click(); + customerPage.plusBtn().click(); + + Assert.assertFalse(customerPage.addBtnV().isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description() + public void createCustomerWithOnlySpace() { + sideBarMenuView.customerBtn().click(); + customerPage.plusBtn().click(); + customerPage.titleFieldAddEntityView().sendKeys(" "); + customerPage.addBtnC().click(); + + Assert.assertNotNull(customerPage.warningMessage()); + Assert.assertTrue(customerPage.warningMessage().isDisplayed()); + Assert.assertEquals(customerPage.warningMessage().getText(), EMPTY_CUSTOMER_MESSAGE); + Assert.assertNotNull(customerPage.addEntityView()); + Assert.assertTrue(customerPage.addEntityView().isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can't create a customer with the same name") + public void createCustomerSameName() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + String customerName = customerPage.getCustomerName(); + customerPage.plusBtn().click(); + customerPage.titleFieldAddEntityView().sendKeys(customerName); + customerPage.addBtnC().click(); + + Assert.assertNotNull(customerPage.warningMessage()); + Assert.assertTrue(customerPage.warningMessage().isDisplayed()); + Assert.assertEquals(customerPage.warningMessage().getText(), SAME_NAME_WARNING_CUSTOMER_MESSAGE); + Assert.assertNotNull(customerPage.addEntityView()); + Assert.assertTrue(customerPage.addEntityView().isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can click on Add after specifying the name (text/numbers /special characters)") + public void createCustomerWithoutRefresh() { + String customerName = ENTITY_NAME; + + sideBarMenuView.customerBtn().click(); + customerPage.plusBtn().click(); + customerPage.titleFieldAddEntityView().sendKeys(customerName); + customerPage.addBtnC().click(); + this.customerName = customerName; + + Assert.assertNotNull(customerPage.customer(customerName)); + Assert.assertTrue(customerPage.customer(customerName).isDisplayed()); + } + + @Test(priority = 40, groups = "smoke") + @Description("Question mark icon leads to rule chain documentation (PE)") + public void documentation() { + String urlPath = "docs/user-guide/ui/customers/"; + + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.customer(customerPage.getCustomerName()).click(); + customerPage.goToHelpPage(); + + Assert.assertTrue(urlContains(urlPath)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java new file mode 100644 index 0000000000..36297cbf3a --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java @@ -0,0 +1,270 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.DashboardPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.DataProviderCredential; + +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomNumber; +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private DashboardPageHelperAbstract dashboardPage; + private String customerName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + dashboardPage = new DashboardPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (customerName != null) { + customerPage.deleteCustomer(customerName); + customerName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description("Can click by pencil icon and edit the title (change the title) and save the changes. All changes have been applied") + public void changeTitle() { + customerPage.createCustomer(ENTITY_NAME); + String title = "Changed" + getRandomNumber(); + + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.setHeaderName(); + String titleBefore = customerPage.getHeaderName(); + customerPage.editPencilBtn().click(); + customerPage.changeTitleEditMenu(title); + customerPage.doneBtnEditView().click(); + customerPage.setHeaderName(); + String titleAfter = customerPage.getHeaderName(); + customerName = title; + + Assert.assertNotEquals(titleBefore, titleAfter); + Assert.assertEquals(titleAfter, title); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t delete the title and save changes") + public void deleteTitle() { + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.titleFieldEntityView().clear(); + + Assert.assertFalse(customerPage.doneBtnEditViewVisible().isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t save just a space in the title") + public void saveOnlyWithSpace() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.changeTitleEditMenu(" "); + customerPage.doneBtnEditView().click(); + customerPage.setHeaderName(); + + Assert.assertNotNull(customerPage.warningMessage()); + Assert.assertTrue(customerPage.warningMessage().isDisplayed()); + Assert.assertEquals(customerPage.warningMessage().getText(), EMPTY_CUSTOMER_MESSAGE); + Assert.assertEquals(customerPage.getCustomerName(), customerPage.getHeaderName()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can write/change/delete the descriptionEntityView and save the changes. All changes have been applied") + public void editDescription() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + String description = "Description"; + + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.descriptionEntityView().sendKeys(description); + customerPage.doneBtnEditView().click(); + String description1 = customerPage.descriptionEntityView().getAttribute("value"); + customerPage.editPencilBtn().click(); + customerPage.descriptionEntityView().sendKeys(description); + customerPage.doneBtnEditView().click(); + String description2 = customerPage.descriptionEntityView().getAttribute("value"); + customerPage.editPencilBtn().click(); + customerPage.changeDescription(""); + customerPage.doneBtnEditView().click(); + customerName = title; + + Assert.assertEquals(description, description1); + Assert.assertEquals(description + description, description2); + Assert.assertTrue(customerPage.descriptionEntityView().getAttribute("value").isEmpty()); + } + + @Test(priority = 20, groups = "smoke") + @Description + public void assignedDashboardFromDashboard() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + + sideBarMenuView.dashboardBtn().click(); + dashboardPage.setDashboardTitle(); + dashboardPage.assignedBtn(dashboardPage.getDashboardTitle()).click(); + dashboardPage.assignedCustomer(title); + sideBarMenuView.customerBtn().click(); + customerPage.entity(title).click(); + customerPage.editPencilBtn().click(); + customerPage.chooseDashboard(); + customerPage.doneBtnEditView().click(); + customerPage.setDashboardFromView(); + customerPage.closeEntityViewBtn().click(); + customerPage.manageCustomersUserBtn(title).click(); + customerPage.createCustomersUser(); + customerPage.userLoginBtn().click(); + customerName = title; + + Assert.assertNotNull(customerPage.usersWidget()); + Assert.assertTrue(customerPage.usersWidget().isDisplayed()); + Assert.assertEquals(customerPage.getDashboardFromView(), dashboardPage.getDashboardTitle()); + } + + @Test(priority = 20, groups = "smoke") + @Description + public void assignedDashboard() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + + sideBarMenuView.customerBtn().click(); + customerPage.manageCustomersDashboardsBtn(title).click(); + customerPage.assignedDashboard(); + sideBarMenuView.customerBtn().click(); + customerPage.entity(title).click(); + customerPage.editPencilBtn().click(); + customerPage.chooseDashboard(); + customerPage.doneBtnEditView().click(); + customerPage.setDashboardFromView(); + customerPage.closeEntityViewBtn().click(); + customerPage.manageCustomersUserBtn(title).click(); + customerPage.createCustomersUser(); + customerPage.userLoginBtn().click(); + customerName = title; + + Assert.assertNotNull(customerPage.usersWidget()); + Assert.assertTrue(customerPage.usersWidget().isDisplayed()); + Assert.assertEquals(customerPage.getDashboard(), customerPage.getDashboardFromView()); + } + + @Test(priority = 20, groups = "smoke") + @Description + public void assignedDashboardWithoutHide() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + + sideBarMenuView.customerBtn().click(); + customerPage.manageCustomersDashboardsBtn(title).click(); + customerPage.assignedDashboard(); + sideBarMenuView.customerBtn().click(); + customerPage.entity(title).click(); + customerPage.editPencilBtn().click(); + customerPage.chooseDashboard(); + customerPage.hideHomeDashboardToolbarCheckbox().click(); + customerPage.doneBtnEditView().click(); + customerPage.setDashboardFromView(); + customerPage.closeEntityViewBtn().click(); + customerPage.manageCustomersUserBtn(title).click(); + customerPage.createCustomersUser(); + customerPage.userLoginBtn().click(); + customerName = title; + + Assert.assertNotNull(customerPage.usersWidget()); + Assert.assertTrue(customerPage.usersWidget().isDisplayed()); + Assert.assertEquals(customerPage.getDashboard(), customerPage.getDashboardFromView()); + Assert.assertNotNull(customerPage.stateController()); + Assert.assertNotNull(customerPage.filterBtn()); + Assert.assertNotNull(customerPage.timeBtn()); + Assert.assertTrue(customerPage.stateController().isDisplayed()); + Assert.assertTrue(customerPage.filterBtn().isDisplayed()); + Assert.assertTrue(customerPage.timeBtn().isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description + public void addPhoneNumber() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + String number = "2015550123"; + + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.phoneNumberEntityView().sendKeys(number); + customerPage.doneBtnEditView().click(); + customerName = title; + + Assert.assertTrue(customerPage.phoneNumberEntityView().getAttribute("value").contains(number)); + } + + @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "incorrectPhoneNumber") + @Description + public void addIncorrectPhoneNumber(String number) { + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.phoneNumberEntityView().sendKeys(number); + boolean doneBtnIsEnable = customerPage.doneBtnEditViewVisible().isEnabled(); + customerPage.doneBtnEditViewVisible().click(); + + Assert.assertFalse(doneBtnIsEnable); + Assert.assertNotNull(customerPage.errorMessage()); + Assert.assertTrue(customerPage.errorMessage().isDisplayed()); + Assert.assertEquals(customerPage.errorMessage().getText(), PHONE_NUMBER_ERROR_MESSAGE); + } + + @Test(priority = 30, groups = "smoke") + public void addAllInformation() { + String title = ENTITY_NAME; + customerPage.createCustomer(title); + String text = "Text"; + String email = "email@mail.com"; + String number = "2015550123"; + + sideBarMenuView.customerBtn().click(); + customerPage.entityTitles().get(0).click(); + customerPage.editPencilBtn().click(); + customerPage.selectCountryEntityView(); + customerPage.descriptionEntityView().sendKeys(text); + customerPage.cityEntityView().sendKeys(text); + customerPage.stateEntityView().sendKeys(text); + customerPage.zipEntityView().sendKeys(text); + customerPage.addressEntityView().sendKeys(text); + customerPage.address2EntityView().sendKeys(text); + customerPage.phoneNumberEntityView().sendKeys(number); + customerPage.emailEntityView().sendKeys(email); + customerPage.doneBtnEditView().click(); + customerName = title; + + Assert.assertEquals(customerPage.countrySelectMenuEntityView().getText(), customerPage.getCountry()); + Assert.assertEquals(customerPage.descriptionEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.cityEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.stateEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.zipEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.addressEntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.address2EntityView().getAttribute("value"), text); + Assert.assertEquals(customerPage.phoneNumberEntityView().getAttribute("value"), "+1" + number); + Assert.assertEquals(customerPage.emailEntityView().getAttribute("value"), email); + } +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java new file mode 100644 index 0000000000..7a22422777 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java @@ -0,0 +1,83 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class DeleteCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private RuleChainsPageHelperAbstract ruleChainsPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can remove the customer by clicking on the trash can icon in the right corner") + public void removeCustomerByRightSideBtn() { + String customer = ENTITY_NAME; + customerPage.createCustomer(customer); + + sideBarMenuView.customerBtn().click(); + String deletedCustomer = customerPage.deleteRuleChainTrash(customer); + customerPage.refreshBtn().click(); + + Assert.assertTrue(customerPage.entityIsNotPresent(deletedCustomer)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can mark the customer in the checkbox and then click on the trash can icon in the menu that appears at the top") + public void removeSelectedCustomer() { + String customerName = ENTITY_NAME; + customerPage.createCustomer(customerName); + + sideBarMenuView.customerBtn().click(); + String deletedCustomer = customerPage.deleteSelected(customerName); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedCustomer)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can click on the name of the rule chain and click on the 'Delete customer' button") + public void removeFromCustomerView() { + String customerName = ENTITY_NAME; + customerPage.createCustomer(customerName); + + sideBarMenuView.customerBtn().click(); + customerPage.entity(customerName).click(); + String deletedCustomer = ruleChainsPage.deleteRuleChainFromView(customerName); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedCustomer)); + } + + @Test(priority = 20, groups = "smoke") + @Description("The rule chain is deleted immediately after clicking remove (no need to refresh the page)") + public void removeCustomerByRightSideBtnWithoutRefresh() { + String customer = ENTITY_NAME; + customerPage.createCustomer(customer); + + sideBarMenuView.customerBtn().click(); + String deletedCustomer = customerPage.deleteRuleChainTrash(customer); + customerPage.refreshBtn().click(); + + Assert.assertTrue(customerPage.entityIsNotPresent(deletedCustomer)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java new file mode 100644 index 0000000000..9847f1b763 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java @@ -0,0 +1,81 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class DeleteSeveralCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can mark several customers in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + public void canDeleteSeveralCustomersByTopBtn() { + String title1 = ENTITY_NAME + "1"; + String title2 = ENTITY_NAME + "2"; + int count = 2; + customerPage.createCustomer(title1); + customerPage.createCustomer(title2); + + sideBarMenuView.customerBtn().click(); + customerPage.clickOnCheckBoxes(count); + + Assert.assertEquals(customerPage.markCheckbox().size(), count); + customerPage.markCheckbox().forEach(x -> Assert.assertTrue(x.isDisplayed())); + + customerPage.deleteSelectedBtn().click(); + customerPage.warningPopUpYesBtn().click(); + customerPage.refreshBtn().click(); + + Assert.assertTrue(customerPage.customerIsNotPresent(title1)); + Assert.assertTrue(customerPage.customerIsNotPresent(title2)); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + public void selectAllCustomers() { + sideBarMenuView.customerBtn().click(); + customerPage.selectAllCheckBox().click(); + customerPage.deleteSelectedBtn().click(); + + Assert.assertNotNull(customerPage.warningPopUpTitle()); + Assert.assertTrue(customerPage.warningPopUpTitle().isDisplayed()); + Assert.assertTrue(customerPage.warningPopUpTitle().getText().contains(String.valueOf(customerPage.markCheckbox().size()))); + } + + @Test(priority = 30, groups = "smoke") + @Description("The rule chains are deleted immediately after clicking remove (no need to refresh the page)") + public void deleteSeveralCustomersByTopBtnWithoutRefresh() { + String title1 = ENTITY_NAME + "1"; + String title2 = ENTITY_NAME + "2"; + int count = 2; + customerPage.createCustomer(title1); + customerPage.createCustomer(title2); + + sideBarMenuView.customerBtn().click(); + customerPage.clickOnCheckBoxes(count); + + customerPage.deleteSelectedBtn().click(); + customerPage.warningPopUpYesBtn().click(); + + Assert.assertTrue(customerPage.customerIsNotPresent(title1)); + Assert.assertTrue(customerPage.customerIsNotPresent(title2)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java new file mode 100644 index 0000000000..785ee8c813 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java @@ -0,0 +1,54 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class ManageCustomersAssetsAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private final String manage = "Assets"; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer assets' window by clicking on the 'Manage customer users' icon in the right corner") + public void openWindowByRightCornerBtn() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.manageCustomersAssetsBtn(customerPage.getCustomerName()).click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerAssetsIconHeader()); + Assert.assertTrue(customerPage.customerAssetsIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Assets' window by clicking on the name/row of the customer and click on the 'Manage users' button") + public void openWindowByView() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entity(customerPage.getCustomerName()).click(); + customerPage.manageCustomersAssetsBtnView().click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerAssetsIconHeader()); + Assert.assertTrue(customerPage.customerAssetsIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java new file mode 100644 index 0000000000..68fe281d0b --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java @@ -0,0 +1,53 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class ManageCustomersDashboardsAbstractDiverBaseTest extends AbstractDiverBaseTest { + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private final String manage = "Dashboards"; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Dashboards' window by clicking on the 'Manage customer users' icon in the right corner") + public void openWindowByRightCornerBtn() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.manageCustomersDashboardsBtn(customerPage.getCustomerName()).click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerDashboardIconHeader()); + Assert.assertTrue(customerPage.customerDashboardIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Dashboards' window by clicking on the name/row of the customer and click on the 'Manage users' button") + public void openWindowByView() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entity(customerPage.getCustomerName()).click(); + customerPage.manageCustomersDashboardsBtnView().click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerDashboardIconHeader()); + Assert.assertTrue(customerPage.customerDashboardIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java new file mode 100644 index 0000000000..d62b5fe4cf --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java @@ -0,0 +1,53 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class ManageCustomersDevicesAbstractDiverBaseTest extends AbstractDiverBaseTest { + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private final String manage = "Devices"; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Devices' window by clicking on the 'Manage customer users' icon in the right corner") + public void openWindowByRightCornerBtn() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.manageCustomersDevicesBtn(customerPage.getCustomerName()).click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerDevicesIconHeader()); + Assert.assertTrue(customerPage.customerDevicesIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Devices' window by clicking on the name/row of the customer and click on the 'Manage users' button") + public void openWindowByView() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entity(customerPage.getCustomerName()).click(); + customerPage.manageCustomersDeviceBtnView().click(); + + Assert.assertTrue(urlContains(manage.toLowerCase())); + Assert.assertNotNull(customerPage.customerDevicesIconHeader()); + Assert.assertTrue(customerPage.customerDevicesIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(manage)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java new file mode 100644 index 0000000000..ff0ac3e4f1 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java @@ -0,0 +1,54 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class ManageCustomersEdgesAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private String iconText = "Edge instances"; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Edges' window by clicking on the 'Manage customer users' icon in the right corner") + public void openWindowByRightCornerBtn() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.manageCustomersEdgeBtn(customerPage.getCustomerName()).click(); + + Assert.assertTrue(urlContains("edgeInstances")); + Assert.assertNotNull(customerPage.customerEdgeIconHeader()); + Assert.assertTrue(customerPage.customerEdgeIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(iconText)); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Edges' window by clicking on the name/row of the customer and click on the 'Manage users' button") + public void openWindowByView() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entity(customerPage.getCustomerName()).click(); + customerPage.manageCustomersEdgeBtnView().click(); + + Assert.assertTrue(urlContains("edgeInstances")); + Assert.assertNotNull(customerPage.customerEdgeIconHeader()); + Assert.assertTrue(customerPage.customerEdgeIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(iconText)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java new file mode 100644 index 0000000000..855e227b5e --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java @@ -0,0 +1,54 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class ManageCustomersUsersAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private String iconText = "Customer Users"; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Users' window by clicking on the 'Manage customer users' icon in the right corner") + public void openWindowByRightCornerBtn() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.manageCustomersUserBtn(customerPage.getCustomerName()).click(); + + Assert.assertTrue(urlContains("user")); + Assert.assertNotNull(customerPage.customerUserIconHeader()); + Assert.assertTrue(customerPage.customerUserIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(iconText)); + } + + @Test(groups = "smoke") + @Description("Can go to the 'Customer Users' window by clicking on the name/row of the customer and click on the 'Manage users' button") + public void openWindowByView() { + sideBarMenuView.customerBtn().click(); + customerPage.setCustomerName(); + customerPage.entity(customerPage.getCustomerName()).click(); + customerPage.manageCustomersUserBtnView().click(); + + Assert.assertTrue(urlContains("user")); + Assert.assertNotNull(customerPage.customerUserIconHeader()); + Assert.assertTrue(customerPage.customerUserIconHeader().isDisplayed()); + Assert.assertTrue(customerPage.customerManageWindowIconHead().getText().contains(iconText)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java new file mode 100644 index 0000000000..6db022da62 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java @@ -0,0 +1,56 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.DataProviderCredential; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class SearchCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private String entityName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @AfterMethod + public void deleteCustomer() { + customerPage.deleteCustomer(entityName); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "customerNameForSearchByFirstAndSecondWord") + @Description("Can search by the first/second word of the name") + public void searchFirstWord(String namePath) { + sideBarMenuView.customerBtn().click(); + customerPage.searchEntity(namePath); + + customerPage.allEntity().forEach(x -> Assert.assertTrue(x.getText().contains(namePath))); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSearchBySymbolAndNumber") + @Description("Can search by number/symbol") + public void searchNumber(String name, String namePath) { + customerPage.createCustomer(name); + + sideBarMenuView.customerBtn().click(); + customerPage.searchEntity(namePath); + customerPage.setCustomerName(); + entityName = name; + + Assert.assertTrue(customerPage.getCustomerName().contains(namePath)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java new file mode 100644 index 0000000000..8ab49b6c68 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java @@ -0,0 +1,121 @@ +package org.thingsboard.server.msa.ui.tests.customerSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.DataProviderCredential; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { + private SideBarMenuViewElements sideBarMenuView; + private CustomerPageHelperAbstract customerPage; + private String customerName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + customerPage = new CustomerPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (customerName != null) { + customerPage.deleteCustomer(customerName); + customerName = null; + } + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") + @Description + public void specialCharacterUp(String title) { + customerPage.createCustomer(title); + + sideBarMenuView.customerBtn().click(); + customerPage.sortByTitleBtn().click(); + customerPage.setCustomerName(); + customerName = title; + + Assert.assertEquals(customerPage.getCustomerName(), title); + } + + @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") + @Description + public void allSortUp(String customer, String customerSymbol, String customerNumber) { + customerPage.createCustomer(customerSymbol); + customerPage.createCustomer(customer); + customerPage.createCustomer(customerNumber); + + sideBarMenuView.customerBtn().click(); + customerPage.sortByTitleBtn().click(); + customerPage.setCustomerName(0); + String firstCustomer = customerPage.getCustomerName(); + customerPage.setCustomerName(1); + String secondCustomer = customerPage.getCustomerName(); + customerPage.setCustomerName(2); + String thirdCustomer = customerPage.getCustomerName(); + + boolean firstEquals = firstCustomer.equals(customerSymbol); + boolean secondEquals = secondCustomer.equals(customerNumber); + boolean thirdEquals = thirdCustomer.equals(customer); + + customerPage.deleteCustomer(customer); + customerPage.deleteCustomer(customerNumber); + customerPage.deleteCustomer(customerSymbol); + + Assert.assertTrue(firstEquals); + Assert.assertTrue(secondEquals); + Assert.assertTrue(thirdEquals); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") + @Description + public void specialCharacterDown(String title) { + customerPage.createCustomer(title); + + sideBarMenuView.customerBtn().click(); + customerPage.sortByNameDown(); + customerPage.setCustomerName(customerPage.allEntity().size() - 1); + customerName = title; + + Assert.assertEquals(customerPage.getCustomerName(), title); + } + + @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") + @Description + public void allSortDown(String customer, String customerSymbol, String customerNumber) { + customerPage.createCustomer(customerSymbol); + customerPage.createCustomer(customer); + customerPage.createCustomer(customerNumber); + + sideBarMenuView.customerBtn().click(); + int lastIndex = customerPage.allEntity().size() - 1; + customerPage.sortByNameDown(); + customerPage.setCustomerName(lastIndex); + String firstCustomer = customerPage.getCustomerName(); + customerPage.setCustomerName(lastIndex - 1); + String secondCustomer = customerPage.getCustomerName(); + customerPage.setCustomerName(lastIndex - 2); + String thirdCustomer = customerPage.getCustomerName(); + + boolean firstEquals = firstCustomer.equals(customerSymbol); + boolean secondEquals = secondCustomer.equals(customerNumber); + boolean thirdEquals = thirdCustomer.equals(customer); + + customerPage.deleteCustomer(customer); + customerPage.deleteCustomer(customerNumber); + customerPage.deleteCustomer(customerSymbol); + + Assert.assertTrue(firstEquals); + Assert.assertTrue(secondEquals); + Assert.assertTrue(thirdEquals); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java new file mode 100644 index 0000000000..2b05fb8867 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java @@ -0,0 +1,110 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBaseTest { + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private OpenRuleChainPageHelperAbstract openRuleChainPage; + private final String absolutePathToFileImportRuleChain = getClass().getClassLoader().getResource(IMPORT_RULE_CHAIN_FILE_NAME).getPath(); + private final String absolutePathToFileImportTxt = getClass().getClassLoader().getResource(IMPORT_TXT_FILE_NAME).getPath(); + private String ruleChainName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + openRuleChainPage = new OpenRuleChainPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (ruleChainName != null) { + ruleChainsPage.deleteRuleChain(ruleChainName); + ruleChainName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description("Can drop a JSON file and import it") + public void importRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openImportRuleChainView(); + ruleChainsPage.browseFile().sendKeys(absolutePathToFileImportRuleChain); + + Assert.assertNotNull(ruleChainsPage.importingFile(IMPORT_RULE_CHAIN_FILE_NAME)); + Assert.assertTrue(ruleChainsPage.importingFile(IMPORT_RULE_CHAIN_FILE_NAME).isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can delete a file by clicking on the icon Remove") + public void importRuleChainAndDeleteFile() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openImportRuleChainView(); + ruleChainsPage.browseFile().sendKeys(absolutePathToFileImportRuleChain); + ruleChainsPage.clearImportFileBtn().click(); + + Assert.assertNotNull(ruleChainsPage.importingFile(EMPTY_IMPORT_MESSAGE)); + Assert.assertTrue(ruleChainsPage.importingFile(EMPTY_IMPORT_MESSAGE).isDisplayed()); + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(IMPORT_TXT_FILE_NAME)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t Select / drop a file of a different format than JSON") + public void importTxtFile() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openImportRuleChainView(); + ruleChainsPage.browseFile().sendKeys(absolutePathToFileImportTxt); + + Assert.assertNotNull(ruleChainsPage.importingFile(EMPTY_IMPORT_MESSAGE)); + Assert.assertTrue(ruleChainsPage.importingFile(EMPTY_IMPORT_MESSAGE).isDisplayed()); + } + + @Test(priority = 30, groups = "smoke") + @Description("After clicking on Import - imported rule chain opens (need to save by clicking on the Apply changes icon)") + public void importRuleChainAndSave() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openImportRuleChainView(); + ruleChainsPage.browseFile().sendKeys(absolutePathToFileImportRuleChain); + ruleChainsPage.importBrowseFileBtn().click(); + openRuleChainPage.doneBtn().click(); + openRuleChainPage.waitUntilDoneBtnDisable(); + sideBarMenuView.ruleChainsBtn().click(); + ruleChainName = IMPORT_RULE_CHAIN_NAME; + + Assert.assertNotNull(ruleChainsPage.entity(IMPORT_RULE_CHAIN_NAME)); + Assert.assertTrue(ruleChainsPage.entity(IMPORT_RULE_CHAIN_NAME).isDisplayed()); + } + + @Test(priority = 40, groups = "smoke") + @Description("Can create a rule chain with the same name") + public void importRuleChainAndSaveWithSameName() { + ruleChainsPage.createRuleChain(IMPORT_RULE_CHAIN_NAME); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openImportRuleChainView(); + ruleChainsPage.browseFile().sendKeys(absolutePathToFileImportRuleChain); + ruleChainsPage.importBrowseFileBtn().click(); + openRuleChainPage.doneBtn().click(); + openRuleChainPage.waitUntilDoneBtnDisable(); + sideBarMenuView.ruleChainsBtn().click(); + boolean sizeBigger1 = ruleChainsPage.entities(IMPORT_RULE_CHAIN_NAME).size() > 1; + + ruleChainsPage.deleteAllRuleChain(IMPORT_RULE_CHAIN_NAME); + + Assert.assertTrue(sizeBigger1); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java new file mode 100644 index 0000000000..32470c86f9 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java @@ -0,0 +1,139 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class CreateRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private String ruleChainName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (ruleChainName != null) { + ruleChainsPage.deleteRuleChain(ruleChainName); + ruleChainName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description("Can click on Add after specifying the name (text/numbers /special characters)") + public void createRuleChain() { + String ruleChainName = ENTITY_NAME; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openCreateRuleChainView(); + ruleChainsPage.nameField().sendKeys(ruleChainName); + ruleChainsPage.addBtnC().click(); + ruleChainsPage.refreshBtn().click(); + this.ruleChainName = ruleChainName; + + Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); + Assert.assertTrue(ruleChainsPage.entity(ruleChainName).isDisplayed()); + } + + @Test(priority = 10, groups = "smoke") + @Description() + public void createRuleChainWithDescription() { + String ruleChainName = ENTITY_NAME; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openCreateRuleChainView(); + ruleChainsPage.nameField().sendKeys(ruleChainName); + ruleChainsPage.descriptionAddEntityView().sendKeys(ENTITY_NAME); + ruleChainsPage.addBtnC().click(); + ruleChainsPage.refreshBtn().click(); + ruleChainsPage.entity(ENTITY_NAME).click(); + ruleChainsPage.setHeaderName(); + this.ruleChainName = ruleChainName; + + Assert.assertEquals(ruleChainsPage.getHeaderName(), ruleChainName); + Assert.assertEquals(ruleChainsPage.descriptionEntityView().getAttribute("value"), ruleChainName); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t add rule chain without the name (empty field or just space)") + public void createRuleChainWithoutName() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openCreateRuleChainView(); + + Assert.assertFalse(ruleChainsPage.addBtnV().isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description() + public void createRuleChainWithOnlySpace() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openCreateRuleChainView(); + ruleChainsPage.nameField().sendKeys(" "); + ruleChainsPage.addBtnC().click(); + + Assert.assertNotNull(ruleChainsPage.warningMessage()); + Assert.assertTrue(ruleChainsPage.warningMessage().isDisplayed()); + Assert.assertEquals(ruleChainsPage.warningMessage().getText(), EMPTY_RULE_CHAIN_MESSAGE); + Assert.assertNotNull(ruleChainsPage.addEntityView()); + Assert.assertTrue(ruleChainsPage.addEntityView().isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can create a rule chain with the same name") + public void createRuleChainWithSameName() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(); + ruleChainsPage.openCreateRuleChainView(); + String ruleChainName = ruleChainsPage.getRuleChainName(); + ruleChainsPage.nameField().sendKeys(ruleChainName); + ruleChainsPage.addBtnC().click(); + ruleChainsPage.refreshBtn().click(); + this.ruleChainName = ruleChainName; + + Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); + Assert.assertTrue(ruleChainsPage.entities(ruleChainName).size() > 1); + } + + @Test(priority = 30, groups = "smoke") + @Description("After clicking on Add - appears immediately in the list (no need to refresh the page)") + public void createRuleChainWithoutRefresh() { + String ruleChainName = ENTITY_NAME; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.openCreateRuleChainView(); + ruleChainsPage.nameField().sendKeys(ruleChainName); + ruleChainsPage.addBtnC().click(); + this.ruleChainName = ruleChainName; + + Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); + Assert.assertTrue(ruleChainsPage.entity(ruleChainName).isDisplayed()); + } + + @Test(priority = 40, groups = "smoke") + @Description("Question mark icon leads to rule chain documentation (PE)") + public void documentation() { + String urlPath = "docs/user-guide/ui/rule-chains/"; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(); + ruleChainsPage.entity(ruleChainsPage.getRuleChainName()).click(); + ruleChainsPage.goToHelpPage(); + + Assert.assertTrue(urlContains(urlPath)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java new file mode 100644 index 0000000000..f2fe8c7c1c --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java @@ -0,0 +1,148 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can remove the rule chain by clicking on the trash can icon in the right corner") + public void removeRuleChainByRightSideBtn() { + ruleChainsPage.createRuleChain(ENTITY_NAME); + + sideBarMenuView.ruleChainsBtn().click(); + String deletedRuleChain = ruleChainsPage.deleteRuleChainTrash(ENTITY_NAME); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can mark the rule chain in the checkbox and then click on the trash can icon in the menu that appears at the top") + public void removeSelectedRuleChain() { + String ruleChainName = ENTITY_NAME; + ruleChainsPage.createRuleChain(ruleChainName); + + sideBarMenuView.ruleChainsBtn().click(); + String deletedRuleChain = ruleChainsPage.deleteSelected(ruleChainName); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can click on the name of the rule chain and click on the 'Delete rule chain' button") + public void removeFromRuleChainView() { + ruleChainsPage.createRuleChain(ENTITY_NAME); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.entity(ENTITY_NAME).click(); + String deletedRuleChain = ruleChainsPage.deleteRuleChainFromView(ENTITY_NAME); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t remove Root Rule Chain (the trash can is disabled in the right corner)") + public void removeRootRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + + Assert.assertFalse(ruleChainsPage.deleteBtn(ROOT_RULE_CHAIN_NAME).isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t remove Root Rule Chain (can`t mark the rule chain in the checkbox )") + public void removeSelectedRootRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + + ruleChainsPage.assertCheckBoxIsNotDisplayed(ROOT_RULE_CHAIN_NAME); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t remove Root Rule Chain (missing delete button)") + public void removeFromRootRuleChainView() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.entity(ROOT_RULE_CHAIN_NAME).click(); + ruleChainsPage.deleteBtnFromView(); + + ruleChainsPage.assertDeleteBtnInRootRuleChainIsNotDisplayed(); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can remove the rule chain by clicking on the trash can icon in the right corner") + public void removeProfileRuleChainByRightSideBtn() { + String deletedRuleChain = "Thermostat"; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.deleteBtn(deletedRuleChain).click(); + ruleChainsPage.warningPopUpYesBtn().click(); + ruleChainsPage.refreshBtn().click(); + + Assert.assertNotNull(ruleChainsPage.entity(deletedRuleChain)); + Assert.assertTrue(ruleChainsPage.entity(deletedRuleChain).isDisplayed()); + Assert.assertNotNull(ruleChainsPage.warningMessage()); + Assert.assertTrue(ruleChainsPage.warningMessage().isDisplayed()); + Assert.assertEquals(ruleChainsPage.warningMessage().getText(), DELETE_RULE_CHAIN_WITH_PROFILE_MESSAGE); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can mark the rule chain in the checkbox and then click on the trash can icon in the menu that appears at the top") + public void removeSelectedProfileRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + String deletedRuleChain = ruleChainsPage.deleteSelected("Thermostat"); + ruleChainsPage.refreshBtn().click(); + + Assert.assertNotNull(ruleChainsPage.entity(deletedRuleChain)); + Assert.assertTrue(ruleChainsPage.entity(deletedRuleChain).isDisplayed()); + Assert.assertNotNull(ruleChainsPage.warningMessage()); + Assert.assertTrue(ruleChainsPage.warningMessage().isDisplayed()); + Assert.assertEquals(ruleChainsPage.warningMessage().getText(), DELETE_RULE_CHAIN_WITH_PROFILE_MESSAGE); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can click on the name of the rule chain and click on the 'Delete rule chain' button") + public void removeFromProfileRuleChainView() { + String deletedRuleChain = "Thermostat"; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.entity(deletedRuleChain).click(); + ruleChainsPage.deleteBtnFromView().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + + Assert.assertNotNull(ruleChainsPage.entity(deletedRuleChain)); + Assert.assertNotNull(ruleChainsPage.warningMessage()); + Assert.assertTrue(ruleChainsPage.warningMessage().isDisplayed()); + Assert.assertEquals(ruleChainsPage.warningMessage().getText(), DELETE_RULE_CHAIN_WITH_PROFILE_MESSAGE); + } + + @Test(priority = 30, groups = "smoke") + @Description("The rule chain is deleted immediately after clicking remove (no need to refresh the page)") + public void removeRuleChainByRightSideBtnWithoutRefresh() { + String ruleChainName = ENTITY_NAME; + ruleChainsPage.createRuleChain(ruleChainName); + + sideBarMenuView.ruleChainsBtn().click(); + String deletedRuleChain = ruleChainsPage.deleteRuleChainTrash(ruleChainName); + + Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java new file mode 100644 index 0000000000..8481d9cde6 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java @@ -0,0 +1,92 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + public void canDeleteSeveralRuleChainsByTopBtn() { + String ruleChainName = ENTITY_NAME; + int count = 2; + ruleChainsPage.createRuleChains(ruleChainName, count); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.clickOnCheckBoxes(count); + + ruleChainsPage.deleteSelectedBtn().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.ruleChainsIsNotPresent(ruleChainName)); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + public void selectAllRuleChain() { + String ruleChainName = ENTITY_NAME; + int count = 2; + ruleChainsPage.createRuleChains(ruleChainName, count); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.selectAllCheckBox().click(); + ruleChainsPage.deleteSelectedBtn().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + ruleChainsPage.refreshBtn().click(); + + Assert.assertTrue(ruleChainsPage.ruleChainsIsNotPresent(ruleChainName)); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t remove Root Rule Chain (the trash can is disabled in the right corner)") + public void removeRootRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.selectAllCheckBox().click(); + + Assert.assertFalse(ruleChainsPage.deleteBtn(ROOT_RULE_CHAIN_NAME).isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t remove Root Rule Chain (can`t mark the rule chain in the checkbox )") + public void removeSelectedRootRuleChain() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.selectAllCheckBox().click(); + + ruleChainsPage.assertCheckBoxIsNotDisplayed(ROOT_RULE_CHAIN_NAME); + } + + @Test(priority = 30, groups = "smoke") + @Description("The rule chains are deleted immediately after clicking remove (no need to refresh the page)") + public void deleteSeveralRuleChainsByTopBtnWithoutRefresh() { + String ruleChainName = ENTITY_NAME; + int count = 2; + ruleChainsPage.createRuleChains(ruleChainName, count); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.clickOnCheckBoxes(count); + ruleChainsPage.deleteSelectedBtn().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + + Assert.assertTrue(ruleChainsPage.ruleChainsIsNotPresent(ruleChainName)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java new file mode 100644 index 0000000000..8a71a11232 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java @@ -0,0 +1,75 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class MakeRuleChainRootAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @AfterMethod + public void makeRoot() { + ruleChainsPage.makeRoot(); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can make rule chain root by clicking on the 'Make rule chain root' icon in the right corner") + public void makeRuleChainRootByRightCornerBtn() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.makeRootBtn(ruleChain).click(); + ruleChainsPage.warningPopUpYesBtn().click(); + + Assert.assertTrue(ruleChainsPage.rootCheckBoxEnable(ruleChain).isDisplayed()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can make rule chain by clicking on the name/row of the rule chain and click on the 'make rule chain root' button") + public void makeRuleChainRootFromView() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.entity(ruleChain).click(); + ruleChainsPage.makeRootFromViewBtn().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + ruleChainsPage.closeEntityViewBtn().click(); + + Assert.assertTrue(ruleChainsPage.rootCheckBoxEnable(ruleChain).isDisplayed()); + } + + @Test(priority = 30, groups = "smoke") + @Description("Can't make multiple root rule chains (only one rule chain can be root)") + public void multiplyRoot() { + SideBarMenuViewElements sideBarMenuView = new SideBarMenuViewElements(driver); + RuleChainsPageHelperAbstract ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.entity(ruleChain).click(); + ruleChainsPage.makeRootFromViewBtn().click(); + ruleChainsPage.warningPopUpYesBtn().click(); + ruleChainsPage.closeEntityViewBtn().click(); + + Assert.assertEquals(ruleChainsPage.rootCheckBoxesEnable().size(), 1); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java new file mode 100644 index 0000000000..f38f20bdff --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java @@ -0,0 +1,71 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class OpenRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private OpenRuleChainPageHelperAbstract openRuleChainPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + openRuleChainPage = new OpenRuleChainPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can open the rule chain by clicking on the 'Open rule chain' icon in the right corner") + public void openRuleChainByRightCornerBtn() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.openRuleChainBtn(ruleChain).click(); + openRuleChainPage.setHeadName(); + + Assert.assertTrue(urlContains(ruleChainsPage.getRuleChainId(ruleChainsPage.getRuleChainName()))); + Assert.assertTrue(openRuleChainPage.headRuleChainName().isDisplayed()); + Assert.assertTrue(openRuleChainPage.inputNode().isDisplayed()); + Assert.assertEquals(ruleChainsPage.getRuleChainName(), openRuleChainPage.getHeadName()); + } + + @Test(priority = 10, groups = "smoke") + @Description("Can open the rule chain by clicking on the name/row of the rule chain and click on the 'Open rule chain' button") + public void openRuleChainByViewBtn() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.entity(ruleChain).click(); + ruleChainsPage.openRuleChainFromViewBtn().click(); + openRuleChainPage.setHeadName(); + + Assert.assertTrue(urlContains(ruleChainsPage.getRuleChainId(ruleChain))); + Assert.assertTrue(openRuleChainPage.headRuleChainName().isDisplayed()); + Assert.assertTrue(openRuleChainPage.inputNode().isDisplayed()); + Assert.assertEquals(ruleChain, openRuleChainPage.getHeadName()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t open the rule chain by clicking twice on the row/name") + public void openRuleChainDoubleClick() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setRuleChainNameWithoutRoot(0); + String ruleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.doubleClickOnRuleChain(ruleChain); + + Assert.assertEquals(getUrl(), URL + "ruleChains"); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java new file mode 100644 index 0000000000..9a080d7435 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java @@ -0,0 +1,130 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.*; + +public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private String ruleChainName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (ruleChainName != null) { + ruleChainsPage.deleteRuleChain(ruleChainName); + ruleChainName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description("Can click by pencil icon and edit the name (change the name) and save the changes. All changes have been applied") + public void changeName() { + ruleChainsPage.createRuleChain(ENTITY_NAME); + String name = "Changed"; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.notRootRuleChainsNames().get(0).click(); + ruleChainsPage.setHeaderName(); + String nameBefore = ruleChainsPage.getHeaderName(); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.changeNameEditMenu(name); + ruleChainsPage.doneBtnEditView().click(); + ruleChainsPage.setHeaderName(); + String nameAfter = ruleChainsPage.getHeaderName(); + ruleChainName = name; + + Assert.assertNotEquals(nameBefore, nameAfter); + Assert.assertEquals(name, nameAfter); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t delete the name and save changes") + public void deleteName() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.notRootRuleChainsNames().get(0).click(); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.changeNameEditMenu(""); + + Assert.assertFalse(ruleChainsPage.doneBtnEditViewVisible().isEnabled()); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can`t save just a space in the name") + public void saveOnlyWithSpace() { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.notRootRuleChainsNames().get(0).click(); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.changeNameEditMenu(" "); + ruleChainsPage.doneBtnEditView().click(); + + Assert.assertNotNull(ruleChainsPage.warningMessage()); + Assert.assertTrue(ruleChainsPage.warningMessage().isDisplayed()); + Assert.assertEquals(ruleChainsPage.warningMessage().getText(), EMPTY_RULE_CHAIN_MESSAGE); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can write/change/delete the descriptionEntityView and save the changes. All changes have been applied") + public void editDescription() { + String name = ENTITY_NAME; + ruleChainsPage.createRuleChain(name); + String description = "Description"; + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.notRootRuleChainsNames().get(0).click(); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.descriptionEntityView().sendKeys(description); + ruleChainsPage.doneBtnEditView().click(); + String description1 = ruleChainsPage.descriptionEntityView().getAttribute("value"); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.descriptionEntityView().sendKeys(description); + ruleChainsPage.doneBtnEditView().click(); + String description2 = ruleChainsPage.descriptionEntityView().getAttribute("value"); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.changeDescription(""); + ruleChainsPage.doneBtnEditView().click(); + ruleChainName = name; + + Assert.assertTrue(ruleChainsPage.descriptionEntityView().getAttribute("value").isEmpty()); + Assert.assertEquals(description, description1); + Assert.assertEquals(description + description, description2); + } + + @Test(priority = 20, groups = "smoke") + @Description("Can enable / disable debug and save changes. All changes have been applied") + public void debugMode() { + String name = ENTITY_NAME; + ruleChainsPage.createRuleChain(name); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.notRootRuleChainsNames().get(0).click(); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.debugCheckboxEdit().click(); + ruleChainsPage.doneBtnEditView().click(); + boolean debugMode = Boolean.parseBoolean(ruleChainsPage.debugCheckboxView().getAttribute("aria-checked")); + ruleChainsPage.editPencilBtn().click(); + ruleChainsPage.debugCheckboxEdit().click(); + ruleChainsPage.doneBtnEditView().click(); + ruleChainName = name; + + Assert.assertFalse(Boolean.parseBoolean(ruleChainsPage.debugCheckboxView().getAttribute("aria-checked"))); + Assert.assertTrue(debugMode); + } +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java new file mode 100644 index 0000000000..0a8dc6d96b --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java @@ -0,0 +1,52 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.DataProviderCredential; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class SearchRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "ruleChainNameForSearchByFirstAndSecondWord") + @Description("Can search by the first/second word of the name") + public void searchFirstWord(String namePath) { + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.searchEntity(namePath); + ruleChainsPage.setRuleChainName(0); + + Assert.assertTrue(ruleChainsPage.getRuleChainName().contains(namePath)); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSearchBySymbolAndNumber") + @Description("Can search by number/symbol") + public void searchNumber(String name, String namePath) { + ruleChainsPage.createRuleChain(name); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.searchEntity(namePath); + ruleChainsPage.setRuleChainName(0); + boolean ruleChainContainsNamePath = ruleChainsPage.getRuleChainName().contains(namePath); + + ruleChainsPage.deleteRuleChain(name); + + Assert.assertTrue(ruleChainContainsNamePath); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java new file mode 100644 index 0000000000..a8f381c494 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java @@ -0,0 +1,122 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.DataProviderCredential; + +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private String ruleChainName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (ruleChainName != null) { + ruleChainsPage.deleteRuleChain(ruleChainName); + ruleChainName = null; + } + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") + @Description + public void specialCharacterUp(String ruleChainName) { + ruleChainsPage.createRuleChain(ruleChainName); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.sortByNameBtn().click(); + ruleChainsPage.setRuleChainName(0); + this.ruleChainName = ruleChainName; + + Assert.assertEquals(ruleChainsPage.getRuleChainName(), ruleChainName); + } + + @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") + @Description + public void allSortUp(String ruleChain, String ruleChainSymbol, String ruleChainNumber) { + ruleChainsPage.createRuleChain(ruleChainSymbol); + ruleChainsPage.createRuleChain(ruleChain); + ruleChainsPage.createRuleChain(ruleChainNumber); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.sortByNameBtn().click(); + ruleChainsPage.setRuleChainName(0); + String firstRuleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.setRuleChainName(1); + String secondRuleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.setRuleChainName(2); + String thirdRuleChain = ruleChainsPage.getRuleChainName(); + + boolean firstEquals = firstRuleChain.equals(ruleChainSymbol); + boolean secondEquals = secondRuleChain.equals(ruleChainNumber); + boolean thirdEquals = thirdRuleChain.equals(ruleChain); + + ruleChainsPage.deleteRuleChain(ruleChain); + ruleChainsPage.deleteRuleChain(ruleChainNumber); + ruleChainsPage.deleteRuleChain(ruleChainSymbol); + + Assert.assertTrue(firstEquals); + Assert.assertTrue(secondEquals); + Assert.assertTrue(thirdEquals); + } + + @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") + @Description + public void specialCharacterDown(String ruleChainName) { + ruleChainsPage.createRuleChain(ruleChainName); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.sortByNameDown(); + ruleChainsPage.setRuleChainName(ruleChainsPage.allNames().size() - 1); + this.ruleChainName = ruleChainName; + + Assert.assertEquals(ruleChainsPage.getRuleChainName(), ruleChainName); + } + + @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") + @Description + public void allSortDown(String ruleChain, String ruleChainSymbol, String ruleChainNumber) { + ruleChainsPage.createRuleChain(ruleChainSymbol); + ruleChainsPage.createRuleChain(ruleChain); + ruleChainsPage.createRuleChain(ruleChainNumber); + + sideBarMenuView.ruleChainsBtn().click(); + int lastIndex = ruleChainsPage.allNames().size() - 1; + ruleChainsPage.sortByNameDown(); + ruleChainsPage.setRuleChainName(lastIndex); + String firstRuleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.setRuleChainName(lastIndex - 1); + String secondRuleChain = ruleChainsPage.getRuleChainName(); + ruleChainsPage.setRuleChainName(lastIndex - 2); + String thirdRuleChain = ruleChainsPage.getRuleChainName(); + + boolean firstEquals = firstRuleChain.equals(ruleChainSymbol); + boolean secondEquals = secondRuleChain.equals(ruleChainNumber); + boolean thirdEquals = thirdRuleChain.equals(ruleChain); + + ruleChainsPage.deleteRuleChain(ruleChain); + ruleChainsPage.deleteRuleChain(ruleChainNumber); + ruleChainsPage.deleteRuleChain(ruleChainSymbol); + + Assert.assertTrue(firstEquals); + Assert.assertTrue(secondEquals); + Assert.assertTrue(thirdEquals); + } +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java new file mode 100644 index 0000000000..3fc33e3ac0 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java @@ -0,0 +1,70 @@ +package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; + +import io.qameta.allure.Description; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; +import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; + +import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; +import static org.thingsboard.server.msa.ui.utils.Const.URL; + +public class SortByTimeAbstractDiverBaseTest extends AbstractDiverBaseTest { + + private SideBarMenuViewElements sideBarMenuView; + private RuleChainsPageHelperAbstract ruleChainsPage; + private String ruleChainName; + + @BeforeMethod + public void login() { + openUrl(URL); + new LoginPageHelperAbstract(driver).authorizationTenant(); + sideBarMenuView = new SideBarMenuViewElements(driver); + ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + } + + @AfterMethod + public void delete() { + if (ruleChainName != null) { + ruleChainsPage.deleteRuleChain(ruleChainName); + ruleChainName = null; + } + } + + @Test(priority = 10, groups = "smoke") + @Description + public void sortByTimeDown() { + String ruleChain = ENTITY_NAME; + ruleChainsPage.createRuleChain(ruleChain); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.setSort(); + String firstListElement = ruleChainsPage.getSort().get(ruleChainsPage.getSort().size() - 1); + String lastCreated = ruleChainsPage.createdTime().get(0).getText(); + ruleChainName = ruleChain; + + Assert.assertEquals(firstListElement, lastCreated); + Assert.assertNotNull(ruleChainsPage.createdTimeEntity(ruleChain, lastCreated)); + } + + @Test(priority = 10, groups = "smoke") + @Description + public void sortByTimeUp() { + String ruleChain = ENTITY_NAME; + ruleChainsPage.createRuleChain(ruleChain); + + sideBarMenuView.ruleChainsBtn().click(); + ruleChainsPage.sortByTimeBtn().click(); + ruleChainsPage.setSort(); + String firstListElement = ruleChainsPage.getSort().get(ruleChainsPage.getSort().size() - 1); + String lastCreated = ruleChainsPage.createdTime().get(ruleChainsPage.createdTime().size() - 1).getText(); + ruleChainName = ruleChain; + + Assert.assertEquals(firstListElement, lastCreated); + Assert.assertNotNull(ruleChainsPage.createdTimeEntity(ruleChain, lastCreated)); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java new file mode 100644 index 0000000000..db6bd40084 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java @@ -0,0 +1,21 @@ +package utils; + +import base.Base; + +public class Const extends Base { + + public static final String URL = "http://localhost:8080/"; + public static final String TENANT_EMAIL = "tenant@thingsboard.org"; + public static final String TENANT_PASSWORD = "tenant"; + public static final String ENTITY_NAME = "Az!@#$%^&*()_-+=~`" + getRandomNumber(); + public static final String ROOT_RULE_CHAIN_NAME = "Root Rule Chain"; + public static final String IMPORT_RULE_CHAIN_NAME = "Rule Chain from Import"; + public static final String IMPORT_RULE_CHAIN_FILE_NAME = "forImport.json"; + public static final String IMPORT_TXT_FILE_NAME = "forImport.txt"; + public static final String EMPTY_IMPORT_MESSAGE = "No file selected"; + public static final String EMPTY_RULE_CHAIN_MESSAGE = "Rule chain name should be specified!"; + public static final String EMPTY_CUSTOMER_MESSAGE = "Customer title should be specified!"; + public static final String DELETE_RULE_CHAIN_WITH_PROFILE_MESSAGE = "The rule chain referenced by the device profiles cannot be deleted!"; + public static final String SAME_NAME_WARNING_CUSTOMER_MESSAGE = "Customer with such title already exists!"; + public static final String PHONE_NUMBER_ERROR_MESSAGE = "Phone number is invalid or not possible"; +} \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java new file mode 100644 index 0000000000..1509250abf --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java @@ -0,0 +1,62 @@ +package utils; + +import org.testng.annotations.DataProvider; + +import static base.Base.getRandomSymbol; +import static utils.Const.ENTITY_NAME; + +public class DataProviderCredential { + + private static final String SYMBOL = String.valueOf(getRandomSymbol()); + private static final String NAME = ENTITY_NAME; + private static final String NUMBER = "1"; + private static final String LONG_PHONE_NUMBER = "20155501231"; + private static final String SHORT_PHONE_NUMBER = "201555011"; + private static final String RULE_CHAIN_SECOND_WORD_NAME_PATH = "Rule"; + private static final String CUSTOMER_SECOND_WORD_NAME_PATH = "Customer"; + private static final String RULE_CHAIN_FIRST_WORD_NAME_PATH = "Root"; + private static final String CUSTOMER_FIRST_WORD_NAME_PATH = "A"; + + @DataProvider + public static Object[][] ruleChainNameForSearchByFirstAndSecondWord() { + return new Object[][]{ + {RULE_CHAIN_SECOND_WORD_NAME_PATH}, + {RULE_CHAIN_FIRST_WORD_NAME_PATH}}; + } + + @DataProvider + public static Object[][] nameForSearchBySymbolAndNumber() { + return new Object[][]{ + {NAME, ENTITY_NAME.split("`")[1]}, + {NAME, String.valueOf(getRandomSymbol())}}; + } + + @DataProvider + public static Object[][] nameForSort() { + return new Object[][]{ + {NAME}, + {SYMBOL}, + {NUMBER}}; + } + + @DataProvider + public static Object[][] nameForAllSort() { + return new Object[][]{ + {NAME, SYMBOL, NUMBER}}; + } + + @DataProvider + public static Object[][] incorrectPhoneNumber() { + return new Object[][]{ + {LONG_PHONE_NUMBER}, + {SHORT_PHONE_NUMBER}, + {ENTITY_NAME}}; + } + + @DataProvider + public static Object[][] customerNameForSearchByFirstAndSecondWord() { + return new Object[][]{ + {CUSTOMER_FIRST_WORD_NAME_PATH}, + {CUSTOMER_SECOND_WORD_NAME_PATH}}; + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java new file mode 100644 index 0000000000..683dca511c --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java @@ -0,0 +1,19 @@ +package org.thingsboard.server.msa.ui.utils; + +import org.thingsboard.server.common.data.Customer; +import org.thingsboard.server.common.data.rule.RuleChain; + +public class CustomerPrototypes { + + public static Customer defaultCustomerPrototype(String entityName){ + Customer customer = new Customer(); + customer.setTitle(entityName); + return customer; + } + + public static RuleChain defaultRuleChainPrototype(String entityName){ + RuleChain ruleChain = new RuleChain(); + ruleChain.setName(entityName); + return ruleChain; + } +} diff --git a/msa/black-box-tests/src/test/resources/connectivity.xml b/msa/black-box-tests/src/test/resources/connectivity.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/msa/black-box-tests/src/test/resources/forImport.json b/msa/black-box-tests/src/test/resources/forImport.json new file mode 100644 index 0000000000..40367d7609 --- /dev/null +++ b/msa/black-box-tests/src/test/resources/forImport.json @@ -0,0 +1,20 @@ +{ + "ruleChain": { + "additionalInfo": { + "description": "" + }, + "name": "Rule Chain from Import", + "type": "CORE", + "firstRuleNodeId": null, + "root": false, + "debugMode": false, + "configuration": null, + "externalId": null + }, + "metadata": { + "firstNodeIndex": null, + "nodes": [], + "connections": null, + "ruleChainConnections": null + } +} diff --git a/msa/black-box-tests/src/test/resources/forImport.txt b/msa/black-box-tests/src/test/resources/forImport.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/msa/black-box-tests/src/test/resources/smokeTests.xml b/msa/black-box-tests/src/test/resources/smokeTests.xml new file mode 100644 index 0000000000..1194791760 --- /dev/null +++ b/msa/black-box-tests/src/test/resources/smokeTests.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/msa/black-box-tests/src/test/resources/smokesCustomer.xml b/msa/black-box-tests/src/test/resources/smokesCustomer.xml new file mode 100644 index 0000000000..0282d57cbd --- /dev/null +++ b/msa/black-box-tests/src/test/resources/smokesCustomer.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msa/black-box-tests/src/test/resources/smokesRuleChain.xml b/msa/black-box-tests/src/test/resources/smokesRuleChain.xml new file mode 100644 index 0000000000..43598e5358 --- /dev/null +++ b/msa/black-box-tests/src/test/resources/smokesRuleChain.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 843e6ee87c2455410bdf4fcd8839793ff1236b98 Mon Sep 17 00:00:00 2001 From: Serafym Tuhai Date: Tue, 22 Nov 2022 13:19:21 +0200 Subject: [PATCH 008/527] add ui tests --- .../server/msa/TestRestClient.java | 80 +++++++++---- .../msa/connectivity/MqttClientTest.java | 2 +- .../server/msa/ui/base/AbstractBasePage.java | 42 ++++--- .../msa/ui/base/AbstractDiverBaseTest.java | 60 ++++++++-- .../msa/ui/listeners/RetryAnalyzer.java | 17 ++- .../msa/ui/listeners/RetryTestListener.java | 17 ++- .../server/msa/ui/listeners/TestListener.java | 31 ++++-- .../msa/ui/pages/CustomerPageElements.java | 19 +++- .../msa/ui/pages/CustomerPageHelper.java | 50 +++------ .../msa/ui/pages/DashboardPageElements.java | 19 +++- .../msa/ui/pages/DashboardPageHelper.java | 19 +++- .../msa/ui/pages/LoginPageElements.java | 19 +++- .../server/msa/ui/pages/LoginPageHelper.java | 19 +++- .../ui/pages/OpenRuleChainPageElements.java | 19 +++- .../msa/ui/pages/OpenRuleChainPageHelper.java | 19 +++- .../msa/ui/pages/OtherPageElements.java | 20 +++- .../msa/ui/pages/OtherPageElementsHelper.java | 19 +++- .../msa/ui/pages/RuleChainsPageElements.java | 19 +++- .../msa/ui/pages/RuleChainsPageHelper.java | 94 ++++------------ .../msa/ui/pages/SideBarMenuViewElements.java | 21 +++- .../customerSmoke/CreateCustomerTest.java | 56 ++++++---- .../customerSmoke/CustomerEditMenuTest.java | 105 ++++++++++-------- .../customerSmoke/DeleteCustomerTest.java | 54 +++++---- .../DeleteSeveralCustomerTest.java | 57 ++++++---- .../ManageCustomersAssetsTest.java | 31 ++++-- .../ManageCustomersDashboardsTest.java | 31 ++++-- .../ManageCustomersDevicesTest.java | 31 ++++-- .../ManageCustomersEdgesTest.java | 33 ++++-- .../ManageCustomersUsersTest.java | 33 ++++-- .../customerSmoke/SearchCustomerTest.java | 50 +++++---- .../tests/customerSmoke/SortByNameTest.java | 65 +++++++---- .../CreateRuleChainImportTest.java | 65 +++++++---- .../ruleChainsSmoke/CreateRuleChainTest.java | 74 +++++++----- .../ruleChainsSmoke/DeleteRuleChainTest.java | 65 +++++++---- .../DeleteSeveralRuleChainsTest.java | 56 ++++++---- .../MakeRuleChainRootTest.java | 41 ++++--- .../ruleChainsSmoke/OpenRuleChainTest.java | 46 +++++--- .../RuleChainEditMenuTest.java | 54 +++++---- .../ruleChainsSmoke/SearchRuleChainTest.java | 39 +++++-- .../tests/ruleChainsSmoke/SortByNameTest.java | 62 +++++++---- .../tests/ruleChainsSmoke/SortByTimeTest.java | 38 +++++-- .../server/msa/ui/utils/Const.java | 21 +++- .../msa/ui/utils/DataProviderCredential.java | 21 +++- .../server/msa/ui/utils/EntityPrototypes.java | 17 ++- .../src/test/resources/connectivity.xml | 27 +++++ .../src/test/resources/forImport.txt | 16 +++ .../src/test/resources/smokeTests.xml | 6 +- .../src/test/resources/smokesCustomer.xml | 2 +- .../src/test/resources/smokesRuleChain.xml | 2 +- .../src/test/resources/testNG.xml | 10 +- msa/pom.xml | 2 + 51 files changed, 1237 insertions(+), 578 deletions(-) diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java index 713205e228..be0068fd04 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java @@ -26,7 +26,9 @@ import io.restassured.http.ContentType; import io.restassured.path.json.JsonPath; import io.restassured.response.ValidatableResponse; import io.restassured.specification.RequestSpecification; +import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.RuleChainId; @@ -76,7 +78,7 @@ public class TestRestClient { loginRequest.put("password", password); JsonPath jsonPath = given().spec(requestSpec).body(loginRequest) - .post( "/api/auth/login") + .post("/api/auth/login") .getBody().jsonPath(); token = jsonPath.get("token"); refreshToken = jsonPath.get("refreshToken"); @@ -84,7 +86,7 @@ public class TestRestClient { } public Device postDevice(String accessToken, Device device) { - return given().spec(requestSpec).body(device) + return given().spec(requestSpec).body(device) .pathParams("accessToken", accessToken) .post("/api/device?accessToken={accessToken}") .then() @@ -94,62 +96,65 @@ public class TestRestClient { } public ValidatableResponse getDeviceById(DeviceId deviceId, int statusCode) { - return given().spec(requestSpec) + return given().spec(requestSpec) .pathParams("deviceId", deviceId.getId()) .get("/api/device/{deviceId}") .then() .statusCode(statusCode); } + public Device getDeviceById(DeviceId deviceId) { - return getDeviceById(deviceId, HTTP_OK) + return getDeviceById(deviceId, HTTP_OK) .extract() .as(Device.class); } + public DeviceCredentials getDeviceCredentialsByDeviceId(DeviceId deviceId) { return given().spec(requestSpec).get("/api/device/{deviceId}/credentials", deviceId.getId()) - .then() - .assertThat() - .statusCode(HTTP_OK) - .extract() - .as(DeviceCredentials.class); + .then() + .assertThat() + .statusCode(HTTP_OK) + .extract() + .as(DeviceCredentials.class); } public ValidatableResponse postTelemetry(String credentialsId, JsonNode telemetry) { - return given().spec(requestSpec).body(telemetry) - .post("/api/v1/{credentialsId}/telemetry", credentialsId) - .then() - .statusCode(HTTP_OK); + return given().spec(requestSpec).body(telemetry) + .post("/api/v1/{credentialsId}/telemetry", credentialsId) + .then() + .statusCode(HTTP_OK); } public ValidatableResponse deleteDevice(DeviceId deviceId) { - return given().spec(requestSpec) + return given().spec(requestSpec) .delete("/api/device/{deviceId}", deviceId.getId()) .then() .statusCode(HTTP_OK); } + public ValidatableResponse deleteDeviceIfExists(DeviceId deviceId) { - return given().spec(requestSpec) + return given().spec(requestSpec) .delete("/api/device/{deviceId}", deviceId.getId()) .then() - .statusCode(anyOf(is(HTTP_OK),is(HTTP_NOT_FOUND))); + .statusCode(anyOf(is(HTTP_OK), is(HTTP_NOT_FOUND))); } public ValidatableResponse postTelemetryAttribute(String entityType, DeviceId deviceId, String scope, JsonNode attribute) { - return given().spec(requestSpec).body(attribute) + return given().spec(requestSpec).body(attribute) .post("/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", entityType, deviceId.getId(), scope) .then() .statusCode(HTTP_OK); } public ValidatableResponse postAttribute(String accessToken, JsonNode attribute) { - return given().spec(requestSpec).body(attribute) + return given().spec(requestSpec).body(attribute) .post("/api/v1/{accessToken}/attributes/", accessToken) .then() .statusCode(HTTP_OK); } public JsonNode getAttributes(String accessToken, String clientKeys, String sharedKeys) { - return given().spec(requestSpec) + return given().spec(requestSpec) .queryParam("clientKeys", clientKeys) .queryParam("sharedKeys", sharedKeys) .get("/api/v1/{accessToken}/attributes", accessToken) @@ -167,10 +172,11 @@ public class TestRestClient { .then() .statusCode(HTTP_OK) .extract() - .as(new TypeRef>() {}); + .as(new TypeRef>() { + }); } - public RuleChain postRootRuleChain(RuleChain ruleChain) { + public RuleChain postRuleChain(RuleChain ruleChain) { return given().spec(requestSpec) .body(ruleChain) .post("/api/ruleChain") @@ -239,7 +245,8 @@ public class TestRestClient { .then() .statusCode(HTTP_OK) .extract() - .as(new TypeRef>() {}); + .as(new TypeRef>() { + }); } public JsonNode postServerSideRpc(DeviceId deviceId, JsonNode serverRpcPayload) { @@ -252,6 +259,35 @@ public class TestRestClient { .as(JsonNode.class); } + public Customer postCustomer(Customer customer) { + return given().spec(requestSpec) + .body(customer) + .post("/api/customer") + .then() + .statusCode(HTTP_OK) + .extract() + .as(Customer.class); + } + + public void deleteCustomer(CustomerId customerId) { + given().spec(requestSpec) + .delete("/api/customer/{customerId}", customerId.getId()) + .then() + .statusCode(HTTP_OK); + } + + public PageData getCustomers(PageLink pageLink) { + Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); + return given().spec(requestSpec).queryParams(params) + .get("/api/customers") + .then() + .statusCode(HTTP_OK) + .extract() + .as(new TypeRef>() { + }); + } + public String getToken() { return token; } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttClientTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttClientTest.java index 55dd432644..03271e629a 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttClientTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/connectivity/MqttClientTest.java @@ -326,7 +326,7 @@ public class MqttClientTest extends AbstractContainerTest { RuleChain newRuleChain = new RuleChain(); newRuleChain.setName("testRuleChain"); - RuleChain ruleChain = testRestClient.postRootRuleChain(newRuleChain); + RuleChain ruleChain = testRestClient.postRuleChain(newRuleChain); JsonNode configuration = mapper.readTree(this.getClass().getClassLoader().getResourceAsStream("RpcResponseRuleChainMetadata.json")); RuleChainMetaData ruleChainMetaData = new RuleChainMetaData(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java index 8e8a15c5af..9e32d6e917 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractBasePage.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.base; import lombok.SneakyThrows; @@ -9,33 +24,22 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.thingsboard.rest.client.RestClient; -import org.thingsboard.server.common.data.page.PageLink; -import org.thingsboard.server.msa.ui.utils.Const; import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Random; @Slf4j -abstract public class BasePage extends Base { +abstract public class AbstractBasePage { protected WebDriver driver; protected WebDriverWait wait; protected Actions actions; - protected RestClient client; - protected PageLink pageLink; - public BasePage(WebDriver driver) { + public AbstractBasePage(WebDriver driver) { this.driver = driver; this.wait = new WebDriverWait(driver, Duration.ofMillis(5000)); this.actions = new Actions(driver); - try { - client = new RestClient(Const.URL); - client.login(Const.TENANT_EMAIL, Const.TENANT_PASSWORD); - pageLink = new PageLink(10); - } catch (Exception e) { - log.info("Can't login"); - } } @SneakyThrows @@ -126,4 +130,14 @@ abstract public class BasePage extends Base { ArrayList tabs = new ArrayList<>(driver.getWindowHandles()); driver.switchTo().window(tabs.get(tabNumber - 1)); } + + public static long getRandomNumber() { + return System.currentTimeMillis(); + } + + public static char getRandomSymbol() { + Random rand = new Random(); + String s = "~`!@#$^&*()_+=-"; + return s.charAt(rand.nextInt(s.length())); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java index 4e5d0d5ead..4079ec264c 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDiverBaseTest.java @@ -1,10 +1,27 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.base; +import com.google.common.io.Files; import io.github.bonigarcia.wdm.WebDriverManager; +import io.qameta.allure.Attachment; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriverException; +import org.apache.commons.io.FileUtils; +import org.openqa.selenium.*; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -12,20 +29,27 @@ import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Listeners; -import org.thingsboard.server.msa.TestListener; -import org.thingsboard.server.msa.ui.listeners.RetryTestListener; +import org.thingsboard.server.common.data.Customer; +import org.thingsboard.server.common.data.page.PageLink; +import org.thingsboard.server.common.data.rule.RuleChain; +import org.thingsboard.server.msa.AbstractContainerTest; +import org.thingsboard.server.msa.ui.listeners.TestListener; +import java.io.File; import java.time.Duration; +import java.util.stream.Collectors; @Slf4j -@Listeners({TestListener.class, RetryTestListener.class}) -abstract public class DiverBaseTest extends Base { - protected WebDriver driver; +@Listeners(TestListener.class) +abstract public class AbstractDiverBaseTest extends AbstractContainerTest { + protected WebDriver driver; private final Dimension dimension = new Dimension(WIDTH, HEIGHT); private static final int WIDTH = 1680; private static final int HEIGHT = 1050; private static final boolean HEADLESS = false; + protected static final PageLink pageLink = new PageLink(10); + @BeforeMethod public void openBrowser() { @@ -63,7 +87,7 @@ abstract public class DiverBaseTest extends Base { } protected boolean urlContains(String urlPath) { - WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(10000)); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(5000)); try { wait.until(ExpectedConditions.urlContains(urlPath)); } catch (WebDriverException e) { @@ -71,4 +95,22 @@ abstract public class DiverBaseTest extends Base { } return driver.getCurrentUrl().contains(urlPath); } + + public static RuleChain getRuleChainByName(String name) { + return testRestClient.getRuleChains(pageLink).getData().stream() + .filter(s -> s.getName().equals(name)).collect(Collectors.toList()).get(0); + } + + public static Customer getCustomerByName(String name) { + return testRestClient.getCustomers(pageLink).getData().stream() + .filter(x -> x.getName().equals(name)).collect(Collectors.toList()).get(0); + } + + @SneakyThrows + @Attachment(value = "Page screenshot", type = "image/png") + public static byte[] captureScreen(WebDriver driver, String dirPath) { + File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(screenshot, new File("./target/allure-results/screenshots/" + dirPath + "//" + screenshot.getName())); + return Files.toByteArray(screenshot); + } } \ No newline at end of file diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java index 30b157f13d..bc3f88d99e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryAnalyzer.java @@ -1,4 +1,19 @@ -package listeners; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.listeners; import org.testng.IRetryAnalyzer; import org.testng.ITestResult; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java index 6083781820..0411083f87 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/RetryTestListener.java @@ -1,4 +1,19 @@ -package listeners; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.listeners; import org.testng.IAnnotationTransformer; import org.testng.annotations.ITestAnnotation; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java index dec83f374b..90ae18bec4 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/listeners/TestListener.java @@ -1,16 +1,33 @@ -package listeners; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.listeners; + -import base.Base; -import base.TestInit; import io.qameta.allure.Allure; import lombok.extern.slf4j.Slf4j; import org.openqa.selenium.WebDriver; import org.testng.ITestContext; import org.testng.ITestListener; import org.testng.ITestResult; +import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; + +import static org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest.captureScreen; @Slf4j -public class TestListener extends Base implements ITestListener { +public class TestListener implements ITestListener { WebDriver driver; @@ -20,7 +37,7 @@ public class TestListener extends Base implements ITestListener { Allure.getLifecycle().updateTestCase((t) -> { t.setStatusDetails(t.getStatusDetails().setMessage(str)); }); - driver = ((TestInit) tr.getInstance()).getDriver(); + driver = ((AbstractDiverBaseTest) tr.getInstance()).getDriver(); captureScreen(driver, "success"); } @@ -33,7 +50,7 @@ public class TestListener extends Base implements ITestListener { t.setStatusDetails(t.getStatusDetails().setMessage(str)); t.setStatusDetails(t.getStatusDetails().setMessage(str1)); }); - driver = ((TestInit) tr.getInstance()).getDriver(); + driver = ((AbstractDiverBaseTest) tr.getInstance()).getDriver(); captureScreen(driver, "failure"); } @@ -46,7 +63,7 @@ public class TestListener extends Base implements ITestListener { t.setStatusDetails(t.getStatusDetails().setMessage(str)); t.setStatusDetails(t.getStatusDetails().setMessage(str1)); }); - driver = ((TestInit) tr.getInstance()).getDriver(); + driver = ((AbstractDiverBaseTest) tr.getInstance()).getDriver(); captureScreen(driver, "skipped"); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java index dcb513ab71..e10fb7d1ed 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageElements.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; @@ -5,8 +20,8 @@ import org.openqa.selenium.WebElement; import java.util.List; -public class CustomerPageElementsAbstract extends OtherPageElementsHelperAbstract { - public CustomerPageElementsAbstract(WebDriver driver) { +public class CustomerPageElements extends OtherPageElementsHelper { + public CustomerPageElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java index 13d6a26077..9956966a16 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/CustomerPageHelper.java @@ -1,17 +1,28 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import lombok.extern.slf4j.Slf4j; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; -import org.thingsboard.server.common.data.Customer; -import org.thingsboard.server.common.data.page.PageData; - -import java.util.stream.Collectors; @Slf4j -public class CustomerPageHelperAbstract extends CustomerPageElementsAbstract { - public CustomerPageHelperAbstract(WebDriver driver) { +public class CustomerPageHelper extends CustomerPageElements { + public CustomerPageHelper(WebDriver driver) { super(driver); } @@ -84,33 +95,6 @@ public class CustomerPageHelperAbstract extends CustomerPageElementsAbstract { return customerCity; } - public void createCustomer(String entityName) { - try { - PageData tenantCustomer; - tenantCustomer = client.getCustomers(pageLink); - Customer customer = new Customer(); - customer.setTitle(entityName); - client.saveCustomer(customer); - tenantCustomer.getData().add(customer); - } catch (Exception e) { - log.info("Can't create!"); - } - } - - public void deleteCustomer(String entityName) { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getCustomers(pageLink); - try { - client.deleteCustomer(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); - } catch (Exception e) { - client.deleteCustomer(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(1).getId()); - } - } catch (Exception e) { - log.info("Can't delete!"); - } - } - public void changeTitleEditMenu(String newTitle) { titleFieldEntityView().clear(); wait.until(ExpectedConditions.textToBe(By.xpath(String.format(INPUT_FIELD, INPUT_FIELD_NAME_TITLE)), "")); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java index 9e2595ed3c..80bd3780c7 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageElements.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; @@ -5,8 +20,8 @@ import org.openqa.selenium.WebElement; import java.util.List; -public class DashboardPageElementsAbstract extends OtherPageElementsHelperAbstract { - public DashboardPageElementsAbstract(WebDriver driver) { +public class DashboardPageElements extends OtherPageElementsHelper { + public DashboardPageElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java index 7bf8956542..1b4ae6dfa9 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DashboardPageHelper.java @@ -1,9 +1,24 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; -public class DashboardPageHelperAbstract extends DashboardPageElementsAbstract { - public DashboardPageHelperAbstract(WebDriver driver) { +public class DashboardPageHelper extends DashboardPageElements { + public DashboardPageHelper(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java index 54239e2971..b6a2f09513 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageElements.java @@ -1,11 +1,26 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.thingsboard.server.msa.ui.base.AbstractBasePage; -public class LoginPageElementsAbstract extends AbstractBasePage { - public LoginPageElementsAbstract(WebDriver driver) { +public class LoginPageElements extends AbstractBasePage { + public LoginPageElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java index a39b507882..e59d07e455 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/LoginPageHelper.java @@ -1,10 +1,25 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; import org.thingsboard.server.msa.ui.utils.Const; -public class LoginPageHelperAbstract extends LoginPageElementsAbstract { - public LoginPageHelperAbstract(WebDriver driver) { +public class LoginPageHelper extends LoginPageElements { + public LoginPageHelper(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java index 521758ea41..7fa0bd7468 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageElements.java @@ -1,11 +1,26 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.thingsboard.server.msa.ui.base.AbstractBasePage; -public class OpenRuleChainPageElementsAbstract extends AbstractBasePage { - public OpenRuleChainPageElementsAbstract(WebDriver driver) { +public class OpenRuleChainPageElements extends AbstractBasePage { + public OpenRuleChainPageElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java index ccaaedab28..0017396a8a 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OpenRuleChainPageHelper.java @@ -1,9 +1,24 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; -public class OpenRuleChainPageHelperAbstract extends OpenRuleChainPageElementsAbstract { - public OpenRuleChainPageHelperAbstract(WebDriver driver) { +public class OpenRuleChainPageHelper extends OpenRuleChainPageElements { + public OpenRuleChainPageHelper(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java index bf4be2dae2..1f3ecfa208 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElements.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.WebDriver; @@ -6,8 +21,8 @@ import org.thingsboard.server.msa.ui.base.AbstractBasePage; import java.util.List; -public class OtherPageElementsAbstract extends AbstractBasePage { - public OtherPageElementsAbstract(WebDriver driver) { +public class OtherPageElements extends AbstractBasePage { + public OtherPageElements(WebDriver driver) { super(driver); } @@ -103,6 +118,7 @@ public class OtherPageElementsAbstract extends AbstractBasePage { } public WebElement editPencilBtn() { + waitUntilVisibilityOfElementsLocated(EDIT_PENCIL_BTN); return waitUntilElementToBeClickable(EDIT_PENCIL_BTN); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java index dc4a41e9b9..dbef06e7fe 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/OtherPageElementsHelper.java @@ -1,11 +1,26 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; -public class OtherPageElementsHelperAbstract extends OtherPageElementsAbstract { - public OtherPageElementsHelperAbstract(WebDriver driver) { +public class OtherPageElementsHelper extends OtherPageElements { + public OtherPageElementsHelper(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java index 4a378bb1c3..eee95edcae 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageElements.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import org.openqa.selenium.By; @@ -6,8 +21,8 @@ import org.openqa.selenium.WebElement; import java.util.List; -public class RuleChainsPageElementsAbstract extends OtherPageElementsHelperAbstract { - public RuleChainsPageElementsAbstract(WebDriver driver) { +public class RuleChainsPageElements extends OtherPageElementsHelper { + public RuleChainsPageElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java index 9d23660b11..a6a7148bc4 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/RuleChainsPageHelper.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.pages; import lombok.extern.slf4j.Slf4j; @@ -5,17 +20,14 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.testng.Assert; -import org.thingsboard.server.common.data.page.PageData; -import org.thingsboard.server.common.data.rule.RuleChain; import java.util.ArrayList; import java.util.Collections; import java.util.Random; -import java.util.stream.Collectors; @Slf4j -public class RuleChainsPageHelperAbstract extends RuleChainsPageElementsAbstract { - public RuleChainsPageHelperAbstract(WebDriver driver) { +public class RuleChainsPageHelper extends RuleChainsPageElements { + public RuleChainsPageHelper(WebDriver driver) { super(driver); } @@ -52,74 +64,6 @@ public class RuleChainsPageHelperAbstract extends RuleChainsPageElementsAbstract return this.ruleChainName; } - public String getRuleChainId(String entityName) { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - return String.valueOf(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); - } - - public void deleteRuleChain(String entityName) { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - try { - client.deleteRuleChain(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(0).getId()); - } catch (Exception e) { - client.deleteRuleChain(tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).get(1).getId()); - } - } catch (Exception e) { - log.info("Can't delete!"); - } - } - - public void deleteAllRuleChain(String entityName) { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - tenantRuleChains.getData().stream().filter(s -> s.getName().equals(entityName)).collect(Collectors.toList()).forEach(x -> client.deleteRuleChain(x.getId())); - } catch (Exception e) { - log.info("Can't delete!"); - } - } - - public void createRuleChain(String entityName) { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - RuleChain ruleChain = new RuleChain(); - ruleChain.setName(entityName); - client.saveRuleChain(ruleChain); - tenantRuleChains.getData().add(ruleChain); - } catch (Exception e) { - log.info("Can't create!"); - } - } - - public void makeRoot() { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - tenantRuleChains.getData().stream().filter(s -> s.getName().equals("Root Rule Chain")).collect(Collectors.toList()).forEach(x -> client.setRootRuleChain(x.getId())); - } catch (Exception e) { - log.info("Can't make root!"); - } - } - - public void createRuleChains(String entityName, int count) { - try { - PageData tenantRuleChains; - tenantRuleChains = client.getRuleChains(pageLink); - RuleChain ruleChain = new RuleChain(); - for (int i = 0; i < count; i++) { - ruleChain.setName(entityName); - client.saveRuleChain(ruleChain); - tenantRuleChains.getData().add(ruleChain); - } - } catch (Exception e) { - log.info("Can't create!"); - } - } - public String deleteRuleChainFromView(String ruleChainName) { String s = ""; if (deleteBtnFromView() != null) { @@ -149,8 +93,8 @@ public class RuleChainsPageHelperAbstract extends RuleChainsPageElementsAbstract Assert.assertFalse(driver.findElement(By.xpath(getCheckbox(entityName))).isDisplayed()); } - public void assertDeleteBtnInRootRuleChainIsNotDisplayed() { - Assert.assertFalse(driver.findElement(By.xpath(getDeleteRuleChainFromViewBtn())).isDisplayed()); + public boolean deleteBtnInRootRuleChainIsNotDisplayed() { + return wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(getDeleteRuleChainFromViewBtn()))); } public boolean ruleChainsIsNotPresent(String ruleChainName) { diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java index 1e1484be7b..902966a1ac 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/SideBarMenuViewElements.java @@ -1,10 +1,25 @@ -package pages; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.pages; -import base.BasePage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.thingsboard.server.msa.ui.base.AbstractBasePage; -public class SideBarMenuViewElements extends BasePage { +public class SideBarMenuViewElements extends AbstractBasePage { public SideBarMenuViewElements(WebDriver driver) { super(driver); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java index c59b950862..9a604416d9 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CreateCustomerTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -6,56 +21,57 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.*; -public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class CreateCustomerTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; private String customerName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @AfterMethod public void delete() { if (customerName != null) { - customerPage.deleteCustomer(customerName); + testRestClient.deleteCustomer(getCustomerByName(customerName).getId()); customerName = null; } } @Test(priority = 10, groups = "smoke") - @Description("Can click on Add after specifying the name (text/numbers /special characters)") + @Description public void createCustomer() { - String customerName = ENTITY_NAME; + customerName = ENTITY_NAME; sideBarMenuView.customerBtn().click(); customerPage.plusBtn().click(); customerPage.titleFieldAddEntityView().sendKeys(customerName); customerPage.addBtnC().click(); customerPage.refreshBtn().click(); - this.customerName = customerName; Assert.assertNotNull(customerPage.customer(customerName)); Assert.assertTrue(customerPage.customer(customerName).isDisplayed()); } @Test(priority = 20, groups = "smoke") + @Description public void createCustomerWithFullInformation() { - String customerName = ENTITY_NAME; + customerName = ENTITY_NAME; String text = "Text"; String email = "email@mail.com"; - String number = "2015550123"; + String number = "12015550123"; sideBarMenuView.customerBtn().click(); customerPage.plusBtn().click(); @@ -74,7 +90,6 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { customerPage.setCustomerCountry(customerName); customerPage.setCustomerCity(customerName); customerPage.entity(customerName).click(); - this.customerName = customerName; Assert.assertNotNull(customerPage.customer(customerName)); Assert.assertEquals(customerPage.entityViewTitle().getText(), customerName); @@ -86,7 +101,7 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { Assert.assertEquals(customerPage.zipEntityView().getAttribute("value"), text); Assert.assertEquals(customerPage.addressEntityView().getAttribute("value"), text); Assert.assertEquals(customerPage.address2EntityView().getAttribute("value"), text); - Assert.assertEquals(customerPage.phoneNumberEntityView().getAttribute("value"), "+1" + number); + Assert.assertEquals(customerPage.phoneNumberEntityView().getAttribute("value"), "+" + number); Assert.assertEquals(customerPage.emailEntityView().getAttribute("value"), email); Assert.assertEquals(customerPage.getCustomerEmail(), email); Assert.assertEquals(customerPage.getCustomerCountry(), customerPage.getCountry()); @@ -94,7 +109,7 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("Can`t add customer without the name (empty field or just space)") + @Description public void createCustomerWithoutName() { sideBarMenuView.customerBtn().click(); customerPage.plusBtn().click(); @@ -103,7 +118,7 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description() + @Description public void createCustomerWithOnlySpace() { sideBarMenuView.customerBtn().click(); customerPage.plusBtn().click(); @@ -118,7 +133,7 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("Can't create a customer with the same name") + @Description public void createCustomerSameName() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -135,22 +150,21 @@ public class CreateCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("Can click on Add after specifying the name (text/numbers /special characters)") + @Description public void createCustomerWithoutRefresh() { - String customerName = ENTITY_NAME; + customerName = ENTITY_NAME; sideBarMenuView.customerBtn().click(); customerPage.plusBtn().click(); customerPage.titleFieldAddEntityView().sendKeys(customerName); customerPage.addBtnC().click(); - this.customerName = customerName; Assert.assertNotNull(customerPage.customer(customerName)); Assert.assertTrue(customerPage.customer(customerName).isDisplayed()); } @Test(priority = 40, groups = "smoke") - @Description("Question mark icon leads to rule chain documentation (PE)") + @Description public void documentation() { String urlPath = "docs/user-guide/ui/customers/"; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java index 36297cbf3a..2bfd157773 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/CustomerEditMenuTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -6,62 +21,64 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.DashboardPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.DashboardPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import org.thingsboard.server.msa.ui.utils.DataProviderCredential; import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomNumber; import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultCustomerPrototype; -public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class CustomerEditMenuTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; - private DashboardPageHelperAbstract dashboardPage; + private CustomerPageHelper customerPage; + private DashboardPageHelper dashboardPage; private String customerName; + @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); - dashboardPage = new DashboardPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); + dashboardPage = new DashboardPageHelper(driver); } @AfterMethod public void delete() { if (customerName != null) { - customerPage.deleteCustomer(customerName); + testRestClient.deleteCustomer(getCustomerByName(customerName).getId()); customerName = null; } } @Test(priority = 10, groups = "smoke") - @Description("Can click by pencil icon and edit the title (change the title) and save the changes. All changes have been applied") + @Description public void changeTitle() { - customerPage.createCustomer(ENTITY_NAME); - String title = "Changed" + getRandomNumber(); + customerName = "Changed" + getRandomNumber(); + testRestClient.postCustomer(defaultCustomerPrototype(ENTITY_NAME)); sideBarMenuView.customerBtn().click(); customerPage.entityTitles().get(0).click(); customerPage.setHeaderName(); String titleBefore = customerPage.getHeaderName(); customerPage.editPencilBtn().click(); - customerPage.changeTitleEditMenu(title); + customerPage.changeTitleEditMenu(customerName); customerPage.doneBtnEditView().click(); customerPage.setHeaderName(); String titleAfter = customerPage.getHeaderName(); - customerName = title; Assert.assertNotEquals(titleBefore, titleAfter); - Assert.assertEquals(titleAfter, title); + Assert.assertEquals(titleAfter, customerName); } @Test(priority = 20, groups = "smoke") - @Description("Can`t delete the title and save changes") + @Description public void deleteTitle() { sideBarMenuView.customerBtn().click(); customerPage.entityTitles().get(0).click(); @@ -72,7 +89,7 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can`t save just a space in the title") + @Description public void saveOnlyWithSpace() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -89,10 +106,10 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can write/change/delete the descriptionEntityView and save the changes. All changes have been applied") + @Description public void editDescription() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); String description = "Description"; sideBarMenuView.customerBtn().click(); @@ -108,7 +125,6 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest customerPage.editPencilBtn().click(); customerPage.changeDescription(""); customerPage.doneBtnEditView().click(); - customerName = title; Assert.assertEquals(description, description1); Assert.assertEquals(description + description, description2); @@ -118,24 +134,23 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest @Test(priority = 20, groups = "smoke") @Description public void assignedDashboardFromDashboard() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); sideBarMenuView.dashboardBtn().click(); dashboardPage.setDashboardTitle(); dashboardPage.assignedBtn(dashboardPage.getDashboardTitle()).click(); - dashboardPage.assignedCustomer(title); + dashboardPage.assignedCustomer(customerName); sideBarMenuView.customerBtn().click(); - customerPage.entity(title).click(); + customerPage.entity(customerName).click(); customerPage.editPencilBtn().click(); customerPage.chooseDashboard(); customerPage.doneBtnEditView().click(); customerPage.setDashboardFromView(); customerPage.closeEntityViewBtn().click(); - customerPage.manageCustomersUserBtn(title).click(); + customerPage.manageCustomersUserBtn(customerName).click(); customerPage.createCustomersUser(); customerPage.userLoginBtn().click(); - customerName = title; Assert.assertNotNull(customerPage.usersWidget()); Assert.assertTrue(customerPage.usersWidget().isDisplayed()); @@ -145,23 +160,22 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest @Test(priority = 20, groups = "smoke") @Description public void assignedDashboard() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); sideBarMenuView.customerBtn().click(); - customerPage.manageCustomersDashboardsBtn(title).click(); + customerPage.manageCustomersDashboardsBtn(customerName).click(); customerPage.assignedDashboard(); sideBarMenuView.customerBtn().click(); - customerPage.entity(title).click(); + customerPage.entity(customerName).click(); customerPage.editPencilBtn().click(); customerPage.chooseDashboard(); customerPage.doneBtnEditView().click(); customerPage.setDashboardFromView(); customerPage.closeEntityViewBtn().click(); - customerPage.manageCustomersUserBtn(title).click(); + customerPage.manageCustomersUserBtn(customerName).click(); customerPage.createCustomersUser(); customerPage.userLoginBtn().click(); - customerName = title; Assert.assertNotNull(customerPage.usersWidget()); Assert.assertTrue(customerPage.usersWidget().isDisplayed()); @@ -171,24 +185,23 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest @Test(priority = 20, groups = "smoke") @Description public void assignedDashboardWithoutHide() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); sideBarMenuView.customerBtn().click(); - customerPage.manageCustomersDashboardsBtn(title).click(); + customerPage.manageCustomersDashboardsBtn(customerName).click(); customerPage.assignedDashboard(); sideBarMenuView.customerBtn().click(); - customerPage.entity(title).click(); + customerPage.entity(customerName).click(); customerPage.editPencilBtn().click(); customerPage.chooseDashboard(); customerPage.hideHomeDashboardToolbarCheckbox().click(); customerPage.doneBtnEditView().click(); customerPage.setDashboardFromView(); customerPage.closeEntityViewBtn().click(); - customerPage.manageCustomersUserBtn(title).click(); + customerPage.manageCustomersUserBtn(customerName).click(); customerPage.createCustomersUser(); customerPage.userLoginBtn().click(); - customerName = title; Assert.assertNotNull(customerPage.usersWidget()); Assert.assertTrue(customerPage.usersWidget().isDisplayed()); @@ -204,8 +217,8 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest @Test(priority = 20, groups = "smoke") @Description public void addPhoneNumber() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); String number = "2015550123"; sideBarMenuView.customerBtn().click(); @@ -213,7 +226,6 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest customerPage.editPencilBtn().click(); customerPage.phoneNumberEntityView().sendKeys(number); customerPage.doneBtnEditView().click(); - customerName = title; Assert.assertTrue(customerPage.phoneNumberEntityView().getAttribute("value").contains(number)); } @@ -235,9 +247,11 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 30, groups = "smoke") + @Description public void addAllInformation() { - String title = ENTITY_NAME; - customerPage.createCustomer(title); + customerName = ENTITY_NAME; + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); + ; String text = "Text"; String email = "email@mail.com"; String number = "2015550123"; @@ -255,7 +269,6 @@ public class CustomerEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest customerPage.phoneNumberEntityView().sendKeys(number); customerPage.emailEntityView().sendKeys(email); customerPage.doneBtnEditView().click(); - customerName = title; Assert.assertEquals(customerPage.countrySelectMenuEntityView().getText(), customerPage.getCountry()); Assert.assertEquals(customerPage.descriptionEntityView().getAttribute("value"), text); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java index 7a22422777..27e8605926 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteCustomerTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,34 +20,35 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; -import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultCustomerPrototype; -public class DeleteCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class DeleteCustomerTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; - private RuleChainsPageHelperAbstract ruleChainsPage; + private CustomerPageHelper customerPage; + private RuleChainsPageHelper ruleChainsPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @Test(priority = 10, groups = "smoke") - @Description("Can remove the customer by clicking on the trash can icon in the right corner") + @Description public void removeCustomerByRightSideBtn() { String customer = ENTITY_NAME; - customerPage.createCustomer(customer); + testRestClient.postCustomer(defaultCustomerPrototype(customer)); sideBarMenuView.customerBtn().click(); String deletedCustomer = customerPage.deleteRuleChainTrash(customer); @@ -42,10 +58,10 @@ public class DeleteCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("Can mark the customer in the checkbox and then click on the trash can icon in the menu that appears at the top") + @Description public void removeSelectedCustomer() { String customerName = ENTITY_NAME; - customerPage.createCustomer(customerName); + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); sideBarMenuView.customerBtn().click(); String deletedCustomer = customerPage.deleteSelected(customerName); @@ -55,10 +71,10 @@ public class DeleteCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("Can click on the name of the rule chain and click on the 'Delete customer' button") + @Description public void removeFromCustomerView() { String customerName = ENTITY_NAME; - customerPage.createCustomer(customerName); + testRestClient.postCustomer(defaultCustomerPrototype(customerName)); sideBarMenuView.customerBtn().click(); customerPage.entity(customerName).click(); @@ -69,10 +85,10 @@ public class DeleteCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 20, groups = "smoke") - @Description("The rule chain is deleted immediately after clicking remove (no need to refresh the page)") + @Description public void removeCustomerByRightSideBtnWithoutRefresh() { String customer = ENTITY_NAME; - customerPage.createCustomer(customer); + testRestClient.postCustomer(defaultCustomerPrototype(customer)); sideBarMenuView.customerBtn().click(); String deletedCustomer = customerPage.deleteRuleChainTrash(customer); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java index 9847f1b763..138c563631 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/DeleteSeveralCustomerTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,41 +20,37 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; -import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultCustomerPrototype; -public class DeleteSeveralCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class DeleteSeveralCustomerTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(priority = 10, groups = "smoke") - @Description("Can mark several customers in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + @Description public void canDeleteSeveralCustomersByTopBtn() { String title1 = ENTITY_NAME + "1"; String title2 = ENTITY_NAME + "2"; - int count = 2; - customerPage.createCustomer(title1); - customerPage.createCustomer(title2); + testRestClient.postCustomer(defaultCustomerPrototype(title1)); + testRestClient.postCustomer(defaultCustomerPrototype(title2)); sideBarMenuView.customerBtn().click(); - customerPage.clickOnCheckBoxes(count); - - Assert.assertEquals(customerPage.markCheckbox().size(), count); - customerPage.markCheckbox().forEach(x -> Assert.assertTrue(x.isDisplayed())); - + customerPage.clickOnCheckBoxes(2); customerPage.deleteSelectedBtn().click(); customerPage.warningPopUpYesBtn().click(); customerPage.refreshBtn().click(); @@ -49,7 +60,7 @@ public class DeleteSeveralCustomerAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 10, groups = "smoke") - @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + @Description public void selectAllCustomers() { sideBarMenuView.customerBtn().click(); customerPage.selectAllCheckBox().click(); @@ -61,17 +72,15 @@ public class DeleteSeveralCustomerAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 30, groups = "smoke") - @Description("The rule chains are deleted immediately after clicking remove (no need to refresh the page)") + @Description public void deleteSeveralCustomersByTopBtnWithoutRefresh() { String title1 = ENTITY_NAME + "1"; String title2 = ENTITY_NAME + "2"; - int count = 2; - customerPage.createCustomer(title1); - customerPage.createCustomer(title2); + testRestClient.postCustomer(defaultCustomerPrototype(title1)); + testRestClient.postCustomer(defaultCustomerPrototype(title2)); sideBarMenuView.customerBtn().click(); - customerPage.clickOnCheckBoxes(count); - + customerPage.clickOnCheckBoxes(2); customerPage.deleteSelectedBtn().click(); customerPage.warningPopUpYesBtn().click(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java index 785ee8c813..7b85771c23 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersAssetsTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,28 +20,28 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.URL; -public class ManageCustomersAssetsAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class ManageCustomersAssetsTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; private final String manage = "Assets"; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(groups = "smoke") - @Description("Can go to the 'Customer assets' window by clicking on the 'Manage customer users' icon in the right corner") + @Description public void openWindowByRightCornerBtn() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -39,7 +54,7 @@ public class ManageCustomersAssetsAbstractDiverBaseTest extends AbstractDiverBas } @Test(groups = "smoke") - @Description("Can go to the 'Customer Assets' window by clicking on the name/row of the customer and click on the 'Manage users' button") + @Description public void openWindowByView() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java index 68fe281d0b..9ac2986fd0 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDashboardsTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,27 +20,27 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.URL; -public class ManageCustomersDashboardsAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class ManageCustomersDashboardsTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; private final String manage = "Dashboards"; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(groups = "smoke") - @Description("Can go to the 'Customer Dashboards' window by clicking on the 'Manage customer users' icon in the right corner") + @Description public void openWindowByRightCornerBtn() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -38,7 +53,7 @@ public class ManageCustomersDashboardsAbstractDiverBaseTest extends AbstractDive } @Test(groups = "smoke") - @Description("Can go to the 'Customer Dashboards' window by clicking on the name/row of the customer and click on the 'Manage users' button") + @Description public void openWindowByView() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java index d62b5fe4cf..30b451899e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersDevicesTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,27 +20,27 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.URL; -public class ManageCustomersDevicesAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class ManageCustomersDevicesTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; private final String manage = "Devices"; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(groups = "smoke") - @Description("Can go to the 'Customer Devices' window by clicking on the 'Manage customer users' icon in the right corner") + @Description public void openWindowByRightCornerBtn() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -38,7 +53,7 @@ public class ManageCustomersDevicesAbstractDiverBaseTest extends AbstractDiverBa } @Test(groups = "smoke") - @Description("Can go to the 'Customer Devices' window by clicking on the name/row of the customer and click on the 'Manage users' button") + @Description public void openWindowByView() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java index ff0ac3e4f1..044f809f77 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersEdgesTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,28 +20,28 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.URL; -public class ManageCustomersEdgesAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class ManageCustomersEdgesTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; - private String iconText = "Edge instances"; + private CustomerPageHelper customerPage; + private final String iconText = "Edge instances"; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(groups = "smoke") - @Description("Can go to the 'Customer Edges' window by clicking on the 'Manage customer users' icon in the right corner") + @Description public void openWindowByRightCornerBtn() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -39,7 +54,7 @@ public class ManageCustomersEdgesAbstractDiverBaseTest extends AbstractDiverBase } @Test(groups = "smoke") - @Description("Can go to the 'Customer Edges' window by clicking on the name/row of the customer and click on the 'Manage users' button") + @Description public void openWindowByView() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java index 855e227b5e..42d03bda1e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/ManageCustomersUsersTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -5,28 +20,28 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.URL; -public class ManageCustomersUsersAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class ManageCustomersUsersTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; - private String iconText = "Customer Users"; + private CustomerPageHelper customerPage; + private final String iconText = "Customer Users"; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @Test(groups = "smoke") - @Description("Can go to the 'Customer Users' window by clicking on the 'Manage customer users' icon in the right corner") + @Description public void openWindowByRightCornerBtn() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); @@ -39,7 +54,7 @@ public class ManageCustomersUsersAbstractDiverBaseTest extends AbstractDiverBase } @Test(groups = "smoke") - @Description("Can go to the 'Customer Users' window by clicking on the name/row of the customer and click on the 'Manage users' button") + @Description public void openWindowByView() { sideBarMenuView.customerBtn().click(); customerPage.setCustomerName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java index 6db022da62..97a4c6f85f 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SearchCustomerTest.java @@ -1,39 +1,49 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; import org.testng.Assert; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import org.thingsboard.server.msa.ui.utils.DataProviderCredential; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultCustomerPrototype; -public class SearchCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class SearchCustomerTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; - private String entityName; + private CustomerPageHelper customerPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); - } - - @AfterMethod - public void deleteCustomer() { - customerPage.deleteCustomer(entityName); + customerPage = new CustomerPageHelper(driver); } @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "customerNameForSearchByFirstAndSecondWord") - @Description("Can search by the first/second word of the name") + @Description public void searchFirstWord(String namePath) { sideBarMenuView.customerBtn().click(); customerPage.searchEntity(namePath); @@ -42,15 +52,17 @@ public class SearchCustomerAbstractDiverBaseTest extends AbstractDiverBaseTest { } @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSearchBySymbolAndNumber") - @Description("Can search by number/symbol") + @Description public void searchNumber(String name, String namePath) { - customerPage.createCustomer(name); + testRestClient.postCustomer(defaultCustomerPrototype(name)); sideBarMenuView.customerBtn().click(); customerPage.searchEntity(namePath); customerPage.setCustomerName(); - entityName = name; + boolean customerNameContainsPath = customerPage.getCustomerName().contains(namePath); + + testRestClient.deleteCustomer(getCustomerByName(name).getId()); - Assert.assertTrue(customerPage.getCustomerName().contains(namePath)); + Assert.assertTrue(customerNameContainsPath); } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java index 8ab49b6c68..3a71ca5ddb 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/customerSmoke/SortByNameTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.customerSmoke; import io.qameta.allure.Description; @@ -6,30 +21,32 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.CustomerPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import org.thingsboard.server.msa.ui.utils.DataProviderCredential; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultCustomerPrototype; -public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class SortByNameTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private CustomerPageHelperAbstract customerPage; + private CustomerPageHelper customerPage; private String customerName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - customerPage = new CustomerPageHelperAbstract(driver); + customerPage = new CustomerPageHelper(driver); } @AfterMethod public void delete() { if (customerName != null) { - customerPage.deleteCustomer(customerName); + testRestClient.deleteCustomer(getCustomerByName(customerName).getId()); customerName = null; } } @@ -37,12 +54,12 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") @Description public void specialCharacterUp(String title) { - customerPage.createCustomer(title); + customerName = title; + testRestClient.postCustomer(defaultCustomerPrototype(title)); sideBarMenuView.customerBtn().click(); customerPage.sortByTitleBtn().click(); customerPage.setCustomerName(); - customerName = title; Assert.assertEquals(customerPage.getCustomerName(), title); } @@ -50,9 +67,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") @Description public void allSortUp(String customer, String customerSymbol, String customerNumber) { - customerPage.createCustomer(customerSymbol); - customerPage.createCustomer(customer); - customerPage.createCustomer(customerNumber); + testRestClient.postCustomer(defaultCustomerPrototype(customerSymbol)); + testRestClient.postCustomer(defaultCustomerPrototype(customer)); + testRestClient.postCustomer(defaultCustomerPrototype(customerNumber)); sideBarMenuView.customerBtn().click(); customerPage.sortByTitleBtn().click(); @@ -67,9 +84,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { boolean secondEquals = secondCustomer.equals(customerNumber); boolean thirdEquals = thirdCustomer.equals(customer); - customerPage.deleteCustomer(customer); - customerPage.deleteCustomer(customerNumber); - customerPage.deleteCustomer(customerSymbol); + testRestClient.deleteCustomer(getCustomerByName(customer).getId()); + testRestClient.deleteCustomer(getCustomerByName(customerNumber).getId()); + testRestClient.deleteCustomer(getCustomerByName(customerSymbol).getId()); Assert.assertTrue(firstEquals); Assert.assertTrue(secondEquals); @@ -79,12 +96,12 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") @Description public void specialCharacterDown(String title) { - customerPage.createCustomer(title); + customerName = title; + testRestClient.postCustomer(defaultCustomerPrototype(title)); sideBarMenuView.customerBtn().click(); customerPage.sortByNameDown(); customerPage.setCustomerName(customerPage.allEntity().size() - 1); - customerName = title; Assert.assertEquals(customerPage.getCustomerName(), title); } @@ -92,9 +109,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") @Description public void allSortDown(String customer, String customerSymbol, String customerNumber) { - customerPage.createCustomer(customerSymbol); - customerPage.createCustomer(customer); - customerPage.createCustomer(customerNumber); + testRestClient.postCustomer(defaultCustomerPrototype(customerSymbol)); + testRestClient.postCustomer(defaultCustomerPrototype(customer)); + testRestClient.postCustomer(defaultCustomerPrototype(customerNumber)); sideBarMenuView.customerBtn().click(); int lastIndex = customerPage.allEntity().size() - 1; @@ -110,9 +127,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { boolean secondEquals = secondCustomer.equals(customerNumber); boolean thirdEquals = thirdCustomer.equals(customer); - customerPage.deleteCustomer(customer); - customerPage.deleteCustomer(customerNumber); - customerPage.deleteCustomer(customerSymbol); + testRestClient.deleteCustomer(getCustomerByName(customer).getId()); + testRestClient.deleteCustomer(getCustomerByName(customerNumber).getId()); + testRestClient.deleteCustomer(getCustomerByName(customerSymbol).getId()); Assert.assertTrue(firstEquals); Assert.assertTrue(secondEquals); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java index 2b05fb8867..a027267469 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainImportTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,17 +21,20 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import java.util.ArrayList; + import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class CreateRuleChainImportTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; - private OpenRuleChainPageHelperAbstract openRuleChainPage; + private RuleChainsPageHelper ruleChainsPage; + private OpenRuleChainPageHelper openRuleChainPage; private final String absolutePathToFileImportRuleChain = getClass().getClassLoader().getResource(IMPORT_RULE_CHAIN_FILE_NAME).getPath(); private final String absolutePathToFileImportTxt = getClass().getClassLoader().getResource(IMPORT_TXT_FILE_NAME).getPath(); private String ruleChainName; @@ -24,22 +42,23 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); - openRuleChainPage = new OpenRuleChainPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); + openRuleChainPage = new OpenRuleChainPageHelper(driver); } @AfterMethod public void delete() { if (ruleChainName != null) { - ruleChainsPage.deleteRuleChain(ruleChainName); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); ruleChainName = null; } } @Test(priority = 10, groups = "smoke") - @Description("Can drop a JSON file and import it") + @Description public void importRuleChain() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openImportRuleChainView(); @@ -50,7 +69,7 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 20, groups = "smoke") - @Description("Can delete a file by clicking on the icon Remove") + @Description public void importRuleChainAndDeleteFile() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openImportRuleChainView(); @@ -63,7 +82,7 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 20, groups = "smoke") - @Description("Can`t Select / drop a file of a different format than JSON") + @Description public void importTxtFile() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openImportRuleChainView(); @@ -74,7 +93,7 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 30, groups = "smoke") - @Description("After clicking on Import - imported rule chain opens (need to save by clicking on the Apply changes icon)") + @Description public void importRuleChainAndSave() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openImportRuleChainView(); @@ -90,9 +109,11 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas } @Test(priority = 40, groups = "smoke") - @Description("Can create a rule chain with the same name") + @Description public void importRuleChainAndSaveWithSameName() { - ruleChainsPage.createRuleChain(IMPORT_RULE_CHAIN_NAME); + ruleChainName = IMPORT_RULE_CHAIN_NAME; + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); + ; sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openImportRuleChainView(); @@ -101,10 +122,16 @@ public class CreateRuleChainImportAbstractDiverBaseTest extends AbstractDiverBas openRuleChainPage.doneBtn().click(); openRuleChainPage.waitUntilDoneBtnDisable(); sideBarMenuView.ruleChainsBtn().click(); - boolean sizeBigger1 = ruleChainsPage.entities(IMPORT_RULE_CHAIN_NAME).size() > 1; - ruleChainsPage.deleteAllRuleChain(IMPORT_RULE_CHAIN_NAME); + boolean entityNotNull = ruleChainsPage.entity(ruleChainName) != null; + boolean entitiesSizeMoreOne = ruleChainsPage.entities(ruleChainName).size() > 1; + ArrayList entityIsDisplayed = new ArrayList<>(); + ruleChainsPage.entities(ruleChainName).forEach(x -> entityIsDisplayed.add(x.isDisplayed())); + + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); - Assert.assertTrue(sizeBigger1); + Assert.assertTrue(entityNotNull); + Assert.assertTrue(entitiesSizeMoreOne); + entityIsDisplayed.forEach(Assert::assertTrue); } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java index 32470c86f9..d3d71a45b0 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/CreateRuleChainTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,54 +21,57 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import java.util.ArrayList; import static org.thingsboard.server.msa.ui.utils.Const.*; -public class CreateRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class CreateRuleChainTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; private String ruleChainName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @AfterMethod public void delete() { if (ruleChainName != null) { - ruleChainsPage.deleteRuleChain(ruleChainName); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); ruleChainName = null; } } @Test(priority = 10, groups = "smoke") - @Description("Can click on Add after specifying the name (text/numbers /special characters)") + @Description public void createRuleChain() { - String ruleChainName = ENTITY_NAME; + ruleChainName = ENTITY_NAME; sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openCreateRuleChainView(); ruleChainsPage.nameField().sendKeys(ruleChainName); ruleChainsPage.addBtnC().click(); ruleChainsPage.refreshBtn().click(); - this.ruleChainName = ruleChainName; Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); Assert.assertTrue(ruleChainsPage.entity(ruleChainName).isDisplayed()); } @Test(priority = 10, groups = "smoke") - @Description() + @Description public void createRuleChainWithDescription() { - String ruleChainName = ENTITY_NAME; + ruleChainName = ENTITY_NAME; sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openCreateRuleChainView(); @@ -63,14 +81,13 @@ public class CreateRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest ruleChainsPage.refreshBtn().click(); ruleChainsPage.entity(ENTITY_NAME).click(); ruleChainsPage.setHeaderName(); - this.ruleChainName = ruleChainName; Assert.assertEquals(ruleChainsPage.getHeaderName(), ruleChainName); Assert.assertEquals(ruleChainsPage.descriptionEntityView().getAttribute("value"), ruleChainName); } @Test(priority = 20, groups = "smoke") - @Description("Can`t add rule chain without the name (empty field or just space)") + @Description public void createRuleChainWithoutName() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openCreateRuleChainView(); @@ -79,7 +96,7 @@ public class CreateRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description() + @Description public void createRuleChainWithOnlySpace() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openCreateRuleChainView(); @@ -94,38 +111,45 @@ public class CreateRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can create a rule chain with the same name") + @Description public void createRuleChainWithSameName() { + ruleChainName = ENTITY_NAME; + testRestClient.postRuleChain(EntityPrototypes.defaultRuleChainPrototype(ruleChainName)); + sideBarMenuView.ruleChainsBtn().click(); - ruleChainsPage.setRuleChainNameWithoutRoot(); ruleChainsPage.openCreateRuleChainView(); - String ruleChainName = ruleChainsPage.getRuleChainName(); ruleChainsPage.nameField().sendKeys(ruleChainName); ruleChainsPage.addBtnC().click(); ruleChainsPage.refreshBtn().click(); - this.ruleChainName = ruleChainName; - Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); - Assert.assertTrue(ruleChainsPage.entities(ruleChainName).size() > 1); + boolean entityNotNull = ruleChainsPage.entity(ruleChainName) != null; + boolean entitiesSizeMoreOne = ruleChainsPage.entities(ruleChainName).size() > 1; + ArrayList entityIsDisplayed = new ArrayList<>(); + ruleChainsPage.entities(ruleChainName).forEach(x -> entityIsDisplayed.add(x.isDisplayed())); + + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); + + Assert.assertTrue(entityNotNull); + Assert.assertTrue(entitiesSizeMoreOne); + entityIsDisplayed.forEach(Assert::assertTrue); } @Test(priority = 30, groups = "smoke") - @Description("After clicking on Add - appears immediately in the list (no need to refresh the page)") + @Description public void createRuleChainWithoutRefresh() { - String ruleChainName = ENTITY_NAME; + ruleChainName = ENTITY_NAME; sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.openCreateRuleChainView(); ruleChainsPage.nameField().sendKeys(ruleChainName); ruleChainsPage.addBtnC().click(); - this.ruleChainName = ruleChainName; Assert.assertNotNull(ruleChainsPage.entity(ruleChainName)); Assert.assertTrue(ruleChainsPage.entity(ruleChainName).isDisplayed()); } @Test(priority = 40, groups = "smoke") - @Description("Question mark icon leads to rule chain documentation (PE)") + @Description public void documentation() { String urlPath = "docs/user-guide/ui/rule-chains/"; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java index f2fe8c7c1c..92da98af1b 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteRuleChainTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -5,41 +20,44 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class DeleteRuleChainTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @Test(priority = 10, groups = "smoke") - @Description("Can remove the rule chain by clicking on the trash can icon in the right corner") + @Description public void removeRuleChainByRightSideBtn() { - ruleChainsPage.createRuleChain(ENTITY_NAME); + String ruleChainName = ENTITY_NAME; + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); - String deletedRuleChain = ruleChainsPage.deleteRuleChainTrash(ENTITY_NAME); + String deletedRuleChain = ruleChainsPage.deleteRuleChainTrash(ruleChainName); ruleChainsPage.refreshBtn().click(); Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); } @Test(priority = 20, groups = "smoke") - @Description("Can mark the rule chain in the checkbox and then click on the trash can icon in the menu that appears at the top") + @Description public void removeSelectedRuleChain() { String ruleChainName = ENTITY_NAME; - ruleChainsPage.createRuleChain(ruleChainName); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); String deletedRuleChain = ruleChainsPage.deleteSelected(ruleChainName); @@ -49,20 +67,21 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can click on the name of the rule chain and click on the 'Delete rule chain' button") + @Description public void removeFromRuleChainView() { - ruleChainsPage.createRuleChain(ENTITY_NAME); + String ruleChainName = ENTITY_NAME; + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.entity(ENTITY_NAME).click(); - String deletedRuleChain = ruleChainsPage.deleteRuleChainFromView(ENTITY_NAME); + String deletedRuleChain = ruleChainsPage.deleteRuleChainFromView(ruleChainName); ruleChainsPage.refreshBtn().click(); Assert.assertTrue(ruleChainsPage.entityIsNotPresent(deletedRuleChain)); } @Test(priority = 20, groups = "smoke") - @Description("Can`t remove Root Rule Chain (the trash can is disabled in the right corner)") + @Description public void removeRootRuleChain() { sideBarMenuView.ruleChainsBtn().click(); @@ -70,7 +89,7 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can`t remove Root Rule Chain (can`t mark the rule chain in the checkbox )") + @Description public void removeSelectedRootRuleChain() { sideBarMenuView.ruleChainsBtn().click(); @@ -78,17 +97,17 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can`t remove Root Rule Chain (missing delete button)") + @Description public void removeFromRootRuleChainView() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.entity(ROOT_RULE_CHAIN_NAME).click(); ruleChainsPage.deleteBtnFromView(); - ruleChainsPage.assertDeleteBtnInRootRuleChainIsNotDisplayed(); + Assert.assertTrue(ruleChainsPage.deleteBtnInRootRuleChainIsNotDisplayed()); } @Test(priority = 10, groups = "smoke") - @Description("Can remove the rule chain by clicking on the trash can icon in the right corner") + @Description public void removeProfileRuleChainByRightSideBtn() { String deletedRuleChain = "Thermostat"; @@ -105,7 +124,7 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can mark the rule chain in the checkbox and then click on the trash can icon in the menu that appears at the top") + @Description public void removeSelectedProfileRuleChain() { sideBarMenuView.ruleChainsBtn().click(); String deletedRuleChain = ruleChainsPage.deleteSelected("Thermostat"); @@ -119,7 +138,7 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 20, groups = "smoke") - @Description("Can click on the name of the rule chain and click on the 'Delete rule chain' button") + @Description public void removeFromProfileRuleChainView() { String deletedRuleChain = "Thermostat"; @@ -135,10 +154,10 @@ public class DeleteRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 30, groups = "smoke") - @Description("The rule chain is deleted immediately after clicking remove (no need to refresh the page)") + @Description public void removeRuleChainByRightSideBtnWithoutRefresh() { String ruleChainName = ENTITY_NAME; - ruleChainsPage.createRuleChain(ruleChainName); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); String deletedRuleChain = ruleChainsPage.deleteRuleChainTrash(ruleChainName); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java index 8481d9cde6..5b8667580e 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/DeleteSeveralRuleChainsTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -5,35 +20,36 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class DeleteSeveralRuleChainsTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @Test(priority = 10, groups = "smoke") - @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + @Description public void canDeleteSeveralRuleChainsByTopBtn() { String ruleChainName = ENTITY_NAME; - int count = 2; - ruleChainsPage.createRuleChains(ruleChainName, count); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName + 1)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); - ruleChainsPage.clickOnCheckBoxes(count); - + ruleChainsPage.clickOnCheckBoxes(2); ruleChainsPage.deleteSelectedBtn().click(); ruleChainsPage.warningPopUpYesBtn().click(); ruleChainsPage.refreshBtn().click(); @@ -42,11 +58,11 @@ public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverB } @Test(priority = 10, groups = "smoke") - @Description("Can mark several rule chains in the checkbox near the names and then click on the trash can icon in the menu that appears at the top") + @Description public void selectAllRuleChain() { String ruleChainName = ENTITY_NAME; - int count = 2; - ruleChainsPage.createRuleChains(ruleChainName, count); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName + 1)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.selectAllCheckBox().click(); @@ -58,7 +74,7 @@ public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverB } @Test(priority = 20, groups = "smoke") - @Description("Can`t remove Root Rule Chain (the trash can is disabled in the right corner)") + @Description public void removeRootRuleChain() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.selectAllCheckBox().click(); @@ -67,7 +83,7 @@ public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverB } @Test(priority = 20, groups = "smoke") - @Description("Can`t remove Root Rule Chain (can`t mark the rule chain in the checkbox )") + @Description public void removeSelectedRootRuleChain() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.selectAllCheckBox().click(); @@ -76,14 +92,14 @@ public class DeleteSeveralRuleChainsAbstractDiverBaseTest extends AbstractDiverB } @Test(priority = 30, groups = "smoke") - @Description("The rule chains are deleted immediately after clicking remove (no need to refresh the page)") + @Description public void deleteSeveralRuleChainsByTopBtnWithoutRefresh() { String ruleChainName = ENTITY_NAME; - int count = 2; - ruleChainsPage.createRuleChains(ruleChainName, count); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName + 1)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); - ruleChainsPage.clickOnCheckBoxes(count); + ruleChainsPage.clickOnCheckBoxes(2); ruleChainsPage.deleteSelectedBtn().click(); ruleChainsPage.warningPopUpYesBtn().click(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java index 8a71a11232..7eb75de8f8 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/MakeRuleChainRootTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,32 +21,33 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; -public class MakeRuleChainRootAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class MakeRuleChainRootTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @AfterMethod public void makeRoot() { - ruleChainsPage.makeRoot(); + testRestClient.setRootRuleChain(getRuleChainByName("Root Rule Chain").getId()); } @Test(priority = 10, groups = "smoke") - @Description("Can make rule chain root by clicking on the 'Make rule chain root' icon in the right corner") + @Description public void makeRuleChainRootByRightCornerBtn() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); @@ -43,7 +59,7 @@ public class MakeRuleChainRootAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 20, groups = "smoke") - @Description("Can make rule chain by clicking on the name/row of the rule chain and click on the 'make rule chain root' button") + @Description public void makeRuleChainRootFromView() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); @@ -57,11 +73,8 @@ public class MakeRuleChainRootAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 30, groups = "smoke") - @Description("Can't make multiple root rule chains (only one rule chain can be root)") + @Description public void multiplyRoot() { - SideBarMenuViewElements sideBarMenuView = new SideBarMenuViewElements(driver); - RuleChainsPageHelperAbstract ruleChainsPage = new RuleChainsPageHelperAbstract(driver); - sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); String ruleChain = ruleChainsPage.getRuleChainName(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java index f38f20bdff..7810c7bf5a 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/OpenRuleChainTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -5,30 +20,31 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.OpenRuleChainPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; -public class OpenRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class OpenRuleChainTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; - private OpenRuleChainPageHelperAbstract openRuleChainPage; + private RuleChainsPageHelper ruleChainsPage; + private OpenRuleChainPageHelper openRuleChainPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); - openRuleChainPage = new OpenRuleChainPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); + openRuleChainPage = new OpenRuleChainPageHelper(driver); } @Test(priority = 10, groups = "smoke") - @Description("Can open the rule chain by clicking on the 'Open rule chain' icon in the right corner") + @Description public void openRuleChainByRightCornerBtn() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); @@ -36,14 +52,14 @@ public class OpenRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { ruleChainsPage.openRuleChainBtn(ruleChain).click(); openRuleChainPage.setHeadName(); - Assert.assertTrue(urlContains(ruleChainsPage.getRuleChainId(ruleChainsPage.getRuleChainName()))); + Assert.assertTrue(urlContains(String.valueOf(getRuleChainByName(ruleChainsPage.getRuleChainName()).getId()))); Assert.assertTrue(openRuleChainPage.headRuleChainName().isDisplayed()); Assert.assertTrue(openRuleChainPage.inputNode().isDisplayed()); Assert.assertEquals(ruleChainsPage.getRuleChainName(), openRuleChainPage.getHeadName()); } @Test(priority = 10, groups = "smoke") - @Description("Can open the rule chain by clicking on the name/row of the rule chain and click on the 'Open rule chain' button") + @Description public void openRuleChainByViewBtn() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); @@ -52,14 +68,14 @@ public class OpenRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { ruleChainsPage.openRuleChainFromViewBtn().click(); openRuleChainPage.setHeadName(); - Assert.assertTrue(urlContains(ruleChainsPage.getRuleChainId(ruleChain))); + Assert.assertTrue(urlContains(String.valueOf(getRuleChainByName(ruleChainsPage.getRuleChainName()).getId()))); Assert.assertTrue(openRuleChainPage.headRuleChainName().isDisplayed()); Assert.assertTrue(openRuleChainPage.inputNode().isDisplayed()); Assert.assertEquals(ruleChain, openRuleChainPage.getHeadName()); } @Test(priority = 20, groups = "smoke") - @Description("Can`t open the rule chain by clicking twice on the row/name") + @Description public void openRuleChainDoubleClick() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setRuleChainNameWithoutRoot(0); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java index 9a080d7435..12e442c3b0 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/RuleChainEditMenuTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,38 +21,41 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class RuleChainEditMenuTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; private String ruleChainName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @AfterMethod public void delete() { if (ruleChainName != null) { - ruleChainsPage.deleteRuleChain(ruleChainName); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); ruleChainName = null; } } @Test(priority = 10, groups = "smoke") - @Description("Can click by pencil icon and edit the name (change the name) and save the changes. All changes have been applied") + @Description public void changeName() { - ruleChainsPage.createRuleChain(ENTITY_NAME); + testRestClient.postRuleChain(defaultRuleChainPrototype(ENTITY_NAME)); + ; String name = "Changed"; sideBarMenuView.ruleChainsBtn().click(); @@ -56,7 +74,7 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 20, groups = "smoke") - @Description("Can`t delete the name and save changes") + @Description public void deleteName() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.notRootRuleChainsNames().get(0).click(); @@ -67,7 +85,7 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 20, groups = "smoke") - @Description("Can`t save just a space in the name") + @Description public void saveOnlyWithSpace() { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.notRootRuleChainsNames().get(0).click(); @@ -81,10 +99,10 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 20, groups = "smoke") - @Description("Can write/change/delete the descriptionEntityView and save the changes. All changes have been applied") + @Description public void editDescription() { - String name = ENTITY_NAME; - ruleChainsPage.createRuleChain(name); + ruleChainName = ENTITY_NAME; + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); String description = "Description"; sideBarMenuView.ruleChainsBtn().click(); @@ -100,7 +118,6 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes ruleChainsPage.editPencilBtn().click(); ruleChainsPage.changeDescription(""); ruleChainsPage.doneBtnEditView().click(); - ruleChainName = name; Assert.assertTrue(ruleChainsPage.descriptionEntityView().getAttribute("value").isEmpty()); Assert.assertEquals(description, description1); @@ -108,10 +125,10 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes } @Test(priority = 20, groups = "smoke") - @Description("Can enable / disable debug and save changes. All changes have been applied") + @Description public void debugMode() { - String name = ENTITY_NAME; - ruleChainsPage.createRuleChain(name); + ruleChainName = ENTITY_NAME; + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.notRootRuleChainsNames().get(0).click(); @@ -122,7 +139,6 @@ public class RuleChainEditMenuAbstractDiverBaseTest extends AbstractDiverBaseTes ruleChainsPage.editPencilBtn().click(); ruleChainsPage.debugCheckboxEdit().click(); ruleChainsPage.doneBtnEditView().click(); - ruleChainName = name; Assert.assertFalse(Boolean.parseBoolean(ruleChainsPage.debugCheckboxView().getAttribute("aria-checked"))); Assert.assertTrue(debugMode); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java index 0a8dc6d96b..f39d54cd63 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SearchRuleChainTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -5,28 +20,30 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import org.thingsboard.server.msa.ui.utils.DataProviderCredential; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class SearchRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class SearchRuleChainTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "ruleChainNameForSearchByFirstAndSecondWord") - @Description("Can search by the first/second word of the name") + @Description public void searchFirstWord(String namePath) { sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.searchEntity(namePath); @@ -36,16 +53,16 @@ public class SearchRuleChainAbstractDiverBaseTest extends AbstractDiverBaseTest } @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSearchBySymbolAndNumber") - @Description("Can search by number/symbol") + @Description public void searchNumber(String name, String namePath) { - ruleChainsPage.createRuleChain(name); + testRestClient.postRuleChain(defaultRuleChainPrototype(name)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.searchEntity(namePath); ruleChainsPage.setRuleChainName(0); boolean ruleChainContainsNamePath = ruleChainsPage.getRuleChainName().contains(namePath); - ruleChainsPage.deleteRuleChain(name); + testRestClient.deleteRuleChain(getRuleChainByName(name).getId()); Assert.assertTrue(ruleChainContainsNamePath); } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java index a8f381c494..1a11ed9552 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByNameTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,31 +21,33 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; import org.thingsboard.server.msa.ui.utils.DataProviderCredential; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class SortByNameTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; private String ruleChainName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @AfterMethod public void delete() { if (ruleChainName != null) { - ruleChainsPage.deleteRuleChain(ruleChainName); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); ruleChainName = null; } } @@ -38,7 +55,8 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") @Description public void specialCharacterUp(String ruleChainName) { - ruleChainsPage.createRuleChain(ruleChainName); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); + ; sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.sortByNameBtn().click(); @@ -51,9 +69,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") @Description public void allSortUp(String ruleChain, String ruleChainSymbol, String ruleChainNumber) { - ruleChainsPage.createRuleChain(ruleChainSymbol); - ruleChainsPage.createRuleChain(ruleChain); - ruleChainsPage.createRuleChain(ruleChainNumber); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainSymbol)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChain)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainNumber)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.sortByNameBtn().click(); @@ -68,9 +86,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { boolean secondEquals = secondRuleChain.equals(ruleChainNumber); boolean thirdEquals = thirdRuleChain.equals(ruleChain); - ruleChainsPage.deleteRuleChain(ruleChain); - ruleChainsPage.deleteRuleChain(ruleChainNumber); - ruleChainsPage.deleteRuleChain(ruleChainSymbol); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChain).getId()); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainNumber).getId()); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainSymbol).getId()); Assert.assertTrue(firstEquals); Assert.assertTrue(secondEquals); @@ -80,7 +98,7 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 10, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForSort") @Description public void specialCharacterDown(String ruleChainName) { - ruleChainsPage.createRuleChain(ruleChainName); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainName)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.sortByNameDown(); @@ -93,9 +111,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { @Test(priority = 20, groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "nameForAllSort") @Description public void allSortDown(String ruleChain, String ruleChainSymbol, String ruleChainNumber) { - ruleChainsPage.createRuleChain(ruleChainSymbol); - ruleChainsPage.createRuleChain(ruleChain); - ruleChainsPage.createRuleChain(ruleChainNumber); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainSymbol)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChain)); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChainNumber)); sideBarMenuView.ruleChainsBtn().click(); int lastIndex = ruleChainsPage.allNames().size() - 1; @@ -111,9 +129,9 @@ public class SortByNameAbstractDiverBaseTest extends AbstractDiverBaseTest { boolean secondEquals = secondRuleChain.equals(ruleChainNumber); boolean thirdEquals = thirdRuleChain.equals(ruleChain); - ruleChainsPage.deleteRuleChain(ruleChain); - ruleChainsPage.deleteRuleChain(ruleChainNumber); - ruleChainsPage.deleteRuleChain(ruleChainSymbol); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChain).getId()); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainNumber).getId()); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainSymbol).getId()); Assert.assertTrue(firstEquals); Assert.assertTrue(secondEquals); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java index 3fc33e3ac0..d05bd11b39 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/ruleChainsSmoke/SortByTimeTest.java @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.tests.ruleChainsSmoke; import io.qameta.allure.Description; @@ -6,31 +21,32 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.thingsboard.server.msa.ui.base.AbstractDiverBaseTest; -import org.thingsboard.server.msa.ui.pages.LoginPageHelperAbstract; -import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelperAbstract; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.pages.RuleChainsPageHelper; import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements; -import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; -import static org.thingsboard.server.msa.ui.utils.Const.URL; +import static org.thingsboard.server.msa.ui.utils.Const.*; +import static org.thingsboard.server.msa.ui.utils.EntityPrototypes.defaultRuleChainPrototype; -public class SortByTimeAbstractDiverBaseTest extends AbstractDiverBaseTest { +public class SortByTimeTest extends AbstractDiverBaseTest { private SideBarMenuViewElements sideBarMenuView; - private RuleChainsPageHelperAbstract ruleChainsPage; + private RuleChainsPageHelper ruleChainsPage; private String ruleChainName; @BeforeMethod public void login() { openUrl(URL); - new LoginPageHelperAbstract(driver).authorizationTenant(); + new LoginPageHelper(driver).authorizationTenant(); + testRestClient.login(TENANT_EMAIL, TENANT_PASSWORD); sideBarMenuView = new SideBarMenuViewElements(driver); - ruleChainsPage = new RuleChainsPageHelperAbstract(driver); + ruleChainsPage = new RuleChainsPageHelper(driver); } @AfterMethod public void delete() { if (ruleChainName != null) { - ruleChainsPage.deleteRuleChain(ruleChainName); + testRestClient.deleteRuleChain(getRuleChainByName(ruleChainName).getId()); ruleChainName = null; } } @@ -39,7 +55,7 @@ public class SortByTimeAbstractDiverBaseTest extends AbstractDiverBaseTest { @Description public void sortByTimeDown() { String ruleChain = ENTITY_NAME; - ruleChainsPage.createRuleChain(ruleChain); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChain)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.setSort(); @@ -55,7 +71,7 @@ public class SortByTimeAbstractDiverBaseTest extends AbstractDiverBaseTest { @Description public void sortByTimeUp() { String ruleChain = ENTITY_NAME; - ruleChainsPage.createRuleChain(ruleChain); + testRestClient.postRuleChain(defaultRuleChainPrototype(ruleChain)); sideBarMenuView.ruleChainsBtn().click(); ruleChainsPage.sortByTimeBtn().click(); diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java index db6bd40084..351423d950 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java @@ -1,8 +1,23 @@ -package utils; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.utils; -import base.Base; +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomNumber; -public class Const extends Base { +public class Const { public static final String URL = "http://localhost:8080/"; public static final String TENANT_EMAIL = "tenant@thingsboard.org"; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java index 1509250abf..5536338fe5 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/DataProviderCredential.java @@ -1,9 +1,24 @@ -package utils; +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.msa.ui.utils; import org.testng.annotations.DataProvider; -import static base.Base.getRandomSymbol; -import static utils.Const.ENTITY_NAME; +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomSymbol; +import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; public class DataProviderCredential { diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java index 683dca511c..5fcfe8f4f9 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/EntityPrototypes.java @@ -1,9 +1,24 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ package org.thingsboard.server.msa.ui.utils; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.rule.RuleChain; -public class CustomerPrototypes { +public class EntityPrototypes { public static Customer defaultCustomerPrototype(String entityName){ Customer customer = new Customer(); diff --git a/msa/black-box-tests/src/test/resources/connectivity.xml b/msa/black-box-tests/src/test/resources/connectivity.xml index e69de29bb2..c2c12c4efb 100644 --- a/msa/black-box-tests/src/test/resources/connectivity.xml +++ b/msa/black-box-tests/src/test/resources/connectivity.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/msa/black-box-tests/src/test/resources/forImport.txt b/msa/black-box-tests/src/test/resources/forImport.txt index e69de29bb2..908a557812 100644 --- a/msa/black-box-tests/src/test/resources/forImport.txt +++ b/msa/black-box-tests/src/test/resources/forImport.txt @@ -0,0 +1,16 @@ +==== + Copyright © 2016-2022 The Thingsboard Authors + + 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. +==== + diff --git a/msa/black-box-tests/src/test/resources/smokeTests.xml b/msa/black-box-tests/src/test/resources/smokeTests.xml index 1194791760..85080e2bfd 100644 --- a/msa/black-box-tests/src/test/resources/smokeTests.xml +++ b/msa/black-box-tests/src/test/resources/smokeTests.xml @@ -1,7 +1,7 @@ - - - - - - + + + + \ No newline at end of file diff --git a/msa/pom.xml b/msa/pom.xml index e527566683..8bc033fcbc 100644 --- a/msa/pom.xml +++ b/msa/pom.xml @@ -46,6 +46,8 @@ web-ui tb-node transport + black-box-tests + From 17d6522571aab7d997f3a9b6554ad37b15324bbb Mon Sep 17 00:00:00 2001 From: Serafym Tuhai Date: Tue, 22 Nov 2022 13:24:23 +0200 Subject: [PATCH 009/527] add ui tests --- msa/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/msa/pom.xml b/msa/pom.xml index 8bc033fcbc..e527566683 100644 --- a/msa/pom.xml +++ b/msa/pom.xml @@ -46,8 +46,6 @@ web-ui tb-node transport - black-box-tests - From f3e927e9c5abfe300b3f7bdf28ccebe37988fa13 Mon Sep 17 00:00:00 2001 From: Serafym Tuhai Date: Tue, 22 Nov 2022 18:12:19 +0200 Subject: [PATCH 010/527] updated README.md --- msa/black-box-tests/README.md | 7 ++++++- msa/black-box-tests/src/test/resources/testNG.xml | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/msa/black-box-tests/README.md b/msa/black-box-tests/README.md index a60e7405a8..856bd08f4a 100644 --- a/msa/black-box-tests/README.md +++ b/msa/black-box-tests/README.md @@ -30,9 +30,14 @@ As result, in REPOSITORY column, next images should be present: mvn clean install -DblackBoxTests.skip=false -DblackBoxTests.hybridMode=true -To run the black box tests with using local env run tests in the [msa/black-box-tests](../black-box-tests) directory with runLocal property: +- To run the black box tests with using local env run tests in the [msa/black-box-tests](../black-box-tests) directory with runLocal property: mvn clean install -DblackBoxTests.skip=false -DrunLocal=true +- To run ui tests run tests in the [msa/black-box-tests](../black-box-tests) directory specifying suiteFile property: + + mvn clean install -DblackBoxTests.skip=false -DsuiteFile=src/test/resources/smokeTests.xml + + diff --git a/msa/black-box-tests/src/test/resources/testNG.xml b/msa/black-box-tests/src/test/resources/testNG.xml index f94bc7485c..45e93f76f1 100644 --- a/msa/black-box-tests/src/test/resources/testNG.xml +++ b/msa/black-box-tests/src/test/resources/testNG.xml @@ -17,9 +17,11 @@ --> + - - - - + + + + + \ No newline at end of file From 75f7b7319a704e6f4a9a5d4401d929c121a37bb0 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 23 Nov 2022 20:50:45 +0200 Subject: [PATCH 011/527] Added base implementation of edge docker install instructions controller --- .../docker/instructions.md | 88 +++++++++++++++++++ .../server/controller/BaseController.java | 4 + .../server/controller/EdgeController.java | 21 +++++ .../edge/DefaultEdgeInstallService.java | 71 +++++++++++++++ .../service/edge/EdgeInstallService.java | 27 ++++++ .../server/controller/AbstractWebTest.java | 8 +- .../controller/BaseEdgeControllerTest.java | 21 ++++- .../docker/expected-install-instructions.md | 88 +++++++++++++++++++ 8 files changed, 321 insertions(+), 7 deletions(-) create mode 100644 application/src/main/data/json/edge/install_instructions/docker/instructions.md create mode 100644 application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java create mode 100644 application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java create mode 100644 application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md diff --git a/application/src/main/data/json/edge/install_instructions/docker/instructions.md b/application/src/main/data/json/edge/install_instructions/docker/instructions.md new file mode 100644 index 0000000000..15a7db1d74 --- /dev/null +++ b/application/src/main/data/json/edge/install_instructions/docker/instructions.md @@ -0,0 +1,88 @@ +## Install edge and connect to cloud instructions + +### Localhost warning + +Localhost cannot be used for docker install - please update baseUrl to the IP address of your machine! + +Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker-compose. + +### Prerequisites + +Install Docker CE and Docker Compose. + +### Create data and logs folders + +Run following commands to create a directory for storing data and logs and then change its owner to docker container user, to be able to change user, chown command is used, which requires sudo permissions (command will request password for a sudo access): + +```bash +mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data +mkdir -p ~/.mytb-edge-logs && sudo chown -R 799:799 ~/.mytb-edge-logs +{:copy-code} +``` + +### Running ThingsBoard Edge as docker service + +Create docker compose file for ThingsBoard Edge service: + +```bash +nano docker-compose.yml +{:copy-code} +``` + +Add the following lines to the yml file: + +``` +version: '2.2' +services: +mytbedge: +restart: always +image: "thingsboard/tb-edge:3.4.1EDGE" +ports: +- "8080:8080" +- "1883:1883" +- "5683-5688:5683-5688/udp" +environment: +SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge +CLOUD_ROUTING_KEY: ${CLOUD_ROUTING_KEY} +CLOUD_ROUTING_SECRET: ${CLOUD_ROUTING_SECRET} +CLOUD_RPC_HOST: ${BASE_URL} +volumes: +- ~/.mytb-edge-data:/data +- ~/.mytb-edge-logs:/var/log/tb-edge +postgres: +restart: always +image: "postgres:12" +ports: +- "5432" +environment: +POSTGRES_DB: tb-edge +POSTGRES_PASSWORD: postgres +volumes: +- ~/.mytb-edge-data/db:/var/lib/postgresql/data +{:copy-code} +``` + +### Ports warning [Optional] +If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server is running you’ll need to update docker compose port mapping. +Please update next lines of docker compose: +ports: +- “18080:8080” +- “11883:1883” +- “15683-15688:5683-5688/udp” + Please make sure ports above are not used by any other application. + + +Execute the following commands to up this docker compose directly: + +```bash +docker-compose pull +docker-compose up +{:copy-code} +``` + +### Open ThingsBoard Edge UI + +Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080. + +If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL: +http://localhost:HTTP_BIND_PORT diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java index ffc3fcf3cd..1a8db80149 100644 --- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java +++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java @@ -131,6 +131,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; import org.thingsboard.server.queue.provider.TbQueueProducerProvider; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.component.ComponentDiscoveryService; +import org.thingsboard.server.service.edge.EdgeInstallService; import org.thingsboard.server.service.edge.EdgeNotificationService; import org.thingsboard.server.service.edge.rpc.EdgeRpcService; import org.thingsboard.server.service.entitiy.TbNotificationEntityService; @@ -281,6 +282,9 @@ public abstract class BaseController { @Autowired(required = false) protected EdgeRpcService edgeRpcService; + @Autowired(required = false) + protected EdgeInstallService edgeInstallService; + @Autowired protected TbNotificationEntityService notificationEntityService; diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index 6a5dd44d0b..12e02aa0bd 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -63,6 +63,7 @@ import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -595,4 +596,24 @@ public class EdgeController extends BaseController { return edgeBulkImportService.processBulkImport(request, user); } + + @ApiOperation(value = "Get Edge Docker Install Instructions (getEdgeDockerInstallInstructions)", + notes = "Get a docker install instructions for provided edge id." + TENANT_AUTHORITY_PARAGRAPH, + produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") + @RequestMapping(value = "/edge/instructions/{edgeId}", method = RequestMethod.GET) + @ResponseBody + public String getEdgeDockerInstallInstructions( + @ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true) + @PathVariable("edgeId") String strEdgeId, + HttpServletRequest request) throws ThingsboardException { + try { + EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); + edgeId = checkNotNull(edgeId); + Edge edge = checkEdgeId(edgeId, Operation.READ); + return checkNotNull(edgeInstallService.getDockerInstallInstructions(getTenantId(), edge, request)); + } catch (Exception e) { + throw handleException(e); + } + } } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java new file mode 100644 index 0000000000..e281efbf16 --- /dev/null +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java @@ -0,0 +1,71 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.service.edge; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.thingsboard.server.common.data.edge.Edge; +import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.service.install.InstallScripts; +import org.thingsboard.server.service.security.system.SystemSecurityService; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +@Service +@Slf4j +@RequiredArgsConstructor +public class DefaultEdgeInstallService implements EdgeInstallService { + + private static final String EDGE_DIR = "edge"; + + private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions"; + + private final InstallScripts installScripts; + private final SystemSecurityService systemSecurityService; + + @Override + public String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request) { + String baseUrl = request.getServerName(); + String template = readFile(resolveFile("docker", "instructions.md")); + template = template.replace("${BASE_URL}", baseUrl); + template = template.replace("${CLOUD_ROUTING_KEY}", edge.getRoutingKey()); + template = template.replace("${CLOUD_ROUTING_SECRET}", edge.getSecret()); + return template; + } + + private String readFile(Path file) { + try { + return new String(Files.readAllBytes(file), StandardCharsets.UTF_8); + } catch (IOException e) { + log.warn("Failed to read file: {}", file, e); + throw new RuntimeException(e); + } + } + + private Path resolveFile(String subDir, String... subDirs) { + return getEdgeInstallInstructionsDir().resolve(Paths.get(subDir, subDirs)); + } + + private Path getEdgeInstallInstructionsDir() { + return Paths.get(installScripts.getDataDir(), InstallScripts.JSON_DIR, EDGE_DIR, EDGE_INSTALL_INSTRUCTIONS_DIR); + } +} diff --git a/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java new file mode 100644 index 0000000000..54ad0de55d --- /dev/null +++ b/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java @@ -0,0 +1,27 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ +package org.thingsboard.server.service.edge; + +import org.thingsboard.server.common.data.edge.Edge; +import org.thingsboard.server.common.data.id.TenantId; + +import javax.servlet.http.HttpServletRequest; + +public interface EdgeInstallService { + + String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request); + +} diff --git a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java index e2b7d700bd..4d8e7c8488 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java @@ -701,16 +701,16 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { } protected Edge constructEdge(String name, String type) { - return constructEdge(tenantId, name, type); + return constructEdge(tenantId, name, type, StringUtils.randomAlphanumeric(20), StringUtils.randomAlphanumeric(20)); } - protected Edge constructEdge(TenantId tenantId, String name, String type) { + protected Edge constructEdge(TenantId tenantId, String name, String type, String routingKey, String secret) { Edge edge = new Edge(); edge.setTenantId(tenantId); edge.setName(name); edge.setType(type); - edge.setSecret(StringUtils.randomAlphanumeric(20)); - edge.setRoutingKey(StringUtils.randomAlphanumeric(20)); + edge.setRoutingKey(routingKey); + edge.setSecret(secret); return edge; } diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java index fa466ce93f..a6dde57752 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java @@ -57,6 +57,10 @@ import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; +import java.io.File; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -92,7 +96,7 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { } } - @Before + @Before public void beforeTest() throws Exception { loginSysAdmin(); @@ -327,7 +331,7 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { String customerIdStr = customerId.getId().toString(); String msgError = msgErrorNoFound("Customer", customerIdStr); - doPost("/api/customer/" + customerIdStr+ "/edge/" + savedEdge.getId().getId().toString()) + doPost("/api/customer/" + customerIdStr + "/edge/" + savedEdge.getId().getId().toString()) .andExpect(status().isNotFound()) .andExpect(statusReason(containsString(msgError))); @@ -876,4 +880,15 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { Edge edge = constructEdge(name, "default"); return doPost("/api/edge", edge, Edge.class); } -} + + @Test + public void testGetEdgeInstallInstructions() throws Exception { + Edge edge = constructEdge(tenantId, "Edge for Test Docker Install Instructions", "default", "7390c3a6-69b0-9910-d155-b90aca4b772e", "l7q4zsjplzwhk16geqxy"); + Edge savedEdge = doPost("/api/edge", edge, Edge.class); + String installInstructions = doGet("/api/edge/instructions/" + savedEdge.getId().getId().toString(), String.class); + URL resource = this.getClass().getClassLoader().getResource("edge/install_instructions/docker/expected-install-instructions.md"); + File file = new File(resource.toURI()); + Assert.assertEquals(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8), installInstructions); + } + +} \ No newline at end of file diff --git a/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md b/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md new file mode 100644 index 0000000000..e9a175bef9 --- /dev/null +++ b/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md @@ -0,0 +1,88 @@ +## Install edge and connect to cloud instructions + +### Localhost warning + +Localhost cannot be used for docker install - please update baseUrl to the IP address of your machine! + +Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker-compose. + +### Prerequisites + +Install Docker CE and Docker Compose. + +### Create data and logs folders + +Run following commands to create a directory for storing data and logs and then change its owner to docker container user, to be able to change user, chown command is used, which requires sudo permissions (command will request password for a sudo access): + +```bash +mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data +mkdir -p ~/.mytb-edge-logs && sudo chown -R 799:799 ~/.mytb-edge-logs +{:copy-code} +``` + +### Running ThingsBoard Edge as docker service + +Create docker compose file for ThingsBoard Edge service: + +```bash +nano docker-compose.yml +{:copy-code} +``` + +Add the following lines to the yml file: + +``` +version: '2.2' +services: +mytbedge: +restart: always +image: "thingsboard/tb-edge:3.4.1EDGE" +ports: +- "8080:8080" +- "1883:1883" +- "5683-5688:5683-5688/udp" +environment: +SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge +CLOUD_ROUTING_KEY: 7390c3a6-69b0-9910-d155-b90aca4b772e +CLOUD_ROUTING_SECRET: l7q4zsjplzwhk16geqxy +CLOUD_RPC_HOST: localhost +volumes: +- ~/.mytb-edge-data:/data +- ~/.mytb-edge-logs:/var/log/tb-edge +postgres: +restart: always +image: "postgres:12" +ports: +- "5432" +environment: +POSTGRES_DB: tb-edge +POSTGRES_PASSWORD: postgres +volumes: +- ~/.mytb-edge-data/db:/var/lib/postgresql/data +{:copy-code} +``` + +### Ports warning [Optional] +If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server is running you’ll need to update docker compose port mapping. +Please update next lines of docker compose: +ports: +- “18080:8080” +- “11883:1883” +- “15683-15688:5683-5688/udp” + Please make sure ports above are not used by any other application. + + +Execute the following commands to up this docker compose directly: + +```bash +docker-compose pull +docker-compose up +{:copy-code} +``` + +### Open ThingsBoard Edge UI + +Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080. + +If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL: +http://localhost:HTTP_BIND_PORT From 4893980352fe9fe285f7ce501382c805d42918ff Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 23 Nov 2022 20:54:49 +0200 Subject: [PATCH 012/527] Added ConditionalOnProperty for DefaultEdgeInstallService --- .../server/service/edge/DefaultEdgeInstallService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java index e281efbf16..e183cebca0 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java @@ -17,11 +17,12 @@ package org.thingsboard.server.service.edge; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.install.InstallScripts; -import org.thingsboard.server.service.security.system.SystemSecurityService; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -33,6 +34,8 @@ import java.nio.file.Paths; @Service @Slf4j @RequiredArgsConstructor +@ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true") +@TbCoreComponent public class DefaultEdgeInstallService implements EdgeInstallService { private static final String EDGE_DIR = "edge"; @@ -40,7 +43,6 @@ public class DefaultEdgeInstallService implements EdgeInstallService { private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions"; private final InstallScripts installScripts; - private final SystemSecurityService systemSecurityService; @Override public String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request) { From b0790490058f2e81083438dbbb3293df8c8d748e Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 24 Nov 2022 10:35:25 +0200 Subject: [PATCH 013/527] Edge instructions UI implementation --- ui-ngx/src/app/core/http/edge.service.ts | 6 +++- .../edge-instructions-dialog.component.html | 26 ++++++++++++++++ .../edge-instructions-dialog.component.scss | 3 ++ .../edge-instructions-dialog.component.ts | 31 +++++++++++++++++++ .../home/pages/edge/edge.component.html | 9 ++++++ .../modules/home/pages/edge/edge.module.ts | 4 ++- .../pages/edge/edges-table-config.resolver.ts | 24 ++++++++++++++ .../assets/locale/locale.constant-en_US.json | 1 + 8 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index 27cfefb6d6..d9ab289873 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; -import { Observable } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { PageLink, TimePageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; @@ -113,4 +113,8 @@ export class EdgeService { public bulkImportEdges(entitiesData: BulkImportRequest, config?: RequestConfig): Observable { return this.http.post('/api/edge/bulk_import', entitiesData, defaultHttpOptionsFromConfig(config)); } + + public getEdgeInstructions(edgeId: string, config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); + } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html new file mode 100644 index 0000000000..3a68cb0069 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html @@ -0,0 +1,26 @@ +
+ +

info_outline + {{ 'edge.install-connect-instructions' | translate }}

+ + +
+ + +
+
+ +
+
+ +
+
diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss new file mode 100644 index 0000000000..5cfbcc9657 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss @@ -0,0 +1,3 @@ +:host { +} + diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts new file mode 100644 index 0000000000..9b0e5a8fce --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts @@ -0,0 +1,31 @@ +import { Component, Inject } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; +import { DialogComponent } from "@shared/components/dialog.component"; +import { Store } from "@ngrx/store"; +import { AppState } from "@core/core.state"; +import { Router } from "@angular/router"; + +export interface EdgeInstructionsData { + instructions: string; +} + +@Component({ + selector: 'tb-edge-instructions', + templateUrl: './edge-instructions-dialog.component.html', + styleUrls: ['./edge-instructions-dialog.component.scss'] +}) +export class EdgeInstructionsDialogComponent extends DialogComponent { + + instructions: string = this.data.instructions; + + constructor(protected store: Store, + protected router: Router, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: EdgeInstructionsData) { + super(store, router, dialogRef); + } + + cancel(): void { + this.dialogRef.close(null); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index 6acc4cba0c..f4609aff36 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -112,6 +112,15 @@ edge.sync +
+ +
> { @@ -526,6 +530,23 @@ export class EdgesTableConfigResolver implements Resolve { + this.dialog.open(EdgeInstructionsDialogComponent, { + disableClose: false, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + instructions: edgeInstructionsTemplate + } + }); + } + ) + } + onEdgeAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': @@ -558,6 +579,9 @@ export class EdgesTableConfigResolver implements Resolve Date: Thu, 24 Nov 2022 11:03:38 +0200 Subject: [PATCH 014/527] Edge instructions added license headers --- ui-ngx/src/app/core/http/edge.service.ts | 4 ++-- .../edge-instructions-dialog.component.html | 17 +++++++++++++++++ .../edge-instructions-dialog.component.scss | 15 +++++++++++++++ .../edge/edge-instructions-dialog.component.ts | 16 ++++++++++++++++ .../modules/home/pages/edge/edge.component.html | 2 +- .../pages/edge/edges-table-config.resolver.ts | 2 +- 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index d9ab289873..85ebbb1282 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -114,7 +114,7 @@ export class EdgeService { return this.http.post('/api/edge/bulk_import', entitiesData, defaultHttpOptionsFromConfig(config)); } - public getEdgeInstructions(edgeId: string, config?: RequestConfig): Observable { - return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); + public getEdgeDockerInstallInstructions(edgeId: string, config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html index 3a68cb0069..fc375316e0 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html @@ -1,3 +1,20 @@ +

info_outline diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss index 5cfbcc9657..3da1d18971 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss @@ -1,3 +1,18 @@ +/** + * Copyright © 2016-2022 The Thingsboard Authors + * + * 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. + */ :host { } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts index 9b0e5a8fce..c96f06535b 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts @@ -1,3 +1,19 @@ +/// +/// Copyright © 2016-2022 The Thingsboard Authors +/// +/// 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. +/// + import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; import { DialogComponent } from "@shared/components/dialog.component"; diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index f4609aff36..e1304c3e06 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -113,7 +113,7 @@

-