+ * In this test case, the build process of a new device type and installation to the server is tested. + */ +public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase { + Log log = LogFactory.getLog(SampleInstallationTest.class); + private Process tempProcess = null; + private Properties properties = System.getProperties(); + private String carbonHome = properties.getProperty("carbon.home"); + private String[] cmdArray; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException, AutomationFrameworkException { + super.init(); + } + + @Test(description = "Verify the sample build process") + public void sampleBuildTest() throws IOException { + String connectedCupDir = carbonHome + File.pathSeparator + "samples" + File.pathSeparator + "connectedcup"; + log.info("Connected cup Sample: " + connectedCupDir); + File dir = new File(connectedCupDir); + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + log.info("Executing maven clean install --------------------------------"); + cmdArray = new String[]{"cmd.exe", "/c", "mvn clean install"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + + } else { + log.info("Executing maven clean install --------------------------------"); + cmdArray = new String[]{"mvn", "clean", "install"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } + + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), "BUILD SUCCESS"); + Assert.assertTrue(buildStatus, "Building the sample was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Verify the sample installation process", dependsOnMethods = {"sampleBuildTest"}) + public void sampleInstallationTest() throws IOException { + + log.info("CARBON_HOME: " + System.getProperty("carbon.home")); + File dir = new File(carbonHome); + log.info("Sample installation started : mvn clean install -f device-deployer.xml"); + try { + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + cmdArray = new String[]{"cmd.exe", "/c", "mvn clean install -f device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } else { + cmdArray = new String[]{"mvn", "clean", "install", "-f", "device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(cmdArray, null, dir); + } + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), "BUILD SUCCESS"); + Assert.assertTrue(buildStatus, "Sample installation was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Test restarting the server", dependsOnMethods = {"sampleInstallationTest"}) + public void serverRestartTest() { + CarbonServerManager serverManager = new CarbonServerManager(automationContext); + try { + serverManager.restartGracefully(); + } catch (AutomationFrameworkException e) { + log.error("Restart failed...."); + } + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + } + + public boolean waitForMessage(InputStream inputStream, String message) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); + String line; + boolean status = false; + while ((line = br.readLine()) != null) { + log.info(line); + if (!status && line.contains(message)) { + status = true; + } + } + return status; + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java similarity index 90% rename from modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java rename to modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java index 8ea6b5d0..472cf2d4 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFailTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java @@ -43,16 +43,16 @@ import java.io.IOException; * 5. Empty email * 6. Incorrect email */ -public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { +public class AddUserFormValidationTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; + private UIElementMapper uiElementMapper; - WebElement firstNameField; - WebElement lastNameField; - WebElement emailField; - WebElement userNameField; - WebElement addUserButton; + private WebElement firstNameField; + private WebElement lastNameField; + private WebElement emailField; + private WebElement userNameField; + private WebElement addUserButton; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { @@ -60,7 +60,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { driver = BrowserManager.getWebDriver(); LoginUtils.login(driver, automationContext, getWebAppURL()); driver.get(getWebAppURL() + Constants.IOT_USER_ADD_URL); - uiElementMapper = UIElementMapper.getInstance(); userNameField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.username.id"))); @@ -72,7 +71,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty form submission") - public void emptyFormTest() throws Exception { + public void emptyFormTest(){ clearForm(); firstNameField.sendKeys(""); @@ -88,7 +87,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for short user name") - public void shortUserNameTest() throws Exception { + public void shortUserNameTest() { clearForm(); firstNameField.sendKeys("User"); @@ -104,7 +103,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty first name") - public void emptyFirstNameTest() throws Exception { + public void emptyFirstNameTest() { clearForm(); firstNameField.sendKeys(""); @@ -120,7 +119,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty last name") - public void emptyLastNameTest() throws Exception { + public void emptyLastNameTest() { clearForm(); firstNameField.sendKeys("User"); @@ -135,7 +134,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for empty email name") - public void emptyEmailTest() throws Exception { + public void emptyEmailTest() { clearForm(); firstNameField.sendKeys("User"); @@ -151,7 +150,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @Test(description = "Test for incorrect email") - public void incorrectEmailTest() throws Exception { + public void incorrectEmailTest() { clearForm(); firstNameField.sendKeys("User"); @@ -164,7 +163,6 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { Assert.assertEquals(driver.findElement(By.xpath( uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))).getText(), "Provided email is invalid. Please check."); - } private void clearForm() { @@ -175,8 +173,7 @@ public class AddUserFailTest extends IOTIntegrationUIBaseTestCase { } @AfterClass(alwaysRun = true) - public void tearDown() throws Exception { + public void tearDown() { driver.quit(); } - } diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java similarity index 83% rename from modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java rename to modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java index 0094ce43..057098ef 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegisterTest.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java @@ -37,9 +37,9 @@ import java.io.IOException; /** * Test for registering a new user and login */ -public class RegisterTest extends IOTIntegrationUIBaseTestCase { +public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; + private UIElementMapper uiElementMapper; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { @@ -50,10 +50,10 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase { @Test(description = "Verify new User registration") public void userRegisterTest() throws IOException { - LoginPage test = new LoginPage(driver); + LoginPage loginPage = new LoginPage(driver); uiElementMapper = UIElementMapper.getInstance(); - NewUserRegisterPage registerTest = test.registerNewUser(); - LoginPage loginPage = registerTest.registerUser( + NewUserRegisterPage registerTest = loginPage.registerNewUser(); + loginPage = registerTest.registerUser( uiElementMapper.getElement("iot.user.add.firstname"), uiElementMapper.getElement("iot.user.add.lastname"), uiElementMapper.getElement("iot.user.add.email"), @@ -65,10 +65,13 @@ public class RegisterTest extends IOTIntegrationUIBaseTestCase { uiElementMapper.getElement("iot.user.add.password")); Assert.assertTrue(homePage.checkUserName()); + } + @Test(description = "Test user logout function", dependsOnMethods = {"userRegisterTest"}) + public void logoutTest() throws IOException { + IOTHomePage homePage = new IOTHomePage(driver); homePage.logout(); - - driver.close(); + Assert.assertEquals(driver.getTitle(), "Login | IoT Server"); } @AfterClass(alwaysRun = true) diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java index b14e9412..b605394a 100644 --- a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTests.java @@ -19,9 +19,6 @@ package org.wso2.carbon.iot.integration.web.ui.test.user; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -30,6 +27,7 @@ import org.wso2.carbon.automation.extensions.selenium.BrowserManager; import org.wso2.carbon.iot.integration.web.ui.test.Constants; import org.wso2.iot.integration.ui.pages.IOTIntegrationUIBaseTestCase; import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage; import javax.xml.stream.XMLStreamException; import javax.xml.xpath.XPathExpressionException; @@ -44,54 +42,22 @@ import java.io.IOException; */ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCase { private WebDriver driver; - UIElementMapper uiElementMapper; - - WebElement firstNameField; - WebElement lastNameField; - WebElement emailField; - WebElement userNameField; - WebElement passwordField; - WebElement passwordConfirmationField; - WebElement registerButton; + private UIElementMapper uiElementMapper; + private NewUserRegisterPage registerPage; @BeforeClass(alwaysRun = true) public void setup() throws XPathExpressionException, XMLStreamException, IOException { super.init(); driver = BrowserManager.getWebDriver(); driver.get(getWebAppURL() + Constants.IOT_USER_REGISTER_URL); - + registerPage = new NewUserRegisterPage(driver); uiElementMapper = UIElementMapper.getInstance(); - - WebDriverWait wait = new WebDriverWait(driver, 10); - wait.until(ExpectedConditions.titleContains("Register | IoT Server")); - - firstNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.firstname.xpath"))); - lastNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.lastname.xpath"))); - emailField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.email.xpath"))); - userNameField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.username.xpath"))); - passwordField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.password.xpath"))); - passwordConfirmationField = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.input.confirmpassword.xpath"))); - registerButton = driver.findElement(By.xpath( - uiElementMapper.getElement("iot.user.add.register.button.xpath"))); - } +} @Test(description = "Test for submitting an empty registration form") - public void emptyFormTest() { - clearForm(); - firstNameField.sendKeys(""); - lastNameField.sendKeys(""); - emailField.sendKeys(""); - userNameField.sendKeys(""); - passwordField.sendKeys(""); - passwordConfirmationField.sendKeys(""); - - registerButton.click(); + public void emptyFormTest() throws IOException { + registerPage.clearForm(); + registerPage.validateForm("", "", "", "", "", ""); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.firstname.error"))).getText(), @@ -115,15 +81,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for non matching passwords") public void nonMatchingPasswordTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user@user.com"); - userNameField.sendKeys("user"); - passwordField.sendKeys("user123"); - passwordConfirmationField.sendKeys("user234"); - registerButton.click(); + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "password", "Password"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.confirmPassword.error"))).getText(), @@ -132,12 +90,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for email") public void incorrectEmailTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user.com"); - registerButton.click(); + registerPage.validateForm("user", "user", "user123", "user1", "password", "password"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.email.error"))).getText(), @@ -146,16 +99,7 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas @Test(description = "Test for password length") public void passwordLengthTest() { - clearForm(); - - firstNameField.sendKeys("User"); - lastNameField.sendKeys("User"); - emailField.sendKeys("user@user.com"); - userNameField.sendKeys("user"); - passwordField.sendKeys("user"); - - registerButton.click(); - + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "passw", "passw"); Assert.assertEquals(driver.findElement(By.id( uiElementMapper.getElement("iot.user.register.password.error"))).getText(), "Password should be between 5 and 30 characters."); @@ -166,12 +110,5 @@ public class RegistrationFormValidationTests extends IOTIntegrationUIBaseTestCas driver.quit(); } - public void clearForm() { - firstNameField.clear(); - lastNameField.clear(); - emailField.clear(); - userNameField.clear(); - passwordField.clear(); - passwordConfirmationField.clear(); - } + } diff --git a/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java b/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java index fbb508cc..142d6569 100644 --- a/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java +++ b/modules/samples/connectedcup/component/controller/src/main/java/org/coffeeking/controller/service/transport/ConnectedCupMQTTConnector.java @@ -134,26 +134,6 @@ public class ConnectedCupMQTTConnector extends MQTTTransportHandler { String[] messageData = mqttMessage.toString().split(":"); Float value = Float.valueOf(messageData[1]); -// if (actualMessage.contains("PUBLISHER")) { -// float temperature = Float.parseFloat(actualMessage.split(":")[2]); -// -// if (!ConnectedCupServiceUtils.publishToDAS(owner, deviceId, messageData[0], value)) { -// log.error("MQTT Subscriber: Publishing data to DAS failed."); -// } -// -// if (log.isDebugEnabled()) { -// log.debug("MQTT Subscriber: Published data to DAS successfully."); -// } -// -// } else if (actualMessage.contains("TEMPERATURE")) { -// String temperatureValue = actualMessage.split(":")[1]; -// SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE, -// temperatureValue, -// Calendar.getInstance().getTimeInMillis()); -// } -// -// - switch(messageData[0]) { case "temperature": SensorDataManager.getInstance().setSensorRecord(deviceId, ConnectedCupConstants.SENSOR_TEMPERATURE,