Added comments and code cleanup

application-manager-new
Menaka Madushanka 9 years ago
parent d9799fa3c0
commit c086968e24

@ -30,10 +30,7 @@ import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
import java.rmi.RemoteException;
/**
* Created by menaka on 1/19/16.
*
*/
public class IOTIntegrationUIBaseTestCase {
private static final Log log = LogFactory.getLog(IOTIntegrationUIBaseTestCase.class);

@ -28,7 +28,9 @@ import org.wso2.iot.integration.ui.pages.UIElementMapper;
import java.io.IOException;
/**
* Add group page of iot server
* Add group page of iot server. This class contains methods to,
* 1. Create a new group
* 2. Submit an empty form
*/
public class DeviceAddGroupPage {
@ -48,6 +50,12 @@ public class DeviceAddGroupPage {
}
/**
* @param name The group name that is need to be created.
* @param description the description for the group
* @return The resultant page.
* @throws Exception
*/
public DeviceGroupsPage addNewGroup (String name, String description) throws Exception{
WebElement nameField = driver.findElement(By.id(
@ -66,6 +74,9 @@ public class DeviceAddGroupPage {
}
/**
* @return The error string when trying to submit an empty form.
*/
public String submitEmptyForm() {
WebElement nameField = driver.findElement(By.id(
uiElementMapper.getElement("iot.device.group.addGroupForm.name.id")));

@ -30,10 +30,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by menaka on 1/24/16.
*
*/
public class DeviceGroupsPage {
private static final Log log = LogFactory.getLog(DeviceGroupsPage.class);
private WebDriver driver;

@ -31,6 +31,23 @@ import org.wso2.iot.integration.ui.pages.uesr.UserListingPage;
import java.io.IOException;
/**
* This class represents the Admin Dashboard of the IOT server.
* Server dashboard has following sections and functions.
* 1. User Management
* - View users.
* - Add a new user
* 2. Group Management.
* - View Groups.
* - Add a new group.
* 3. Device Management.
* - View enrolled devices.
* - Enroll a device.
* 3. Policy Management.
* - View Policies.
* - Create a policy.
*/
public class IOTAdminDashboard {
private static final Log log = LogFactory.getLog(IOTHomePage.class);

@ -72,7 +72,6 @@ public class IOTHomePage {
}
//To add new Device groups as user
public void goToGroupMgt() throws Exception {
driver.findElement(By.xpath("iot.home.page.uuf-menu.xpath")).click();
driver.findElement(By.xpath("iot.home.page.uuf-menu.groupmgt.xpath")).click();

@ -32,7 +32,7 @@ import org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage;
import java.io.IOException;
/**
* Login page of the iot server
* Represents the Login page of the iot server.
*
*/
public class LoginPage {
@ -50,6 +50,13 @@ public class LoginPage {
}
}
/**
* Method to login as a registered user.
* @param username Username of the user.
* @param password Password of the user.
* @return After a user is logged in, it will redirect to the IOT Server Home page.
* @throws IOException
*/
public IOTHomePage loginAsUser(String username, String password) throws IOException {
log.info("Login as " + username);
WebElement userNameField = driver.findElement(By.xpath(
@ -62,6 +69,13 @@ public class LoginPage {
return new IOTHomePage(driver);
}
/**
* Method to login as the server admin.
* @param username The admin user name (admin).
* @param password The admin password (admin).
* @return After admin logged in, it will redirect to the IOT Server dashboard.
* @throws IOException
*/
public IOTAdminDashboard loginAsAdmin(String username, String password) throws IOException {
log.info("Login as " + username);
WebElement userNameField = driver.findElement(By.xpath(
@ -74,6 +88,11 @@ public class LoginPage {
return new IOTAdminDashboard(driver);
}
/**
* Method for new user registration.
* @return After clicking the Register link, it will navigate to the User Registration page.
* @throws IOException
*/
public NewUserRegisterPage registerNewUser() throws IOException {
WebElement registerLink = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.user.register.link.xpath")));

@ -9,6 +9,10 @@ import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* This class represents the add user page of the IOT server.
*/
public class AddUserPage {
private static final Log log = LogFactory.getLog(AddUserPage.class);
private WebDriver driver;
@ -24,7 +28,16 @@ public class AddUserPage {
}
}
public UserAddedPage createNewUser(String userName, String firstName, String lastName, String email) throws Exception {
/**
* Method to create a new user.
* @param userName The username for the user.
* @param firstName The user's first name.
* @param lastName The user's last name.
* @param email Email address of the user.
* @return The user added confirmation page.
* @throws Exception
*/
public UserAddedConfirmationPage createNewUser(String userName, String firstName, String lastName, String email) throws Exception {
WebElement userNameField = driver.findElement(By.id(
uiElementMapper.getElement("iot.admin.addUser.username.id")));
@ -44,9 +57,9 @@ public class AddUserPage {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))));
driver.findElement(By.xpath("//button[@id='add-user-btn']")).click();
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))).click();
return new UserAddedPage(driver);
return new UserAddedConfirmationPage(driver);
}

@ -9,8 +9,7 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* Created by menaka on 2/8/16.
*
* This class represents the Edit user page of the IOT server
*/
public class EditUserPage {
private static final Log log = LogFactory.getLog(EditUserPage.class);

@ -13,7 +13,7 @@ import org.wso2.iot.integration.ui.pages.login.LoginPage;
import java.io.IOException;
/**
* Created by menaka on 1/19/16.
* This class represents the new user registration page.
*/
public class NewUserRegisterPage {
private static final Log log = LogFactory.getLog(NewUserRegisterPage.class);
@ -30,8 +30,19 @@ public class NewUserRegisterPage {
}
}
public LoginPage addUser(String firstName, String lastName, String email, String userName, String password,
String
/**
* The method to register a new user.
* @param firstName First name of the user.
* @param lastName Last name of the user.
* @param email Email address of the user.
* @param userName User name for the user. This will be used to login to the server.
* @param password The password for the user.
* @param confirmPassword Password confirmation.
* @return After the user is created it navigates back to the login page.
* @throws IOException
*/
public LoginPage registerUser(String firstName, String lastName, String email, String userName, String password,
String
confirmPassword) throws IOException {
WebElement firstNameField = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.user.add.input.firstname.xpath")));

@ -0,0 +1,27 @@
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* This class represents the confirmation page for adding a new user.
*/
public class UserAddedConfirmationPage {
private static final Log log = LogFactory.getLog(UserAddedConfirmationPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public UserAddedConfirmationPage(WebDriver driver) throws Exception {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click();
}
}

@ -1,37 +0,0 @@
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* Created by menaka on 1/27/16.
*
*/
public class UserAddedPage {
private static final Log log = LogFactory.getLog(UserAddedPage.class);
private WebDriver driver;
private UIElementMapper uiElementMapper;
public UserAddedPage(WebDriver driver) throws Exception {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click();
// WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
// if (!driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.added.page.subtitle.xpath")))
// .getText().contains("User was added successfully.")){
// throw new IllegalStateException("This is not the User Added page");
// }
}
}

@ -1,15 +1,15 @@
package org.wso2.iot.integration.ui.pages.uesr;
import org.apache.commons.jexl2.UnifiedJEXL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.omg.PortableServer.THREAD_POLICY_ID;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* Class to represent the user listing page.
*/
public class UserListingPage {
private static final Log log = LogFactory.getLog(UserListingPage.class);
private WebDriver driver;
@ -19,12 +19,16 @@ public class UserListingPage {
this.driver = driver;
this.uiElementMapper = UIElementMapper.getInstance();
if (!driver.findElement(By.xpath("//span[@class='page-sub-title']"))
if (!driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.added.page.subtitle.xpath")))
.getText().contains("USERS")){
throw new IllegalStateException("This is not the User Listing page");
}
}
/**
* @return After deleting a user, returns back to the user listing page.
* @throws Exception
*/
public UserListingPage deleteUser() throws Exception {
WebElement deleteBtn = driver.findElement(By.xpath(
uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath")));

@ -8,7 +8,7 @@ import org.openqa.selenium.support.ui.WebDriverWait;
import org.wso2.iot.integration.ui.pages.UIElementMapper;
/**
* Created by menaka on 2/8/16.
* Class to represent the user view.
*/
public class ViewUserPage {
private static final Log log = LogFactory.getLog(ViewUserPage.class);

@ -102,7 +102,7 @@ iot.admin.user.addButton.xpath=/html/body/div[3]/div[2]/div[1]/div[3]/div/div/di
iot.admin.user.viewButton.xpath=/html/body/div[3]/div[2]/div[1]/div[3]/div/div/div[2]/div[2]/span[2]/a[1]/span/i[2]
iot.admin.user.added.page.subtitle.xpath="//p[@class='page-sub-title']"
#="//span[@class='page-sub-title']"
iot.admin.addUser.username.id=username
iot.admin.addUser.firstName.id=firstname

@ -19,14 +19,8 @@ package org.wso2.carbon.iot.integration.web.ui.test;
public class Constants {
public static final String IOT_LOGIN_PATH = "/devicemgt/login";
// public static final String LOGIN_GROUP = "login-group";
// public static final String MDM_ROLES_URL = "/mdm/roles";
public static final String IOT_USER_REGISTER_URL = "/devicemgt/register";
public static final String IOT_USER_ADD_URL = "/devicemgt/user/add";
public static final String IOT_GROUP_ADD_URL = "/devicemgt/group/add";
// public static final String MDM_USER_URL = "/mdm/users/";
// public static final String MDM_ROLES_EDIT_URL = "/mdm/roles/edit-role/";
// public static final String MDM_PLATFORM_CONFIG_URL = "/mdm/platform-configuration";
// public static final String MDM_NOTIFICATION_URL = "/mdm/notification-listing";
public static final String IOT_HOME_URL = "/devicemgt/";
}

@ -23,11 +23,20 @@ import org.wso2.iot.integration.ui.pages.UIElementMapper;
import org.wso2.iot.integration.ui.pages.login.LoginPage;
/**
* Login as registered user
* This class is used to login to the system as the Admin.
*/
public class LoginUtils {
private static UIElementMapper uiElementMapper;
/**
*
* This method is used to login as admin.
*
* @param driver The selenium web driver
* @param automationContext Test Automation context
* @param webAppURL The server url
* @throws Exception
*/
public static void login(WebDriver driver, AutomationContext automationContext,
String webAppURL) throws Exception {
uiElementMapper = UIElementMapper.getInstance();

@ -30,8 +30,9 @@ import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase;
import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage;
/**
* Created by menaka on 1/25/16.
*
* This class contains methods to test the failing scenarios of Group creation.
* There can be groups with same name.
* So the failing scenario is sending the form with empty group name.
*/
public class DeviceGroupFailTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
@ -43,7 +44,7 @@ public class DeviceGroupFailTest extends IOTIntegrationUIBaseTestCase {
LoginUtils.login(driver, automationContext, getWebAppURL());
}
@Test(description = "Test for submitting an empty form.")
@Test(description = "Test for empty group name.")
public void addNewGroupFailTest () throws Exception {
driver.get(getWebAppURL() + Constants.IOT_GROUP_ADD_URL);
DeviceAddGroupPage addGroupPage = new DeviceAddGroupPage(driver);

@ -40,7 +40,7 @@ import org.wso2.iot.integration.ui.pages.UIElementMapper;
* 5. Empty email
* 6. Incorrect email
*/
public class AddUserFormTest extends IOTIntegrationUIBaseTestCase {
public class AddUserFailTest extends IOTIntegrationUIBaseTestCase {
private WebDriver driver;
UIElementMapper uiElementMapper;

@ -49,7 +49,7 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase {
LoginPage test = new LoginPage(driver);
uiElementMapper = UIElementMapper.getInstance();
NewUserRegisterPage registerTest = test.registerNewUser();
LoginPage loginPage = registerTest.addUser(
LoginPage loginPage = registerTest.registerUser(
uiElementMapper.getElement("iot.user.add.firstname"),
uiElementMapper.getElement("iot.user.add.lastname"),
uiElementMapper.getElement("iot.user.add.email"),

@ -125,7 +125,7 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(),
"Please enter the same password as above");
}
//
@Test (description = "Test for email")
public void incorrectEmail() throws Exception {
clearForm();
@ -140,7 +140,7 @@ public class RegistrationFormTests extends IOTIntegrationUIBaseTestCase{
"Email is not valid. Please enter a correct email address.");
}
//
@Test (description = "Test for password length")
public void passwordLengthTest() throws Exception {
clearForm();

@ -34,7 +34,7 @@
<class name="org.wso2.carbon.iot.integration.web.ui.test.group.DeviceGroupTest"/>
<class name="org.wso2.carbon.iot.integration.web.ui.test.group.DeviceGroupFailTest"/>
<class name="org.wso2.carbon.iot.integration.web.ui.test.user.TestAdminFunctions"/>
<class name="org.wso2.carbon.iot.integration.web.ui.test.user.AddUserFormTest"/>
<class name="org.wso2.carbon.iot.integration.web.ui.test.user.AddUserFailTest"/>
</classes>
</test>

@ -122,6 +122,7 @@ public class ConnectedCupMQTTConnector extends MQTTTransportHandler {
public void processIncomingMessage(MqttMessage mqttMessage, String... strings) throws TransportHandlerException {
String topic = strings[0];
String ownerAndId = topic.replace("wso2" + File.separator, "");
ownerAndId = ownerAndId.replace(File.separator + ConnectedCupConstants.DEVICE_TYPE + File.separator, ":");
ownerAndId = ownerAndId.replace(File.separator + "connected_publisher", "");
@ -154,11 +155,13 @@ public class ConnectedCupMQTTConnector extends MQTTTransportHandler {
//
switch(messageData[0]) {
case "temperature": SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE,
case "temperature":
SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE,
String.valueOf(messageData[1]),
Calendar.getInstance().getTimeInMillis());
break;
case "coffeelevel": SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_LEVEL,
case "coffeelevel":
SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_LEVEL,
String.valueOf(messageData[1]),
Calendar.getInstance().getTimeInMillis());
break;

Loading…
Cancel
Save