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 c34d14e48f..de7f92cfb3 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 @@ -430,6 +430,7 @@ public class TestRestClient { .then() .statusCode(HTTP_OK); } + public String getToken() { return token; } @@ -438,18 +439,6 @@ public class TestRestClient { return refreshToken; } - public PageData getTenants(PageLink pageLink) { - Map params = new HashMap<>(); - addPageLinkToParam(params, pageLink); - return given().spec(requestSpec).queryParams(params) - .get("/api/tenants") - .then() - .statusCode(HTTP_OK) - .extract() - .as(new TypeRef>() { - }); - } - public Asset postAsset(Asset asset) { return given().spec(requestSpec) .body(asset) @@ -469,6 +458,13 @@ public class TestRestClient { .as(Asset.class); } + public void deleteAsset(AssetId assetId) { + given().spec(requestSpec) + .delete("/api/asset/{assetId}", assetId.getId()) + .then() + .statusCode(HTTP_OK); + } + public EntityView postEntityView(EntityView entityView) { return given().spec(requestSpec) .body(entityView) @@ -487,4 +483,11 @@ public class TestRestClient { .extract() .as(EntityView.class); } + + public void deleteEntityView(EntityViewId entityViewId) { + given().spec(requestSpec) + .delete("/api/entityView/{entityViewId}", entityViewId.getId()) + .then() + .statusCode(HTTP_OK); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java index aecdc61c03..3073ce506d 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java @@ -50,6 +50,7 @@ import java.net.URL; import java.time.Duration; import java.util.stream.Collectors; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.thingsboard.server.msa.TestProperties.getBaseUiUrl; import static org.thingsboard.server.msa.ui.utils.Const.TENANT_EMAIL; @@ -193,4 +194,8 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest { getWebStorage().getLocalStorage().clear(); getWebStorage().getSessionStorage().clear(); } + + public void assertIsDisplayed(WebElement element) { + assertThat(element.isDisplayed()).as(element + " is displayed").isTrue(); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java index 7d88a1ed4f..6e1e38a226 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AlarmDetailsViewElements.java @@ -24,7 +24,8 @@ public class AlarmDetailsViewElements extends AbstractBasePage { super(driver); } - private static final String ASSIGN_FIELD = "//tb-alarm-assignee//mat-icon[contains(text(),'keyboard_arrow_down')]/parent::button"; + //private static final String ASSIGN_FIELD = "//tb-alarm-assignee//mat-icon[contains(text(),'keyboard_arrow_down')]/parent::button"; + private static final String ASSIGN_FIELD = "//mat-label[text()='Assignee']/parent::label/parent::div//input"; private static final String USER_FROM_DROP_DOWN = "//div[@class='user-display-name']/span[text() = '%s']"; private static final String CLOSE_ALARM_DETAILS_VIEW_BTN = "//mat-dialog-container//mat-icon[contains(text(),'close')]/parent::button"; private static final String UNASSIGNED_BTN = "//div[@role='listbox']//mat-icon[text() = 'account_circle']/following-sibling::span"; diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java new file mode 100644 index 0000000000..f4424894dd --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/AssetPageElements.java @@ -0,0 +1,44 @@ +/** + * Copyright © 2016-2023 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; + +public class AssetPageElements extends OtherPageElements{ + public AssetPageElements(WebDriver driver) { + super(driver); + } + + private static final String CUSTOMER_DETAILS_VIEW = "//tb-details-panel"; + private static final String CUSTOMER_DETAILS_ALARMS = CUSTOMER_DETAILS_VIEW + "//span[text()='Alarms']"; + + public WebElement customerDetailsView() { + return waitUntilPresenceOfElementLocated(CUSTOMER_DETAILS_VIEW); + } + + public WebElement customerDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(CUSTOMER_DETAILS_ALARMS); + } + + public void openAssetAlarms(String assetName) { + if (!customerDetailsView().isDisplayed()) { + entity(assetName).click(); + } + customerDetailsAlarmsBtn().click(); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPage.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPage.java new file mode 100644 index 0000000000..b62c13d8a7 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/EntityViewPage.java @@ -0,0 +1,45 @@ +/** + * Copyright © 2016-2023 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; + +public class EntityViewPage extends OtherPageElementsHelper{ + public EntityViewPage(WebDriver driver) { + super(driver); + } + + private static final String CUSTOMER_DETAILS_VIEW = "//tb-details-panel"; + private static final String CUSTOMER_DETAILS_ALARMS = CUSTOMER_DETAILS_VIEW + "//span[text()='Alarms']"; + + public WebElement customerDetailsView() { + return waitUntilPresenceOfElementLocated(CUSTOMER_DETAILS_VIEW); + } + + public WebElement customerDetailsAlarmsBtn() { + return waitUntilElementToBeClickable(CUSTOMER_DETAILS_ALARMS); + } + + + public void openEntityViewAlarms(String customerName) { + if (!customerDetailsView().isDisplayed()) { + entity(customerName).click(); + } + customerDetailsAlarmsBtn().click(); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignByCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignByCustomerTest.java deleted file mode 100644 index 516abf8ab7..0000000000 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignByCustomerTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright © 2016-2023 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.assignee; - -import org.thingsboard.server.msa.ui.base.AbstractDriverBaseTest; - -abstract public class AbstractAssignByCustomerTest extends AbstractDriverBaseTest { -} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java index 1dfe2b139d..182bf04fb4 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AbstractAssignTest.java @@ -19,12 +19,9 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; import org.thingsboard.server.common.data.id.AlarmId; -import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; -import org.thingsboard.server.common.data.id.EntityViewId; import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.msa.ui.base.AbstractDriverBaseTest; import org.thingsboard.server.msa.ui.pages.AlarmDetailsViewHelper; @@ -41,117 +38,57 @@ abstract public class AbstractAssignTest extends AbstractDriverBaseTest { protected AlarmId alarmId; protected AlarmId assignedAlarmId; - protected AlarmId propageteAlarmId; - protected AlarmId propageteAssigneAlarmId; - protected AlarmId tenantAlarmId; - protected AlarmId onCustomerAlarmId; - protected AlarmId assetAlarmId; - protected AlarmId entityViewAlarmId; protected DeviceId deviceId; - protected DeviceId tenantDeviceId; + protected UserId userId; protected UserId userWithNameId; protected CustomerId customerId; protected String deviceName; - protected String assetName; - protected String entityViewName; - protected String tenantDeviceName; + protected SideBarMenuViewHelper sideBarMenuView; protected AlarmHelper alarmPage; protected DevicePageHelper devicePage; + protected CustomerPageHelper customerPage; protected AlarmDetailsViewHelper alarmDetailsView; - CustomerPageHelper customerPage; - protected String name = "User"; - protected String customerTitle = "Customer" + random(); + protected String userName = "User " + random(); + protected String customerTitle = "Customer " + random(); protected String userEmail = random() + "@thingsboard.org"; protected String userWithNameEmail = random() + "@thingsboard.org"; - protected String alarm = "Test alarm 1"; - protected String assignedAlarm = "Test alarm 2"; - protected String propagateAlarm = "Test propagated alarm 1"; - protected String propagateAssignedAlarm = "Test propagated alarm 2"; - protected String tenantAlarm = "Test tenant alarm"; - protected String customerAlarm = "Test customer alarm"; - protected String assetAlarm = "Test asset alarm"; - protected String entityViewAlarm = "Test entity view alarm"; - protected AssetId assetId; - protected EntityViewId entityViewId; + protected String alarm = "Test alarm " + random(); + protected String assignedAlarm = "Test assigned alarm " + random(); @BeforeClass - public void generateTestEntities() { + public void generateTestEntity() { new LoginPageHelper(driver).authorizationTenant(); sideBarMenuView = new SideBarMenuViewHelper(driver); alarmPage = new AlarmHelper(driver); devicePage = new DevicePageHelper(driver); - alarmDetailsView = new AlarmDetailsViewHelper(driver); customerPage = new CustomerPageHelper(driver); + alarmDetailsView = new AlarmDetailsViewHelper(driver); customerId = testRestClient.postCustomer(EntityPrototypes.defaultCustomerPrototype(customerTitle)).getId(); userId = testRestClient.postUser(EntityPrototypes.defaultUser(userEmail, getCustomerByName(customerTitle).getId())).getId(); - userWithNameId = testRestClient.postUser(EntityPrototypes.defaultUser(userWithNameEmail, getCustomerByName(customerTitle).getId(), name)).getId(); + userWithNameId = testRestClient.postUser(EntityPrototypes.defaultUser(userWithNameEmail, getCustomerByName(customerTitle).getId(), userName)).getId(); deviceName = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype("", customerId)).getName(); - tenantDeviceName = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype("")).getName(); deviceId = testRestClient.getDeviceByName(deviceName).getId(); - tenantDeviceId = testRestClient.getDeviceByName(tenantDeviceName).getId(); - onCustomerAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(customerId, customerAlarm)).getId(); - assetId = testRestClient.postAsset(EntityPrototypes.defaultAssetPrototype("", customerId)).getId(); - assetName = testRestClient.getAssetById(assetId).getName(); - assetAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(assetId, assetAlarm)).getId(); - entityViewId = testRestClient.postEntityView(EntityPrototypes.defaultEntityViewPrototype("", "", "DEVICE")).getId(); - entityViewName = testRestClient.getEntityViewById(entityViewId).getName(); - entityViewAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(entityViewId, entityViewAlarm)).getId(); + } + + @AfterClass + public void deleteEntities() { + testRestClient.deleteCustomer(customerId); + testRestClient.deleteDevice(deviceId); } @BeforeMethod - public void generateTestAlarms() { - if (getJwtTokenFromLocalStorage() == null) { - new LoginPageHelper(driver).authorizationTenant(); - } + public void createTestAlarms() { alarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, alarm)).getId(); assignedAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, assignedAlarm, userId)).getId(); - propageteAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAlarm, true)).getId(); - propageteAssigneAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAssignedAlarm, userId, true)).getId(); - - tenantAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(tenantDeviceId, tenantAlarm)).getId(); - - } - - @AfterClass - public void deleteTestEntities() { - testRestClient.deleteDevice(deviceId); - testRestClient.deleteDevice(tenantDeviceId); - testRestClient.deleteCustomer(customerId); - testRestClient.deleteAlarm(onCustomerAlarmId); - testRestClient.deleteAlarm(assetAlarmId); - testRestClient.deleteAlarm(entityViewAlarmId); } @AfterMethod - public void deleteTestAlarms() { + public void deleteCreatedAlarms() { testRestClient.deleteAlarm(alarmId); testRestClient.deleteAlarm(assignedAlarmId); - testRestClient.deleteAlarm(propageteAlarmId); - testRestClient.deleteAlarm(propageteAssigneAlarmId); - testRestClient.deleteAlarm(tenantAlarmId); - } - - public void loginByUser(String userEmail) { - sideBarMenuView.customerBtn().click(); - customerPage.manageCustomersUserBtn(customerTitle).click(); - customerPage.getUserLoginBtnByEmail(userEmail).click(); - } - - @DataProvider - public Object[][] alarms() { - return new Object[][]{ - {alarm}, - {propagateAlarm}}; - } - - @DataProvider - public Object[][] assignedAlarms() { - return new Object[][]{ - {assignedAlarm}, - {propagateAssignedAlarm}}; } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignByCustomerTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignByCustomerTest.java deleted file mode 100644 index e02f0ce45b..0000000000 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignByCustomerTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright © 2016-2023 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.assignee; - -public class AssignByCustomerTest extends AbstractAssignByCustomerTest{ -} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTab.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTab.java deleted file mode 100644 index 9781ef6417..0000000000 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTab.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * Copyright © 2016-2023 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.assignee; - -import org.testng.Assert; -import org.testng.annotations.Test; -import org.thingsboard.server.msa.ui.pages.AssetPageElements; -import org.thingsboard.server.msa.ui.utils.Const; - -import static org.assertj.core.api.Assertions.assertThat; - -public class AssignDetailsTab extends AbstractAssignTest { - - @Test(dataProvider = "alarms") - public void assignAlarmToYourself(String alarm) { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.assignAlarmTo(alarm, Const.TENANT_EMAIL); - - Assert.assertTrue(alarmPage.assignedUser(Const.TENANT_EMAIL).isDisplayed()); - } - - @Test(dataProvider = "alarms") - public void assignAlarmToAnotherUser(String alarm) { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.assignAlarmTo(alarm, userEmail); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - - @Test(dataProvider = "assignedAlarms") - public void unassignedAlarm(String assignedAlarm) { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.unassignedAlarm(assignedAlarm); - - Assert.assertTrue(alarmPage.unassigned(assignedAlarm).isDisplayed()); - } - - @Test(dataProvider = "assignedAlarms") - public void reassignAlarm(String assignedAlarm) { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.assignAlarmTo(assignedAlarm, Const.TENANT_EMAIL); - - Assert.assertTrue(alarmPage.assignedUser(Const.TENANT_EMAIL).isDisplayed()); - } - - @Test - public void searchByEmail() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.searchAlarm(alarm, Const.TENANT_EMAIL); - alarmPage.setUsers(); - - assertThat(alarmPage.getUsers()).hasSize(1).contains(Const.TENANT_EMAIL); - alarmPage.assignUsers().forEach(u -> assertThat(u.isDisplayed()).isTrue()); - } - - @Test - public void searchByName() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.searchAlarm(alarm, name); - alarmPage.setUsers(); - - //assertThat(alarmPage.getUsers()).hasSize(1).contains(name); - alarmPage.assignUsers().forEach(u -> assertThat(u.isDisplayed()).isTrue()); - } - - @Test - public void assignAlarmToYourselfFromDetails() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.alarmDetailsBtn(alarm).click(); - alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); - alarmDetailsView.closeAlarmDetailsViewBtn().click(); - - Assert.assertTrue(alarmPage.assignedUser(Const.TENANT_EMAIL).isDisplayed()); - } - - @Test - public void assignAlarmToAnotherUserFromDetails() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.alarmDetailsBtn(alarm).click(); - alarmDetailsView.assignAlarmTo(userEmail); - alarmDetailsView.closeAlarmDetailsViewBtn().click(); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - - @Test - public void unassignedAlarmFromDetails() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.alarmDetailsBtn(assignedAlarm).click(); - alarmDetailsView.unassignedAlarm(); - alarmDetailsView.closeAlarmDetailsViewBtn().click(); - - Assert.assertTrue(alarmPage.unassigned(assignedAlarm).isDisplayed()); - } - - @Test - public void reassignAlarmFromDetails() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.alarmDetailsBtn(assignedAlarm).click(); - alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); - alarmDetailsView.closeAlarmDetailsViewBtn().click(); - - Assert.assertTrue(alarmPage.assignedUser(Const.TENANT_EMAIL).isDisplayed()); - } - - @Test - public void assignAlarmToYourselfCustomer() { - loginByUser(userEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.assignAlarmTo(alarm, userEmail); - clearStorage(); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - - @Test - public void reassignAlarmByCustomerFromAnotherCustomerUser() { - loginByUser(userWithNameEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.assignAlarmTo(assignedAlarm, name); - clearStorage(); - - Assert.assertTrue(alarmPage.assignedUser(name).isDisplayed()); - } - - @Test - public void unassignedAlarmFromCustomer() { - loginByUser(userWithNameEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.unassignedAlarm(assignedAlarm); - clearStorage(); - - Assert.assertTrue(alarmPage.unassigned(assignedAlarm).isDisplayed()); - } - - @Test - public void unassignedAlarmFromAnotherUserFromCustomer() { - loginByUser(userEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(deviceName); - alarmPage.unassignedAlarm(assignedAlarm); - clearStorage(); - - Assert.assertTrue(alarmPage.unassigned(assignedAlarm).isDisplayed()); - } - - @Test - public void checkTheDisplayOfNamesEmailsFromCustomer() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(tenantDeviceName); - alarmPage.assignAlarmTo(tenantAlarm, Const.TENANT_EMAIL); - devicePage.closeDeviceDetailsViewBtn().click(); - devicePage.assignToCustomerBtn(tenantDeviceName).click(); - devicePage.assignToCustomer(customerTitle); - loginByUser(userEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(tenantDeviceName); - - clearStorage(); - Assert.assertTrue(alarmPage.assignedUser(Const.TENANT_EMAIL).isDisplayed()); - } - - @Test - public void reassignTenantForOldAlarm() { - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(tenantDeviceName); - alarmPage.assignAlarmTo(tenantAlarm, Const.TENANT_EMAIL); - devicePage.closeDeviceDetailsViewBtn().click(); - devicePage.assignToCustomerBtn(tenantDeviceName).click(); - devicePage.assignToCustomer(customerTitle); - loginByUser(userEmail); - sideBarMenuView.goToDevicesPage(); - devicePage.openDeviceAlarms(tenantDeviceName); - alarmPage.assignAlarmTo(tenantAlarm, userEmail); - - clearStorage(); - Assert.assertTrue(alarmPage.accessForbiddenDialogView().isDisplayed()); - } - - @Test - public void assignCustomerAlarmToYourself() { - sideBarMenuView.customerBtn().click(); - customerPage.openCustomerAlarms(customerTitle); - alarmPage.assignAlarmTo(customerAlarm, userEmail); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - - @Test - public void assignAssetAlarmToYourself() { - AssetPageElements assetPageElements = new AssetPageElements(driver); - sideBarMenuView.goToAssetsPage(); - assetPageElements.openAssetAlarms(customerTitle); - alarmPage.assignAlarmTo(assetAlarm, userEmail); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - - @Test - public void assignEntityViewsAlarmToYourself() { - AssetPageElements assetPageElements = new AssetPageElements(driver); - sideBarMenuView.goToEntityViewsPage(); - assetPageElements.openAssetAlarms(entityViewName); - alarmPage.assignAlarmTo(entityViewAlarm, userEmail); - - Assert.assertTrue(alarmPage.assignedUser(userEmail).isDisplayed()); - } - -} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java new file mode 100644 index 0000000000..5f65c94810 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabAssignTest.java @@ -0,0 +1,229 @@ +/** + * Copyright © 2016-2023 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.assignee; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.AssetId; +import org.thingsboard.server.common.data.id.EntityViewId; +import org.thingsboard.server.msa.ui.pages.AssetPageElements; +import org.thingsboard.server.msa.ui.pages.EntityViewPage; +import org.thingsboard.server.msa.ui.utils.Const; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; + +public class AssignDetailsTabAssignTest extends AbstractAssignTest { + + private AlarmId propageteAlarmId; + private AlarmId propageteAssigneAlarmId; + private AlarmId customerAlarmId; + private AlarmId assetAlarmId; + private AlarmId entityViewAlarmId; + private String assetName; + private String entityViewName; + private final String propagateAlarm = "Test propagated alarm 1 " + random(); + private final String propagateAssignedAlarm = "Test propagated alarm 2 " + random(); + private final String customerAlarm = "Test customer alarm" + random(); + private final String assetAlarm = "Test asset alarm" + random(); + private final String entityViewAlarm = "Test entity view alarm" + random(); + private AssetId assetId; + private EntityViewId entityViewId; + + @BeforeClass + public void generateTestEntities() { + customerAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(customerId, customerAlarm)).getId(); + assetId = testRestClient.postAsset(EntityPrototypes.defaultAssetPrototype("", customerId)).getId(); + assetName = testRestClient.getAssetById(assetId).getName(); + assetAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(assetId, assetAlarm)).getId(); + entityViewId = testRestClient.postEntityView(EntityPrototypes.defaultEntityViewPrototype("", "", "DEVICE")).getId(); + entityViewName = testRestClient.getEntityViewById(entityViewId).getName(); + entityViewAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(entityViewId, entityViewAlarm)).getId(); + } + + @BeforeMethod + public void generateTestAlarms() { + propageteAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAlarm, true)).getId(); + propageteAssigneAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, propagateAssignedAlarm, userId, true)).getId(); + } + + @AfterClass + public void deleteTestEntities() { + testRestClient.deleteAlarm(customerAlarmId); + testRestClient.deleteAlarm(assetAlarmId); + testRestClient.deleteAlarm(entityViewAlarmId); + testRestClient.deleteAsset(assetId); + testRestClient.deleteEntityView(entityViewId); + } + + @AfterMethod + public void deleteTestAlarms() { + testRestClient.deleteAlarm(propageteAlarmId); + testRestClient.deleteAlarm(propageteAssigneAlarmId); + } + + @DataProvider + public Object[][] alarms() { + return new Object[][]{ + {alarm}, + {propagateAlarm}}; + } + + @DataProvider + public Object[][] assignedAlarms() { + return new Object[][]{ + {assignedAlarm}, + {propagateAssignedAlarm}}; + } + + @Test(dataProvider = "alarms") + public void assignAlarmToYourself(String alarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test(dataProvider = "alarms") + public void assignAlarmToAnotherUser(String alarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarm, userEmail); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Test(dataProvider = "assignedAlarms") + public void unassignedAlarm(String assignedAlarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarm); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarm)); + } + + @Test(dataProvider = "assignedAlarms") + public void reassignAlarm(String assignedAlarm) { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(assignedAlarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void searchByEmail() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.searchAlarm(alarm, Const.TENANT_EMAIL); + alarmPage.setUsers(); + + assertThat(alarmPage.getUsers()).hasSize(1).as("Search result contains search input").contains(Const.TENANT_EMAIL); + alarmPage.assignUsers().forEach(this::assertIsDisplayed); + } + + @Test(groups = "broken") + public void searchByName() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.searchAlarm(alarm, userName); + alarmPage.setUsers(); + + assertThat(alarmPage.getUsers()).hasSize(1).as("Search result contains search input").contains(userName); + alarmPage.assignUsers().forEach(this::assertIsDisplayed); + } + + @Test + public void assignAlarmToYourselfFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(alarm).click(); + alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void assignAlarmToAnotherUserFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(alarm).click(); + alarmDetailsView.assignAlarmTo(userEmail); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Test + public void unassignedAlarmFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(assignedAlarm).click(); + alarmDetailsView.unassignedAlarm(); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarm)); + } + + @Test + public void reassignAlarmFromDetails() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.alarmDetailsBtn(assignedAlarm).click(); + alarmDetailsView.assignAlarmTo(Const.TENANT_EMAIL); + alarmDetailsView.closeAlarmDetailsViewBtn().click(); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void assignCustomerAlarmToYourself() { + sideBarMenuView.customerBtn().click(); + customerPage.openCustomerAlarms(customerTitle); + alarmPage.assignAlarmTo(customerAlarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void assignAssetAlarmToYourself() { + AssetPageElements assetPageElements = new AssetPageElements(driver); + sideBarMenuView.goToAssetsPage(); + assetPageElements.openAssetAlarms(assetName); + alarmPage.assignAlarmTo(assetAlarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void assignEntityViewsAlarmToYourself() { + EntityViewPage entityViewPage = new EntityViewPage(driver); + sideBarMenuView.goToEntityViewsPage(); + entityViewPage.openEntityViewAlarms(entityViewName); + alarmPage.assignAlarmTo(entityViewAlarm, Const.TENANT_EMAIL); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java new file mode 100644 index 0000000000..7696b4cbe8 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/assignee/AssignDetailsTabFromCustomerAssignTest.java @@ -0,0 +1,129 @@ +/** + * Copyright © 2016-2023 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.assignee; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.thingsboard.server.common.data.id.AlarmId; +import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.msa.ui.pages.LoginPageHelper; +import org.thingsboard.server.msa.ui.utils.Const; +import org.thingsboard.server.msa.ui.utils.EntityPrototypes; + +import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; + +public class AssignDetailsTabFromCustomerAssignTest extends AbstractAssignTest { + + AlarmId tenantAlarmId; + DeviceId tenantDeviceId; + String tenantDeviceName; + String tenantAlarm = "Test tenant alarm " + random(); + + public void loginByUser(String userEmail) { + sideBarMenuView.customerBtn().click(); + customerPage.manageCustomersUserBtn(customerTitle).click(); + customerPage.getUserLoginBtnByEmail(userEmail).click(); + } + + @BeforeMethod + public void generateTenantEntity() { + if (getJwtTokenFromLocalStorage() == null) { + new LoginPageHelper(driver).authorizationTenant(); + } + tenantDeviceName = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype("")).getName(); + tenantDeviceId = testRestClient.getDeviceByName(tenantDeviceName).getId(); + tenantAlarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(tenantDeviceId, tenantAlarm)).getId(); + } + + @AfterMethod + public void clear() { + testRestClient.deleteAlarm(tenantAlarmId); + testRestClient.deleteDevice(tenantDeviceId); + clearStorage(); + } + + @Test + public void assignAlarmToYourselfCustomer() { + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(alarm, userEmail); + + assertIsDisplayed(alarmPage.assignedUser(userEmail)); + } + + @Test + public void reassignAlarmByCustomerFromAnotherCustomerUser() { + loginByUser(userWithNameEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.assignAlarmTo(assignedAlarm, userName); + + assertIsDisplayed(alarmPage.assignedUser(userName)); + } + + @Test + public void unassignedAlarmFromCustomer() { + loginByUser(userWithNameEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarm); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarm)); + } + + @Test + public void unassignedAlarmFromAnotherUserFromCustomer() { + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(deviceName); + alarmPage.unassignedAlarm(assignedAlarm); + + assertIsDisplayed(alarmPage.unassigned(assignedAlarm)); + } + + @Test + public void checkTheDisplayOfNamesEmailsFromCustomer() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignAlarmTo(tenantAlarm, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + devicePage.assignToCustomerBtn(tenantDeviceName).click(); + devicePage.assignToCustomer(customerTitle); + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + + assertIsDisplayed(alarmPage.assignedUser(Const.TENANT_EMAIL)); + } + + @Test + public void reassignTenantForOldAlarm() { + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignAlarmTo(tenantAlarm, Const.TENANT_EMAIL); + devicePage.closeDeviceDetailsViewBtn().click(); + devicePage.assignToCustomerBtn(tenantDeviceName).click(); + devicePage.assignToCustomer(customerTitle); + loginByUser(userEmail); + sideBarMenuView.goToDevicesPage(); + devicePage.openDeviceAlarms(tenantDeviceName); + alarmPage.assignBtn(tenantAlarm).click(); + + assertIsDisplayed(alarmPage.accessForbiddenDialogView()); + } +} diff --git a/msa/black-box-tests/src/test/resources/assignee.xml b/msa/black-box-tests/src/test/resources/assignee.xml new file mode 100644 index 0000000000..52499824cd --- /dev/null +++ b/msa/black-box-tests/src/test/resources/assignee.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file