replace mapper with JacksonUtil, add dataProvider, refactor assert messages

This commit is contained in:
Seraphym-Tuhai 2023-05-24 16:36:16 +03:00
parent da2c0d308c
commit d8a8caff11
2 changed files with 29 additions and 47 deletions

View File

@ -15,21 +15,20 @@
*/ */
package org.thingsboard.server.msa.ui.tests.devicessmoke; package org.thingsboard.server.msa.ui.tests.devicessmoke;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.qameta.allure.Description; import io.qameta.allure.Description;
import io.qameta.allure.Epic; import io.qameta.allure.Epic;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.msa.ui.utils.DataProviderCredential;
import org.thingsboard.server.msa.ui.utils.EntityPrototypes; import org.thingsboard.server.msa.ui.utils.EntityPrototypes;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random;
import static org.thingsboard.server.msa.ui.utils.Const.DEVICE_ACTIVE_STATE;
import static org.thingsboard.server.msa.ui.utils.Const.DEVICE_INACTIVE_STATE;
import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME;
@Epic("Filter devices (By device profile and state)") @Epic("Filter devices (By device profile and state)")
@ -40,7 +39,7 @@ public class DeviceFilterTest extends AbstractDeviceTest {
private String activeDeviceWithProfileName; private String activeDeviceWithProfileName;
@BeforeClass @BeforeClass
public void createTestEntities() throws JsonProcessingException { public void createTestEntities() {
DeviceProfile deviceProfile = testRestClient.postDeviceProfile(EntityPrototypes.defaultDeviceProfile(ENTITY_NAME + random())); DeviceProfile deviceProfile = testRestClient.postDeviceProfile(EntityPrototypes.defaultDeviceProfile(ENTITY_NAME + random()));
Device deviceWithProfile = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME + random(), deviceProfile.getId())); Device deviceWithProfile = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME + random(), deviceProfile.getId()));
Device activeDevice = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME + random())); Device activeDevice = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME + random()));
@ -48,8 +47,8 @@ public class DeviceFilterTest extends AbstractDeviceTest {
DeviceCredentials deviceCredentials = testRestClient.getDeviceCredentialsByDeviceId(activeDevice.getId()); DeviceCredentials deviceCredentials = testRestClient.getDeviceCredentialsByDeviceId(activeDevice.getId());
DeviceCredentials deviceCredentials1 = testRestClient.getDeviceCredentialsByDeviceId(activeDeviceWithProfile.getId()); DeviceCredentials deviceCredentials1 = testRestClient.getDeviceCredentialsByDeviceId(activeDeviceWithProfile.getId());
testRestClient.postTelemetry(deviceCredentials.getCredentialsId(), mapper.readTree(createPayload().toString())); testRestClient.postTelemetry(deviceCredentials.getCredentialsId(), JacksonUtil.toJsonNode(createPayload().toString()));
testRestClient.postTelemetry(deviceCredentials1.getCredentialsId(), mapper.readTree(createPayload().toString())); testRestClient.postTelemetry(deviceCredentials1.getCredentialsId(), JacksonUtil.toJsonNode(createPayload().toString()));
deviceProfileTitle = deviceProfile.getName(); deviceProfileTitle = deviceProfile.getName();
deviceWithProfileName = deviceWithProfile.getName(); deviceWithProfileName = deviceWithProfile.getName();
@ -71,61 +70,34 @@ public class DeviceFilterTest extends AbstractDeviceTest {
devicePage.filterDeviceByDeviceProfile(deviceProfileTitle); devicePage.filterDeviceByDeviceProfile(deviceProfileTitle);
devicePage.listOfDevicesProfile().forEach(d -> assertThat(d.getText()) devicePage.listOfDevicesProfile().forEach(d -> assertThat(d.getText())
.as("There are only devices with the selected profile on the page") .as("There are only devices with the selected profile(%s) on the page", deviceProfileTitle)
.isEqualTo(deviceProfileTitle)); .isEqualTo(deviceProfileTitle));
} }
@Test(groups = "smoke") @Test(groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "filterData")
@Description("Filter by state (Active)") @Description("Filter by state")
public void filterDevicesByActiveState() { public void filterDevicesByState(String state) {
sideBarMenuView.goToDevicesPage(); sideBarMenuView.goToDevicesPage();
devicePage.filterBtn().click(); devicePage.filterBtn().click();
devicePage.filterDeviceByState(DEVICE_ACTIVE_STATE); devicePage.filterDeviceByState(state);
devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText()) devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText())
.as("There are only devices with active state on the page") .as("There are only devices with '%s' state on the page", state)
.isEqualTo(DEVICE_ACTIVE_STATE)); .isEqualTo(state));
} }
@Test(groups = "smoke") @Test(groups = "smoke", dataProviderClass = DataProviderCredential.class, dataProvider = "filterData")
@Description("Filter by state (Inactive)") @Description("Filter device by device profile and state")
public void filterDevicesByInactiveState() { public void filterDevicesByDeviceProfileAndState(String state) {
sideBarMenuView.goToDevicesPage(); sideBarMenuView.goToDevicesPage();
devicePage.filterBtn().click(); devicePage.filterBtn().click();
devicePage.filterDeviceByState(DEVICE_INACTIVE_STATE); devicePage.filterDeviceByDeviceProfileAndState(deviceProfileTitle, state);
devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText())
.as("There are only devices with inactive state on the page")
.isEqualTo(DEVICE_INACTIVE_STATE));
}
@Test(groups = "smoke")
@Description("Filter device by device profile and active state")
public void filterDevicesByDeviceProfileAndActiveState() {
sideBarMenuView.goToDevicesPage();
devicePage.filterBtn().click();
devicePage.filterDeviceByDeviceProfileAndState(deviceProfileTitle, DEVICE_ACTIVE_STATE);
devicePage.listOfDevicesProfile().forEach(d -> assertThat(d.getText()) devicePage.listOfDevicesProfile().forEach(d -> assertThat(d.getText())
.as("There are only devices with the selected profile on the page") .as("There are only devices with the selected profile(%s) on the page", deviceProfileTitle)
.isEqualTo(deviceProfileTitle)); .isEqualTo(deviceProfileTitle));
devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText()) devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText())
.as("There are only devices with active state on the page") .as("There are only devices with '%s' state on the page", state)
.isEqualTo(DEVICE_ACTIVE_STATE)); .isEqualTo(state));
}
@Test(groups = "smoke")
@Description("Filter device by device profile and inactive state")
public void filterDevicesByDeviceProfileAndInactiveState() {
sideBarMenuView.goToDevicesPage();
devicePage.filterBtn().click();
devicePage.filterDeviceByDeviceProfileAndState(deviceProfileTitle, DEVICE_INACTIVE_STATE);
devicePage.listOfDevicesProfile().forEach(d -> assertThat(d.getText())
.as("There are only devices with the selected profile on the page")
.isEqualTo(deviceProfileTitle));
devicePage.listOfDevicesState().forEach(d -> assertThat(d.getText())
.as("There are only devices with inactive state on the page")
.isEqualTo(DEVICE_INACTIVE_STATE));
} }
} }

View File

@ -21,6 +21,8 @@ import org.testng.annotations.DataProvider;
import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomNumber; import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomNumber;
import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomSymbol; import static org.thingsboard.server.msa.ui.base.AbstractBasePage.getRandomSymbol;
import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random; import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random;
import static org.thingsboard.server.msa.ui.utils.Const.DEVICE_ACTIVE_STATE;
import static org.thingsboard.server.msa.ui.utils.Const.DEVICE_INACTIVE_STATE;
import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME; import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME;
public class DataProviderCredential { public class DataProviderCredential {
@ -166,4 +168,12 @@ public class DataProviderCredential {
{label, newLabel, label + newLabel}, {label, newLabel, label + newLabel},
{label, Keys.CONTROL + "A" + Keys.BACK_SPACE, ""}}; {label, Keys.CONTROL + "A" + Keys.BACK_SPACE, ""}};
} }
@DataProvider(name = "filterData")
public static Object[][] getFilterData() {
return new Object[][]{
{DEVICE_ACTIVE_STATE},
{DEVICE_INACTIVE_STATE}
};
}
} }