diff --git a/README.md b/README.md index 29ba7963..6000aa24 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,11 @@ srcset="http://b.content.wso2.com/sites/all/common/images/product-logos/IoT-server.svg@2x.png 2x" alt="WSO2 IoT Server" /> -# Welcome to WSO2 IoT Server -[![Build Status](https://wso2.org/jenkins/buildStatus/icon?job=product-iots)](https://wso2.org/jenkins/view/Dashboard/job/product-iots/) + +# Welcome to WSO2 IoT Server + + + WSO2 IoT Server is a complete solution that enables device manufacturers and enterprises to connect and manage their devices, build apps, manage events, secure devices and data, and visualize sensor data in a scalable manner. diff --git a/modules/distribution/src/core/cloud/portal/global-navigation.jag b/modules/distribution/src/core/cloud/portal/global-navigation.jag index e4f22cc2..84e47f93 100644 --- a/modules/distribution/src/core/cloud/portal/global-navigation.jag +++ b/modules/distribution/src/core/cloud/portal/global-navigation.jag @@ -18,16 +18,23 @@ <% var query = request.getQueryString(); var dest = encodeURIComponent(originalURI + (query ? '?' + query : '')); +var configs = require('/configs/portal.js').config(); +var isCloud = configs.isCloud; %>
-
+ <% if (isCloud) { %> +
<% if (user) { %>
- - + <% } else { %> +
+ <% if (user) { %> + +
+ +
+ +
+
+ <% } else { %> + + <%= i18n.localize("login.label")%> + + <% } %> +
+ <% } %>
-
+ \ No newline at end of file diff --git a/modules/distribution/src/core/cloud/portal/portal.js b/modules/distribution/src/core/cloud/portal/portal.js index 0a7386a1..3d03a903 100644 --- a/modules/distribution/src/core/cloud/portal/portal.js +++ b/modules/distribution/src/core/cloud/portal/portal.js @@ -149,7 +149,7 @@ $(function () { var dashboard = findDashboard(id); dashboardEl.html(dashboardThumbnailHbs(dashboard)); }); - + portal.on('click', '.ues-view:not(.disable)', function(e) { e.preventDefault(); window.open($(this).attr('href'), '_blank'); @@ -185,20 +185,20 @@ $(function () { }); }; - $(document).ready(function () { - $('#cloud-menu-popover i.fw-tiles').popover({ - html: true, - trigger:'click', - title: function() { - return $("#popover-head").html(); - }, - content: function() { - return $("#popover-content").html(); - } - }); + if($('#cloud-menu-popover').length) { + $('#cloud-menu-popover i.fw-tiles').popover({ + html: true, + trigger:'click', + title: function() { + return $("#popover-head").html(); + }, + content: function() { + return $("#popover-content").html(); + } + }); + } }); - initUI(); loadDashboards(); }); \ No newline at end of file diff --git a/modules/distribution/src/core/conf/log4j.properties b/modules/distribution/src/core/conf/log4j.properties index f1fc1e73..58f26676 100644 --- a/modules/distribution/src/core/conf/log4j.properties +++ b/modules/distribution/src/core/conf/log4j.properties @@ -59,6 +59,8 @@ log4j.logger.de.hunsicker.jalopy.io=FATAL #log4j.logger.org.apache.synapse.transport.http.headers=DEBUG #log4j.logger.org.apache.synapse.transport.http.wire=DEBUG +# uncomment the following logs to see http calls headers and messages +#log4j.logger.feign=DEBUG #only WARN allowed for access loggers in http transport by default log4j.logger.org.apache.synapse.transport.http.access=WARN diff --git a/modules/distribution/src/core/jaggeryapps/portal/configs/designer.json b/modules/distribution/src/core/jaggeryapps/portal/configs/designer.json index 2f049839..86b79ac3 100644 --- a/modules/distribution/src/core/jaggeryapps/portal/configs/designer.json +++ b/modules/distribution/src/core/jaggeryapps/portal/configs/designer.json @@ -1,4 +1,5 @@ { + "isCloud" : false, "store": { "types": ["fs"] }, diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml new file mode 100644 index 00000000..ab34a520 --- /dev/null +++ b/modules/integration/pom.xml @@ -0,0 +1,41 @@ + + + + + + org.wso2.iot + wso2iot-parent + 3.1.0-SNAPSHOT + ../../pom.xml + + + 4.0.0 + wso2iot-integration + pom + WSO2 IoT Server - Integration Module + http://wso2.org + + + tests-artifacts + tests-common + + tests-iot-web-ui + + + diff --git a/modules/integration/tests-artifacts/pom.xml b/modules/integration/tests-artifacts/pom.xml new file mode 100644 index 00000000..b82a7758 --- /dev/null +++ b/modules/integration/tests-artifacts/pom.xml @@ -0,0 +1,33 @@ + + + + + + org.wso2.iot + wso2iot-integration + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + tests-artifacts + pom + WSO2 IoT - Integration Test Artifacts + + diff --git a/modules/integration/tests-common/admin-clients/pom.xml b/modules/integration/tests-common/admin-clients/pom.xml new file mode 100644 index 00000000..a536774f --- /dev/null +++ b/modules/integration/tests-common/admin-clients/pom.xml @@ -0,0 +1,34 @@ + + + + + + + org.wso2.iot + tests-common + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.iot.integration.common.clients + jar + WSO2 IoT - Integration Test Common Admin Clients + + diff --git a/modules/integration/tests-common/integration-test-utils/pom.xml b/modules/integration/tests-common/integration-test-utils/pom.xml new file mode 100644 index 00000000..f56d6b5f --- /dev/null +++ b/modules/integration/tests-common/integration-test-utils/pom.xml @@ -0,0 +1,41 @@ + + + + + + + org.wso2.iot + tests-common + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.iot.integration.common.utils + jar + WSO2 IoT Server - Integration Test Common Utils + + + + Apache License Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + + + diff --git a/modules/integration/tests-common/pom.xml b/modules/integration/tests-common/pom.xml new file mode 100644 index 00000000..027bb14a --- /dev/null +++ b/modules/integration/tests-common/pom.xml @@ -0,0 +1,39 @@ + + + + + + org.wso2.iot + wso2iot-integration + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + tests-common + pom + WSO2 IoT Server - Integration Test Common + + + + + web-ui-pages + + + diff --git a/modules/integration/tests-common/web-ui-pages/pom.xml b/modules/integration/tests-common/web-ui-pages/pom.xml new file mode 100644 index 00000000..7dcce232 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/pom.xml @@ -0,0 +1,125 @@ + + + + + + + org.wso2.iot + tests-common + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.iot.core.integration.ui.pages + jar + WSO2 IoT - Integration Test Common Web UI Pages + + + + org.wso2.carbon.automationutils + org.wso2.carbon.integration.common.admin.client + compile + + + org.wso2.carbon + org.wso2.carbon.user.mgt.stub + + + org.wso2.carbon + org.wso2.carbon.logging.view.stub + + + org.wso2.carbon + org.wso2.carbon.ndatasource.stub + + + org.wso2.carbon + org.wso2.carbon.server.admin.stub + + + org.wso2.carbon + org.wso2.carbon.throttle.stub + + + org.wso2.carbon + org.wso2.carbon.tenant.mgt.stub + + + org.wso2.carbon + org.wso2.carbon.application.mgt.stub + + + org.wso2.carbon + org.wso2.carbon.security.mgt.stub + + + org.wso2.carbon + org.wso2.carbon.identity.user.profile.stub + + + org.wso2.carbon + org.wso2.carbon.identity.user.profile.stub + + + org.slf4j + slf4j-api + + + + + org.wso2.carbon.automation + org.wso2.carbon.automation.extensions + compile + + + org.slf4j + slf4j-api + + + + + org.seleniumhq.selenium + selenium-java + + + org.seleniumhq.selenium + selenium-android-driver + + + compile + + + org.testng + testng + compile + + + org.wso2.carbon.automation + org.wso2.carbon.automation.test.utils + compile + + + org.wso2.carbon.automation + org.wso2.carbon.automation.engine + compile + + + + diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java new file mode 100644 index 00000000..31e473ce --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIElementMapper.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Read the mapper file and load the UI elements into Properties object. + */ +public class UIElementMapper { + + public static final Properties uiProperties = new Properties(); + private static UIElementMapper instance; + + private UIElementMapper(){ + } + + public static synchronized UIElementMapper getInstance() throws IOException { + if (instance == null) { + setStream(); + instance = new UIElementMapper(); + } + return instance; + } + + public static Properties setStream() throws IOException { + + InputStream inputStream = UIElementMapper.class.getResourceAsStream("/mapper.properties"); + + if (inputStream.available() > 0) { + uiProperties.load(inputStream); + inputStream.close(); + return uiProperties; + } + return null; + } + + public String getElement (String key) { + if (!uiProperties.isEmpty()) { + return uiProperties.getProperty(key); + } + return null; + } +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIUtils.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIUtils.java new file mode 100644 index 00000000..09346afb --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/UIUtils.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages; + +import org.apache.commons.logging.Log; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +/** + * This class contains the constants and common methods used in pages. + */ +public class UIUtils { + + public static long webDriverTimeOut = 10; + public static long webDriverTime = 60; + public static int threadTimeout = 1000; + + public static boolean isElementPresent(Log log, WebDriver driver, By by) { + try { + WebDriverWait wait = new WebDriverWait(driver, webDriverTime); + wait.until(ExpectedConditions.presenceOfElementLocated(by)); + driver.findElement(by); + return true; + } catch (NoSuchElementException e) { + log.error(by.toString() + " is not present"); + return false; + } + + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java new file mode 100644 index 00000000..c87dafa3 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/DevicesPage.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.devices; + +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.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceViewPage; + +import java.io.IOException; +import java.util.List; + +/** + * Class to represent the IOT devices page. In this page, all the enrolled devices are listed. + * User can perform following functions on the enrolled devices. + * 1. View the device. + * 2. View device analytics. + * 3. Edit the device. + * 4. Delete the device. + */ +public class DevicesPage { + + Log log = LogFactory.getLog(DevicesPage.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public DevicesPage(WebDriver driver) throws IOException { + + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("Device Management | IoT Server"))) { + throw new IllegalStateException("This is not the Device Management page"); + } + } + + /** + * This method checks whether the given device is enrolled and visible in the UI of the IOT server. + * @param name : The name of the device to be checked. + * @return : True if the device is enrolled and visible. False otherwise. + */ + public boolean isDeviceEnrolled(String name) { + List deviceNames = driver.findElements(By.tagName("h4")); + if (!deviceNames.isEmpty()) { + for (WebElement deviceName : deviceNames) { + if (deviceName.getText().contains(name)) { + return true; + } + } + } + return false; + } + + /** + * This method performs the navigation to the Device view of the given device. + * Here the navigation happens to the Connected cup device. + * @param deviceName : Name of the device. + * @return : The corresponding device view page. Null if not visible. + */ + public ConnectedCupDeviceViewPage viewDevice(String deviceName) throws IOException { + WebElement deviceTable = driver.findElement(By.xpath(uiElementMapper.getElement("iot.devices.table.xpath"))); + List data = deviceTable.findElements(By.cssSelector("a")); + for (WebElement e : data) { + String s = getLink(e, "/device/connectedcup?id="); + if (s != null) { + driver.get(s); + return new ConnectedCupDeviceViewPage(driver, deviceName); + } + } + return null; + } + + /** + * Method to extract the URL, which matches with the given parameters from an HTML element. + * @param element : WebElement, from which the URL should be extracted. + * @param lookupText : The parameters to be contained in the URL. + * @return : The URL String found. NULL if the URL is not found. + */ + private String getLink(WebElement element, String... lookupText) { + String link = element.getAttribute("href"); + boolean check = true; + for (String s : lookupText) { + if (!link.contains(s)) { + check = false; + } + } + return check ? link : null; + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java new file mode 100644 index 00000000..a6c55025 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/devices/EnrollDevicePage.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.devices; + +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.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceTypeViewPage; + +import java.io.IOException; + +/** + * Device Enrollment page. + * This page lists the all device types which are currently installed in the IOT server. + */ +public class EnrollDevicePage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + private Log log = LogFactory.getLog(EnrollDevicePage.class); + + public EnrollDevicePage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("Device Types | IoT Server"))) { + throw new IllegalStateException("This is not the Device Enrollment page"); + } + } + + /** + * This method checks whether the Connected cup device is installed. If the device is installed correctly, it is + * displayed in this page. + * @return : True if the device is visible in the page. False otherwise. + */ + public boolean isInstalled() { + boolean check = UIUtils.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + if (check) { + WebElement deviceDiv = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + WebElement tryBtn = deviceDiv.findElement(By.tagName("button")); + return tryBtn.isDisplayed(); + } + return false; + } + + /** + * Method to perform the navigation to Device type view page of the Connected cup. + * @return : The corresponding Device type view page. Null, if the element is not visible. + */ + public ConnectedCupDeviceTypeViewPage gotoConnectedCupDeviceTypeViewPage() throws IOException { + boolean check = UIUtils.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + if (check){ + WebElement deviceDiv = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.xpath"))); + WebElement tryBtn = deviceDiv.findElement(By.tagName("button")); + tryBtn.click(); + return new ConnectedCupDeviceTypeViewPage(driver); + } else { + log.error("Element not found..........................."); + return null; + } + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/error/IOTErrorPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/error/IOTErrorPage.java new file mode 100644 index 00000000..da402c96 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/error/IOTErrorPage.java @@ -0,0 +1,31 @@ +package org.wso2.iot.integration.ui.pages.error; + +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; +import org.wso2.iot.integration.ui.pages.UIUtils; + +import java.io.IOException; + +public class IOTErrorPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + private boolean isErrorPage = true; + + public IOTErrorPage (WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.error.page")))) { + isErrorPage = false; + throw new IllegalStateException("This is not the Error page"); + } + } + + public boolean isErrorPresent() { + return this.isErrorPage; + } +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/Graph.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/Graph.java new file mode 100644 index 00000000..1058f2f6 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/Graph.java @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.graphs; + +/** + * Class to store graph data + */ +public class Graph { + + private String graphId; + private String yAxis; + private String xAxis; + private String legend; + + public void setGraphId(String graphId) { + this.graphId = graphId; + } + + public String getyAxis() { + return yAxis; + } + + public void setyAxis(String yAxis) { + this.yAxis = yAxis; + } + + public String getxAxis() { + return xAxis; + } + + public void setxAxis(String xAxis) { + this.xAxis = xAxis; + } + + public String getLegend() { + return legend; + } + + public void setLegend(String legend) { + this.legend = legend; + } + + @Override + public String toString(){ + return String.format("The graph for graph id : %s, X - axis : %s, Y - axis : %s, legend : %s ", graphId, + xAxis, yAxis, legend); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/GraphHandler.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/GraphHandler.java new file mode 100644 index 00000000..6efcde09 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/graphs/GraphHandler.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.graphs; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +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.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.UIUtils; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * Graphs should also be tested in UI tests. So, this class contains methods to extract various properties of graphs.. + * Such as, + * - Legend + * - Tool Tips + * - X, Y axis properties + * - get the graph path values etc. + * Works with IOT server device view graphs and analytics graphs. + */ +public class GraphHandler { + private UIElementMapper uiElementMapper; + private Log log = LogFactory.getLog(GraphHandler.class); + private WebElement graphDiv; + private WebDriver driver; + private List graphs; + + public GraphHandler(WebDriver driver) throws IOException { + this.driver = driver; + uiElementMapper = UIElementMapper.getInstance(); + graphDiv = driver.findElement(By.xpath(uiElementMapper.getElement("iot.stats.graph.container.xpath"))); + } + + /** + * This method is to get all the elements of graphs and store in a Hash map. + * This simplifies iterating through the DOM every time finding for an element when having multiple graphs. + */ + public Map getGraphMap() { + HashMap graphMap = new HashMap<>(); + WebDriverWait wait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath( + uiElementMapper.getElement("iot.stat.graph.wrapper.xpath"))))); + List graphs = driver.findElements(By.xpath( + uiElementMapper.getElement("iot.stat.graph.wrapper.xpath"))); + for (WebElement e : graphs) { + Graph g = new Graph(); + String key = e.getAttribute("id").split("-")[1]; + g.setGraphId(key.toLowerCase().replace(" ", "")); + String xAxis = e.findElement(By.xpath(uiElementMapper.getElement("iot.stat.graph.xAxis.xpath"))).getText(); + g.setxAxis(xAxis); + String yAxis = e.findElement(By.xpath("//*[contains(@id, \"y_axis-" + key + "\")]")).getText(); + g.setyAxis(yAxis); + String legend = e.findElement(By.xpath("//*[contains(@id, \"legend-" + key + "\")]")).findElement( + By.tagName("span")).getText(); + g.setLegend(legend); + graphMap.put(key, g); + } + return graphMap; + } + + /** + * Get the number of graphs in the UI + */ + public int getGraphCount() { + try { + graphs = this.graphDiv.findElements(By.xpath("//*[contains(@class, \"chartWrapper\")]")); + } catch (NoSuchElementException e) { + log.error(String.format("Graph element is not found. \n %s", e.getMessage())); + } + return graphs.size(); + } + + /** + * Get the Web Element corresponds to the given graph id + * + * @param graphId : the id of the graph. + * @return Web Element of the graph + */ + public WebElement getGraphById(String graphId) { + graphs = this.graphDiv.findElements(By.xpath(uiElementMapper.getElement("iot.stat.graph.wrapper.xpath"))); + for (int i = 0; i < graphs.size() && graphs.size() > 0; i++) { + WebElement element = graphs.get(i); + if (element.getAttribute("id").toLowerCase().replace(" ", "").contains(graphId.toLowerCase())) { + return element; + } + } + return null; + } + + /** + * Check the graph path is visible or not. + * + * @param graph : web element of the graph + * @return : True if the path is visible. False otherwise + */ + public boolean isPathAvailable(WebElement graph) { + try { + WebElement graphContainer = getGraph(graph, uiElementMapper.getElement("iot.stat.graph.class.name")); + return graphContainer != null && graphContainer.findElement(By.tagName("path")).isDisplayed(); + } catch (NoSuchElementException e) { + log.error(String.format("No element found. \n %s", e.getMessage())); + return false; + } + } + + /** + * Check the path of the graph draws the values pushed by the device. As it takes some time, explicit wait of 10 + * seconds is added. + * + * @param graph : Web element of the graph + * @param val : Value which pushed by the device + * @return : True if the path is drawn to the values. False otherwise. + */ + public boolean isPathGetValues(WebElement graph, String val) { + WebElement graphContainer = getGraph(graph, uiElementMapper.getElement("iot.stat.graph.class.name")); + driver.manage().timeouts().implicitlyWait(UIUtils.webDriverTimeOut, TimeUnit.SECONDS); + String[] values; + if (graphContainer != null) { + values = graphContainer.findElement(By.tagName("path")).getAttribute("d").split(","); + for (String value : values) { + if (value.contains(val)) { + return true; + } + } + } + return false; + } + + /** + * This method returns the WebElement for graph with the given class name. + * + * @param graph : Outer container of the graphs + * @param className : Class name of the graph needed. + * @return the WebElement which defined by the given class name. Null if no element is found. + */ + private WebElement getGraph(WebElement graph, String className) { + List elements = graph.findElements(By.tagName("div")); + for (WebElement e : elements) { + if (e.getAttribute("class").contains(className)) { + return e; + } + } + return null; + } +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java new file mode 100644 index 00000000..b80d0efb --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceAddGroupPage.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.groups; + +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.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.UIUtils; + +import java.io.IOException; + +/** + * Add group page of iot server. This class contains methods to, + * 1. Create a new group + * 2. Submit an empty form + */ +public class DeviceAddGroupPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public DeviceAddGroupPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.groups.page")))) { + throw new IllegalStateException("This is not the Add Group page"); + } + } + + + /** + * This method performs creation of a new device group. + * @param name : The group name that is need to be created. + * @param description : the description for the group + * @return The resultant page. + */ + public DeviceGroupsPage addNewGroup(String name, String description) throws IOException { + + WebElement nameField = driver.findElement(By.id( + uiElementMapper.getElement("iot.device.group.addGroupForm.name.id"))); + WebElement descriptionField = driver.findElement(By.id( + uiElementMapper.getElement("iot.device.group.addGroupForm.description.id"))); + WebElement addGroupButton = driver.findElement(By.id( + uiElementMapper.getElement("iot.device.group.addGroupForm.addButton.id"))); + + nameField.sendKeys(name); + descriptionField.sendKeys(description); + + addGroupButton.click(); + + return new DeviceGroupsPage(driver); + } + + /** + * This method submits an empty form and returns the error message. + * @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"))); + WebElement descriptionField = driver.findElement(By.id( + uiElementMapper.getElement("iot.device.group.addGroupForm.description.id"))); + WebElement addGroupButton = driver.findElement(By.id( + uiElementMapper.getElement("iot.device.group.addGroupForm.addButton.id"))); + + nameField.sendKeys(""); + descriptionField.sendKeys(""); + + addGroupButton.click(); + + return driver.findElement(By.xpath( + uiElementMapper.getElement("iot.device.groups.add.emptyfrom.error"))).getText(); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java new file mode 100644 index 00000000..becb12fa --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/groups/DeviceGroupsPage.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.groups; + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; +import java.util.List; + +/** + * This class represents the Groups page. + */ +public class DeviceGroupsPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public DeviceGroupsPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.groups.page")))) { + throw new IllegalStateException("This is not the Groups page"); + } + } + + /** + * Method to go to the Add device group page, by clicking the Add group button. + * @return : Add device groups page. + */ + public DeviceAddGroupPage addNewGroup() throws IOException { + WebElement addNewGroupBtn = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.device.viewGroup.empty.addGroup.xpath"))); + addNewGroupBtn.click(); + return new DeviceAddGroupPage(driver); + } + + /** + * This method checks whether the created group is visible in the UI. + * @param groupName : Name of the group created. + * @return : True if the group is visible. False otherwise. + */ + public boolean isGroupCreated(String groupName) { + WebElement table = driver.findElement(By.xpath(uiElementMapper.getElement("iot.device.table.id"))); + List allGroupNames = table.findElements(By.tagName("td")); + + for (WebElement name : allGroupNames) { + if (name.getText().contains(groupName)){ + return true; + } + } + return false; + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTAdminDashboard.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTAdminDashboard.java new file mode 100644 index 00000000..828e582b --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTAdminDashboard.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.home; + +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.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.devices.DevicesPage; +import org.wso2.iot.integration.ui.pages.devices.EnrollDevicePage; +import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage; +import org.wso2.iot.integration.ui.pages.groups.DeviceGroupsPage; +import org.wso2.iot.integration.ui.pages.login.LoginPage; +import org.wso2.iot.integration.ui.pages.uesr.AddUserPage; +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(IOTAdminDashboard.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public IOTAdminDashboard(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait wait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + + if (!wait.until(ExpectedConditions.titleIs(uiElementMapper.getElement("cdmf.home.page")))) { + throw new IllegalStateException("This is not the home page"); + } + } + + /** + * Performs the logout action. + * @return : The IOT login page + */ + public LoginPage logout() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).click(); + WebElement logout = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.logout.link.xpath"))); + logout.click(); + return new LoginPage(driver); + } + + /** + * Performs the navigation to Add device group page. + * @return : Add Device Group page. + */ + public DeviceAddGroupPage addGroup() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.device.group.addButton.xpath"))).click(); + return new DeviceAddGroupPage(driver); + } + + /** + * Performs the navigation to Group listing page. + * @return : Groups page. + */ + public DeviceGroupsPage viewGroups() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.device.group.viewButton.xpath"))).click(); + return new DeviceGroupsPage(driver); + } + + /** + * Navigates to the Add User page. + * @return : Add user page. + */ + public AddUserPage addUser() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.addButton.xpath"))).click(); + return new AddUserPage(driver); + } + + /** + * Navigates to the User Listing page. + * @return : User Listing page. + */ + public UserListingPage viewUser() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.user.viewButton.xpath"))).click(); + return new UserListingPage(driver); + } + + /** + * Navigates to the New device enrollment page. + * @return : Enroll Device page. + */ + public EnrollDevicePage enrollNewDevice() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.device.addBtn.xpath"))).click(); + return new EnrollDevicePage(driver); + } + + /** + * Navigates to the Devices listing page. + * @return : devices listing page. + */ + public DevicesPage viewDevices() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.device.viewBtn.xpath"))).click(); + return new DevicesPage(driver); + } + + //ToDo : Need to add policy methods +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTHomePage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTHomePage.java new file mode 100644 index 00000000..58b929e9 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/home/IOTHomePage.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.home; + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.devices.EnrollDevicePage; +import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage; +import org.wso2.iot.integration.ui.pages.login.LoginPage; + +import java.io.IOException; + +/** + * This class represents the IOT server home page. + */ +public class IOTHomePage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public IOTHomePage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + // Check that we're on the right page. + WebDriverWait wait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!wait.until(ExpectedConditions.titleIs(uiElementMapper.getElement("cdmf.user.home.page")))) { + throw new IllegalStateException("This is not the home page"); + } + } + + /** + * Method to check the current User name + * @return : True if the user name matches the logged in user. False otherwise. + */ + public boolean checkUserName() { + String name = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).getText(); + return name.contains(uiElementMapper.getElement("iot.user.login.username")); + } + + + /** + * Performs the logout function. + * @return : IOT login page. + */ + public LoginPage logout() throws IOException { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.registered.name"))).click(); + WebElement logout = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.logout.link.xpath"))); + logout.click(); + return new LoginPage(driver); + } + + /** + * Navigates to the New device enrollment page. + * @return : Enroll Device page. + */ + public EnrollDevicePage enrollNewDevice() throws IOException { + driver.findElement(By.xpath("iot.home.page.uuf-menu.xpath")).click(); + driver.findElement(By.xpath("iot.home.page.uuf-menu.devicemgt.xpath")).click(); + driver.findElement(By.xpath("iot.home.enrollDevice.xpath")).click(); + return new EnrollDevicePage(driver); + } + + /** + * Performs the navigation to Add device group page. + * @return : Add Device Group page. + */ + public DeviceAddGroupPage addNewGroup() throws IOException { + driver.findElement(By.xpath("iot.home.page.uuf-menu.xpath")).click(); + driver.findElement(By.xpath("iot.home.page.uuf-menu.groupmgt.xpath")).click(); + driver.findElement(By.xpath("iot.device.viewGroup.empty.addGroup.xpath")).click(); + return new DeviceAddGroupPage(driver); + } + + //ToDo : To add policies + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java new file mode 100644 index 00000000..91fb30c6 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/login/LoginPage.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.login; + +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.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import org.wso2.iot.integration.ui.pages.home.IOTHomePage; +import org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage; + +import java.io.IOException; + +/** + * Represents the Login page of the iot server. + * + */ +public class LoginPage { + + private static final Log log = LogFactory.getLog(LoginPage.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + private WebElement userNameField; + private WebElement passwordField; + private WebElement loginButton; + + public LoginPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.login.page")))) { + throw new IllegalStateException("This is not the Login page"); + } + userNameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.login.input.username.xpath"))); + passwordField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.login.input.password.xpath"))); + loginButton = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.button.xpath"))); + } + + /** + * 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); + userNameField.sendKeys(username); + passwordField.sendKeys(password); + loginButton.click(); + 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); + userNameField.sendKeys(username); + passwordField.sendKeys(password); + loginButton.click(); + 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"))); + registerLink.click(); + return new NewUserRegisterPage(driver); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceInterface.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceInterface.java new file mode 100644 index 00000000..2ea11f7a --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceInterface.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.samples; + +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.WebElement; +import org.openqa.selenium.interactions.Action; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +/** + * Class to represent the Connected cup device interface. + * This device is a virtual device, which allows users to change Temperature and Level values and put an order. + */ +public class ConnectedCupDeviceInterface { + + private Log log = LogFactory.getLog(ConnectedCupDeviceInterface.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public ConnectedCupDeviceInterface(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("Connected Coffee Cup"))) { + throw new IllegalStateException("This is not the Connected cup device page"); + } + } + + /** + * Method to perform the order coffee functionality. + * @return : True if the element is present and action is performed. False otherwise. + */ + public boolean orderCoffee() { + if (UIUtils.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.orderCoffee.xpath")))) { + WebElement orderBtn = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.orderCoffee.xpath"))); + orderBtn.click(); + return true; + } + return false; + } + + /** + * Method to change the temperature level. + * @param temp : The value to be set. + * @return : True if the element is present and value is set. False otherwise. + */ + public boolean changeTemperature(String temp) { + if (UIUtils.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.temperature.xpath")))) { + WebElement tempSlider = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.temperature.xpath"))); + moveSlider(tempSlider, Integer.parseInt(temp)); + driver.manage().timeouts().implicitlyWait(UIUtils.webDriverTime, TimeUnit.SECONDS); + return true; + } + return false; + } + + /** + * Method to change the Coffee level. + * @param level : The value to be set. + * @return : True if the element is present and value is set. False otherwise. + */ + public boolean changeCoffeeLevel(String level) { + if (UIUtils.isElementPresent(log, driver, By.xpath( + uiElementMapper.getElement("iot.sample.coffee.level.xpath")))) { + WebElement lvlSlider = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.coffee.level.xpath"))); + moveSlider(lvlSlider, Integer.parseInt(level)); + driver.manage().timeouts().implicitlyWait(UIUtils.webDriverTime, TimeUnit.SECONDS); + return true; + } + return false; + } + + /** + * This method performs the slider change action of the web interface. + * @param slider : The element of the slider to be changed. + * @param val : Value to be set. + */ + private void moveSlider(WebElement slider, int val) { + Actions move = new Actions(driver); + Action action = move.dragAndDropBy(slider, 0, val).build(); + action.perform(); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java new file mode 100644 index 00000000..2fa4e605 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceTypeViewPage.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.samples; + + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; + +/** + * This class represents the Device Type View page of the Connected cup device, which has the functionality for + * download the device agent. + */ +public class ConnectedCupDeviceTypeViewPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public ConnectedCupDeviceTypeViewPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + if (!driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText(). + contains("Connected Cup")) { + throw new IllegalStateException("This is not the Connected cup device type view page"); + } + } + + /** + * This method verifies that the pop up modal for inserting a name for device is present. + * @return : True if the Modal pop up is displayed. False otherwise. + */ + public boolean isPopUpPresent() throws InterruptedException { + WebElement createInstanceBtn = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.createInstanceBtn.xpath"))); + createInstanceBtn.click(); + WebDriverWait wait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.modal.popup.xpath"))))); + + return driver.findElement(By.xpath(uiElementMapper.getElement("iot.sample.modal.popup.xpath"))).isDisplayed(); + } + + /** + * This method performs the enrolment process of the connected cup device. After clicking the Download button in + * the popup, user should be navigated to the device type view page again. + * This method checks the navigation and return true if navigation is correct. + * @param name : Name for the device. + * @return : True if navigates to the Device type view page without errors. False otherwise. + */ + public boolean enrollDevice(String name) { + WebElement nameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.createInstance.nameField.xpath"))); + WebElement createButton = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.createInstance.downloadBtn.xpath"))); + nameField.sendKeys(name); + createButton.click(); + return driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.page.title"))).getText().contains("Connected Cup"); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java new file mode 100644 index 00000000..5631a564 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/samples/ConnectedCupDeviceViewPage.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.samples; + +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.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.graphs.Graph; +import org.wso2.iot.integration.ui.pages.graphs.GraphHandler; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * This class represents the Connected cup device view page. + * In this page, there are following elements. + * 1. Device overview. (Whether the device is active or not) + * 2. Device operations. (Operations which are performed on the device) + * 3. Device Stats + * + * In this class, device operations and device stats are validated. + */ +public class ConnectedCupDeviceViewPage { + + private Map graphMap = new HashMap<>(); + private Log log = LogFactory.getLog(ConnectedCupDeviceViewPage.class); + private WebDriver driverServer; + private WebDriver driverDevice; + private UIElementMapper uiElementMapper; + private GraphHandler handler; + + public ConnectedCupDeviceViewPage(WebDriver driver, String name) throws IOException { + this.driverServer = driver; + this.driverDevice = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + this.handler = new GraphHandler(driverServer); + + if (!driver.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.view.page.title"))).getText(). + contains(name)) { + throw new IllegalStateException("This is not the Connected cup device type view page"); + } + handler = new GraphHandler(driverServer); + graphMap = handler.getGraphMap(); + } + + /** + * This method executes Connected cup sample web app. + * @return : The Connected cup web page. + */ + public ConnectedCupDeviceInterface gotoDevice() throws IOException { + WebDriverWait wait = new WebDriverWait(driverServer, UIUtils.webDriverTime); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath")))); + String link = driverServer.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).getAttribute("href"); + driverDevice.get(link); + return new ConnectedCupDeviceInterface(driverDevice); + } + + /** + * Gets the connected cup device web app URL. + * @return : Link of the connected cup device web app. + */ + public String getDeviceLink() { + WebDriverWait wait = new WebDriverWait(driverServer, UIUtils.webDriverTime); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath")))); + return driverServer.findElement(By.xpath( + uiElementMapper.getElement("iot.sample.connectedcup.gotodevice.xpath"))).getAttribute("href"); + } + + /** + * This method checks whether there are expected number of graphs are available in the UI. + * @param count : Number of graphs expected. + * @return : True if there are count number of graphs. False otherwise. + */ + public boolean isGraphsAvailable(int count) { + return handler.getGraphCount() == count; + } + + /** + * Checks whether the selected graph axes represent the given values. + * @param axis : Graph axis. X or Y + * @param graphId : Id of the graph + * @param axisName : Name which is expected to be displayed. + * @return : True if given axis contains the expected title. False otherwise or, there are no graphs present. + */ + public boolean graphAxisName(String axis, String graphId, String axisName) { + if (graphMap.size() != 0) { + if (axis.toLowerCase().contains("x")) { + return graphMap.get(graphId).getxAxis().contains(axisName); + } else { + return graphMap.get(graphId).getyAxis().contains(axisName); + } + } + log.error("There are no graphs found."); + return false; + } + + /** + * Check the legend of the selected graph have the expected title. + * @param graphId : Id of the graph. + * @param legend : Expected value to be displayed in the legend. + * @return : True if legend contains the expected value. False otherwise or there are no graphs present. + */ + public boolean graphLegendName(String graphId, String legend) { + if (graphMap.size() != 0) { + if (graphMap.get(graphId) != null){ + return graphMap.get(graphId).getLegend().contains(legend); + } + log.error(String.format("Graph for %s is not found.", graphId)); + return false; + } + log.error("There are no graphs found."); + return false; + } + + /** + * Method to check the graph path is displayed in the UI for given graph. + * @param graphId : Id of the graph. + * @return : True of path is displayed. False otherwise or no graphs are present. + */ + public boolean checkGraphPath(String graphId) { + WebElement graph = handler.getGraphById(graphId); + if (graph != null) { + return handler.isPathAvailable(graph); + } else { + log.error(String.format("Graph for Id %s is not present.", graphId)); + return false; + } + } + + /** + * Method to verify that the graphs get readings from the device. + * @param graphId : Id of the graph. + * @param value : Value which is expected to be displayed in the graph. + * @return : True if the value is displayed in the graph. False otherwise or graph is null. + */ + public boolean checkGraphValues(String graphId, String value) { + WebElement graph = handler.getGraphById(graphId); + driverServer.manage().timeouts().implicitlyWait(UIUtils.webDriverTime, TimeUnit.SECONDS); + if (graph != null) { + return handler.isPathGetValues(graph, value); + } else { + log.error(String.format("Graph for Id %s is not present.", graphId)); + return false; + } + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java new file mode 100644 index 00000000..3305fbda --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/AddUserPage.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.uesr; + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; + + +/** + * This class represents the add user page of the IOT server. + */ +public class AddUserPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public AddUserPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.user.add.page")))) { + throw new IllegalStateException("This is not the Add User page"); + } + } + + /** + * 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. + */ + public UserAddedConfirmationPage createNewUser(String userName, String firstName, String lastName, String email) + throws IOException { + + WebElement userNameField = driver.findElement(By.id( + uiElementMapper.getElement("iot.admin.addUser.username.id"))); + WebElement firstNameField = driver.findElement(By.id( + uiElementMapper.getElement("iot.admin.addUser.firstName.id"))); + WebElement lastNameField = driver.findElement(By.id( + uiElementMapper.getElement("iot.admin.addUser.lastName.id"))); + WebElement emailField = driver.findElement(By.id( + uiElementMapper.getElement("iot.admin.addUser.email.id"))); + + userNameField.sendKeys(userName); + firstNameField.sendKeys(firstName); + lastNameField.sendKeys(lastName); + emailField.sendKeys(email); + + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))).click(); + + return new UserAddedConfirmationPage(driver); + } + +} \ No newline at end of file diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java new file mode 100644 index 00000000..dcba72e6 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/EditUserPage.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.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.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +/** + * This class represents the Edit user page of the IOT server + */ +public class EditUserPage { + + private static final Log log = LogFactory.getLog(EditUserPage.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public EditUserPage(WebDriver driver) throws Exception { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))){ + throw new IllegalStateException("This is not the Edit User page"); + } + } + + public void editUser(String password, String firstName, String lastName) { + driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.add.input.password.xpath"))); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java new file mode 100644 index 00000000..b40dfe51 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/NewUserRegisterPage.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.uesr; + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.login.LoginPage; + +import java.io.IOException; + +/** + * This class represents the new user registration page. + * User registration page has the registration form for new users to enter the required data and the submit button. + */ +public class NewUserRegisterPage { + + private WebDriver driver; + private WebElement firstNameField; + private WebElement lastNameField; + private WebElement emailField; + private WebElement userNameField; + private WebElement passwordField; + private WebElement passwordConfirmationField; + private WebElement registerButton; + + public NewUserRegisterPage(WebDriver driver) throws IOException { + this.driver = driver; + UIElementMapper uiElementMapper = UIElementMapper.getInstance(); + + // Check that we're on the right page. + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains(uiElementMapper.getElement("cdmf.register.page")))) { + throw new IllegalStateException("This is not the Register page"); + } + + 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"))); + } + + /** + * 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 { + handleAction(firstName, lastName, email, userName, password, confirmPassword); + return new LoginPage(driver); + } + + /** + * Following method is to validate the user registration form. + * */ + public void validateForm(String firstName, String lastName, String email, String userName, + String password, String confirmPassword) { + handleAction(firstName, lastName, email, userName, password, confirmPassword); + } + + /** + * Support method to populate the User registration form. + * @param firstName : First name of the user. + * @param lastName : Last name of the user. + * @param email : E mail of the user. + * @param userName : User name of the user. + * @param password : Password for the user. + * @param confirmPassword : Confirmation password. + */ + private void handleAction(String firstName, String lastName, String email, String userName, String password, + String confirmPassword) { + clearForm(); + firstNameField.sendKeys(firstName); + lastNameField.sendKeys(lastName); + emailField.sendKeys(email); + userNameField.sendKeys(userName); + passwordField.sendKeys(password); + passwordConfirmationField.sendKeys(confirmPassword); + registerButton.click(); + } + + /** + * Support method to clear the Registration form. + */ + private void clearForm() { + firstNameField.clear(); + lastNameField.clear(); + emailField.clear(); + userNameField.clear(); + passwordField.clear(); + passwordConfirmationField.clear(); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java new file mode 100644 index 00000000..a32087e4 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserAddedConfirmationPage.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.uesr; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; + +/** + * This class represents the confirmation page for adding a new user. + */ +public class UserAddedConfirmationPage { + + public UserAddedConfirmationPage(WebDriver driver) throws IOException { + UIElementMapper uiElementMapper = UIElementMapper.getInstance(); + + driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.view.btn.xpath"))).click(); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java new file mode 100644 index 00000000..7d6fe4e1 --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/UserListingPage.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.uesr; + +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.wso2.iot.integration.ui.pages.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import java.io.IOException; + +/** + * Class to represent the user listing page. + */ +public class UserListingPage { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public UserListingPage(WebDriver driver) throws IOException { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + } + + /** + * Performs the delete user action. + * @return After deleting a user, returns back to the user listing page. + */ + public UserListingPage deleteUser() throws IOException, InterruptedException { + WebElement deleteBtn = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.deleteUser.btn.xpath"))); + + WebDriverWait wait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + wait.until(ExpectedConditions.visibilityOf(deleteBtn)); + deleteBtn.click(); + + WebElement deleteConfirmationBtn = driver.findElement( + By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.yes.link.xpath"))); + wait.until(ExpectedConditions.visibilityOf(deleteConfirmationBtn)); + deleteConfirmationBtn.click(); + + Thread.sleep(UIUtils.threadTimeout); + WebElement deleteSuccessBtn = driver.findElement( + By.xpath(uiElementMapper.getElement("iot.admin.deleteUser.success.link.xpath"))); + deleteSuccessBtn.click(); + + return new UserListingPage(driver); + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java new file mode 100644 index 00000000..a4d3964e --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/java/org/wso2/iot/integration/ui/pages/uesr/ViewUserPage.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.ui.pages.uesr; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.UIUtils; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +/** + * Class to represent the user view. + */ +public class ViewUserPage { + + private static final Log log = LogFactory.getLog(ViewUserPage.class); + private WebDriver driver; + private UIElementMapper uiElementMapper; + + public ViewUserPage (WebDriver driver) throws Exception { + this.driver = driver; + this.uiElementMapper = UIElementMapper.getInstance(); + + WebDriverWait webDriverWait = new WebDriverWait(driver, UIUtils.webDriverTimeOut); + if (!webDriverWait.until(ExpectedConditions.titleContains("User Management | IoT Server"))){ + throw new IllegalStateException("This is not the User view page"); + } + } + +} diff --git a/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties b/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties new file mode 100644 index 00000000..edba2fed --- /dev/null +++ b/modules/integration/tests-common/web-ui-pages/src/main/resources/mapper.properties @@ -0,0 +1,658 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. +# + +# CDMF Page titles ----------------------------------------------------------------------------------------------------- +cdmf.home.page=Home | CDMF +cdmf.login.page=Login | CDMF +cdmf.register.page=Register | CDMF +cdmf.error.page=Error | CDMF +cdmf.user.home.page=Device Management | CDMF +cdmf.groups.page=Group Management | CDMF +cdmf.user.add.page=User Management | Add User | CDMF + +# User registration and login details----------------------------------------------------------------------------------- + +iot.user.add.firstname=firstname +iot.user.add.lastname=lastname +iot.user.add.username=testUser +iot.user.add.password=testPassword +iot.user.add.email=username@wso2.com + +iot.user.login.username=testUser +iot.user.login.password=testPassword + + +# User registration and login ui---------------------------------------------------------------------------------------- + +iot.user.registered.name=/html/body/header/div/div[2]/ul/li/a/span[2] + +iot.user.add.input.firstname.xpath=//*[@id="first_name"] +iot.user.add.input.lastname.xpath=//*[@id="last_name"] +iot.user.add.input.username.xpath=//*[@id="user_name"] +iot.user.add.input.password.xpath=//*[@id="password"] +iot.user.add.input.confirmpassword.xpath=//*[@id="password_confirmation"] +iot.user.add.input.email.xpath=//*[@id="email"] +iot.user.add.register.button.xpath=//*[@id="add-user-btn"] + + +iot.user.login.input.username.xpath=//*[@id="signInForm"]/div[1]/input +iot.user.login.input.password.xpath=//*[@id="signInForm"]/div[2]/input +iot.user.login.button.xpath=//*[@id="signInForm"]/div[3]/button + +iot.user.register.link.xpath=//*[@id="register-link-wrapper"]/a + +# Devices page elements ------------------------------------------------------------------------------------------------ + +iot.home.page.uuf-menu.xpath=//*[@id="_uuf-navmenu-button"] + +iot.home.page.uuf-menu.devicemgt.xpath=//*[@id="_uuf-navmenu-items"]/ul/li[1]/a +iot.home.page.uuf-menu.groupmgt.xpath=//*[@id="_uuf-navmenu-items"]/ul/li[2]/a +iot.home.page.uuf-menu.policymgt.xpath=//*[@id="_uuf-navmenu-items"]/ul/li[3]/a + +iot.home.page.title.xpath=/html/body/div[3]/div[1]/div/span +iot.admin.dashboard.title.xpath=/html/body/div[3]/div[1]/div/span + +iot.home.enrollDevice.xpath=//*[@id="ast-container"]/div/p/a +iot.user.logout.link.xpath=/html/body/header/div/div[2]/ul/li/ul/li[2]/a + +iot.devices.table.xpath=//*[@id="device-grid"] + +# Register page error elements ----------------------------------------------------------------------------------------- +#//*[@id="user-create-error-msg"] +iot.user.register.form.error=user-create-error-msg + +# Admin dashboard Device ----------------------------------------------------------------------------------------------- +iot.admin.device.viewBtn.xpath=//a[@href='/devicemgt/devices'] +iot.admin.device.addBtn.xpath=//a[@href='/devicemgt/device/enroll'] + +# Incorrect login Credentials ------------------------------------------------------------------------------------------ +iot.user.login.username.error=username-error +iot.user.login.password.error=password-error +iot.user.login.incorrect.xpath=/html/body/div/div/div/div[1] +iot.user.login.shortPassword=password-error + +iot.dashboard.device.div.xpath=/html/body/div[3]/div[7]/div[1]/div/div/div[1] + +#Grouping -------------------------------------------------------------------------------------------------------------- + +iot.device.group.addButton.xpath=/html/body/div[3]/div[2]/div/div[3]/div[2]/div/div[2]/div[2]/span[2]/a[2]/span/i[2] +iot.device.group.viewButton.xpath=/html/body/div[3]/div[2]/div/div[3]/div[2]/div/div[2]/div[2]/span[2]/a[1]/span/i[2] + +iot.device.group.addNewGroup.xpath=/html/body/div[3]/div/div[1]/div/p[1] + +iot.device.viewGroup.empty.addGroup.xpath=//*[@id="ast-container"]/div/p/a + +iot.device.group.addGroupForm.name.id=name +iot.device.group.addGroupForm.description.id=description +iot.device.group.addGroupForm.addButton.id=add-group-btn + +iot.device.groups.view.header.xpath=/html/body/div[3]/div[2]/div/h1[1] + +#/html/body/div[3]/div[2]/div/div[3]/div/div/div[1]/label +iot.device.groups.add.emptyfrom.error=/html/body/div[3]/div[2]/div/div[3]/div/div/div[1]/label + +iot.device.table.id=//*[@id="ast-container"] + +#Add user -------------------------------------------------------------------------------------------------------------- +iot.admin.user.addButton.xpath=/html/body/div[3]/div[2]/div/div[3]/div[3]/div/div[2]/div[2]/span[2]/a[2] +iot.admin.user.viewButton.xpath=/html/body/div[3]/div[2]/div/div[3]/div[3]/div/div[2]/div[2]/span[2]/a[1] + +iot.admin.user.added.page.subtitle.xpath="//p[@class='page-sub-title']" +iot.admin.user.listing.page.subtitle.xpath="//span[@class='page-sub-title']" + +iot.admin.addUser.username.id=username +iot.admin.addUser.firstName.id=firstname +iot.admin.addUser.lastName.id=lastname +iot.admin.addUser.email.id=emailAddress +iot.admin.addUser.roles.id=roles + +iot.admin.addUser.add.btn.xpath=//*[@id="add-user-btn"] +iot.admin.addUser.view.btn.xpath=//*[@id="user-created-msg"]/div/button + +iot.admin.deleteUser.btn.xpath=//*[@id="user-user1"]/td[5]/a[3]/span[1]/i[2] +iot.admin.deleteUser.yes.link.xpath=//*[@id="remove-user-yes-link"] +iot.admin.deleteUser.success.link.xpath=//*[@id="modal-footer-content"]/div/a +iot.admin.addUser.formError.xpath=//*[@id="user-create-error-msg"] + +#----- User view page heading ------------------------------------------------------------------------------------------ + +iot.user.view.page.heading.xpath=/html/body/div[3]/div[1]/div/label + +#----- Editing a user--------------------------------------------------------------------------------------------------- + +iot.admin.viewUser.btn.xpath=//*[@id="user1"]/td[5]/a[1]/span[1]/i[2] +iot.admin.editUser.btn.xpath=//*[@id="userEditBtn"] +iot.admin.editUser.edit.btn.xpath=//*[@id="add-user-btn"] + +#---------------------------Testing the samples ------------------------------------------------------------------------ +iot.sample.connectedcup.xpath=//*[@id="connectedcup"] +iot.sample.connectedcup.try.btn.xpath=//button[contains(@id,'connectedcup_btn')] +iot.sample.connectedcup.try.btn.id=connectedcup_btn +iot.sample.connectedcup.page.title=//h1[@class='grey '] +iot.sample.connectedcup.view.page.title=//label[@class='device-id device-select'] +iot.sample.connectedcup.createInstanceBtn.xpath=//a[@class='download-link btn-operations'] +iot.sample.connectedcup.createInstance.nameField.xpath=//input[@class='connectedCupName'] +iot.sample.connectedcup.createInstance.downloadBtn.xpath=//a[contains(@class,'btn-operations')] +iot.sample.modal.popup.xpath=//div[@class='modalpopup-content'] + +iot.sample.connectedcup.gotodevice.xpath=//a[@class='btn-operations'] +iot.sample.connectedcup.device.title.xpath=/html/body/div[4]/h1 + +iot.sample.orderCoffee.xpath=//*[@id="order-cup"] +iot.sample.coffee.level.xpath=//*[@id="amount_coffee"] +iot.sample.temperature.xpath=//*[@id="amount_temp"] + +iot.sample.analytics.link.xpath=//*[@id="device_statistics"]/a + +iot.sample.coffeelevel.graph.path=//*[@id="chart-Coffee Level"]/svg/path[1] +iot.sample.temperature.graph.path=//*[@id="chart-Temperature"]/svg/path[1] + + +iot.try.devices.div.classname=//div[@class='try-device-container'] +iot.try.device.text.xpath=//p[contains(@class,'try-device-text')] + + +#------------------ Graphs (Device View) ------------------------------------------------------------------------------- +iot.stats.graph.container.xpath=//*[@id="div-chart"] +iot.stat.graph.wrapper.xpath=//*[contains(@class, "chartWrapper")] +iot.stat.graph.xAxis.xpath=//*[contains(@class, "custom_x_axis")] +iot.stat.graph.class.name=custom_rickshaw_graph rickshaw_graph + +#----------------------------------------------------------------------------------------------------------------------- +#iot.user.delete.button=//*[@id="inosh"]/td[5]/a[3] +#iot.user.delete.button.confirm=remove-user-yes-link +#iot.user.delete.button.success=remove-user-success-link +#iot.roles.add.button=appbar-btn- +#iot.roles.add.rolename.input=rolename +#iot.roles.add.role.button=add-role-btn +#iot.roles.add.role.created.msg.div=role-created-msg +#iot.roles.update.rolename.input=rolename +#iot.roles.update.role.button=add-role-btn +#iot.roles.update.role.created.msg.div=role-created-msg +#iot.roles.update.role.created.success.msg=ROLE WAS UPDATED SUCCESSFULLY +#iot.configuration.android.tab.identifier=id('androidConfigLink') +#iot.configuration.widows.tab.identifier=id('windowsConfigLink') +#iot.configuration.ios.tab.identifier=id('iosConfigLink') +#iot.configuration.general.tab.identifier=id('generalConfigLink') +#iot.configuration.general.input.monitoringFr.identifier=id('monitoring-config-frequency') +#iot.configuration.general.button.save.identifier=id('monitoring-config-frequency') +#iot.configuration.saved.lable.identifier=id('record-created-msg') +#iot.configuration.saved.lable.val=Please click "Go back to configurations", if you wish to save another configuration or click "Exit" to complete the process and go back to the dashboard. +#iot.configuration.saved.button.back.identifier=id('btnBack') +#iot.configuration.saved.button.back.val=Go back to configurations +#iot.configuration.saved.button.exit.identifier=id('btnExit') +#iot.configuration.saved.button.exit.val=Exit +#iot.configuration.android.select.identifier=id('android-config-notifier') +#iot.configuration.android.input.identifier=id('android-config-notifier-frequency') +#iot.configuration.android.button.save.identifier=id('save-android-btn') +#iot.configuration.windows.input.identifier=id('windows-config-notifier-frequency') +#iot.configuration.windows.button.save.identifier=id('save-windows-btn') +#iot.notification.bubble.identifier=notification-bubble +#iot.notification.unread.identifier=unReadNotifications +#iot.notification.all.identifier=allNotifications +# +# +# +# +#app.sign.in.button=button.btn +#app.redMine.login.button.name=login +#app.redMine.issue.button=New issue +#app.redMine.issue.subject=issue_subject +#app.redMine.issue.description=issue_description +#app.redMine.issue.submit=commit +#app.AddNew.App.link=Add New Application +#new.app.add.app.name=applicationName +#new.app.add.app.key=applicationKey +#new.app.add.app.icon=icon +#new.app.add.app.Description=applicationDescription +#new.app.add.app.edit.Description=appDescriptionEdit_textarea +#new.app.add.app.type=applicationType +#app.issue.version.id=issue_fixed_version_id +#app.database.db.environment.id=rssInstances +#app.database.db.environment.user=js_db_user +#app.database.db.environment.template=js_db_template +#new.app.add.repository.type=repositoryType +#create.new.app.button=appcreation +#app.homepage.search.textBox=search +#app.first.element.of.home.page=/html/body/div/div/article/section/ul/li[2]/div/h2/a/b +#app.overview.page.app.type.id=apptype +#app.overview.page.app.description.id=description +#app.overview.page.repository.type.id=repotype +#app.overview.page.app.owner.id=appOwner +#app.overview.page.app.key.xpath=/html/body/div/div/article/section[2]/div/div/div/p +#app.add.member.link=Add Members +#app.add.member.name=allUsersList +#app.invite.users= btn_nvite_users +#app.add.add.to.list.button=addToListBtn +#app.add.branch.link=Create Branch +#app.add.second.branch.xpath=(//a[contains(text(),'Branch')])[2] +#app.add.branch.version=create_branchtrunk +#app.add.branch.button.xpath=//input[@value='Create Branch'] +#app.add.branch.two.button.xpath=(//input[@value='Create Branch'])[2] +#app.navigate.Link=Repos & Builds +#app.navigate.Governance.page.link=menu_governance +#app.navigate.isue.page.link.id=menu_trackIssues +#app.trunk.overview.xpath=/html/body/div/div/article/section[3]/div/ul/li/p/strong +#app.trunk.build.status.xpath=/html/body/div/div/article/section[3]/div/ul/li[2]/p/span/strong +#governance.page.firstElement.xpath=/html/body/div/div[2]/article/section/div[2]/ul/li/ul/li/div/strong +#governance.page.firstElement.date.xpath=/html/body/div/div[2]/article/section/div[2]/ul/li/ul/li[2]/div[2]/form/div/input +#governance.page.date.save.xpath=/html/body/div/div[2]/article/section/div[2]/ul/li/ul/li[2]/div[2]/form/div/button +#governance.page.promote.key.xpath=/html/body/div/div[2]/article/section/div[2]/ul/li/ul/li[3]/div/ul/li[2]/a/span +#code.completed.status=(//input[@id='registry.custom_lifecycle.checklist.option.0.item'])[last()] +#code.review.status=(//input[@id='registry.custom_lifecycle.checklist.option.1.item'])[last()] +#design.review.status=(//input[@id='registry.custom_lifecycle.checklist.option.2.item'])[last()] +#app.application.overview.page=Overview +#app.overview.page.team.details.id=userCountList +#app.team.page.id=menu_userAdmin +#app.add.member.page.id=btnAddMembers +#app.issue.redMine.tab.link=Track Issues +#app.testing.first.element.xpath=/html/body/div/div[2]/article/section/div[2]/ul[2]/li/ul/li/div/strong +#app.testing.date.save.xpath=/html/body/div/div[2]/article/section/div[2]/ul[2]/li/ul/li[2]/div/form/div/button +#app.testing.first.element.arrow.xpath=/html/body/div/div[2]/article/section/div[2]/ul[2]/li/ul/li[3]/div/ul/li[2]/a +#app.factory.issue.total.count.xpath=/html/body/div/div[2]/article/section/section/div/ul/li[2] +#app.factory.issue.item.header.id=item_list +#app.factory.database.configure.page.link=Database Configurations +#app.factory.new.database.link=Database +#app.factory.database.name.id=databaseName +#app.factory.database.password=databaseUserPassword +#app.factory.database.confirm.password=confirmDatabaseUserPassword +#app.factory.database.submit.button=div.buttonrow > input[name="Submit"] +#app.factory.database.advance.Checkbox=advancecheckbox +#app.factory.database.user.CheckBox=Username +#app.factory.database.user.password=Password +#app.factory.database.user.Repeat.password=repeatPassword +#app.factory.database.environment.id=rssInstances +#app.factory.database.user.submit.name=Submit +#app.factory.database.template.name=templateName +#app.factory.database.template.submit.name=Submit +#app.factory.db.admin.id=menu_dbAdmin +#app.factory.db.dbUser.link=DB User +#app.factory.db.template.link=DB Template +#app.factory.db.resources.id=dbSection +#app.db.link=Db +#app.db.user=wso2usr +#app.db.template=wso2Temp@Development +#app.factory.delete.user=Delete User +#app.factory.del.template=Delete Template +#app.factory.delete.Ok=Ok +#app.factory.delete.db=Delete DB +#app.data.source.name=datasource_name +#app.data.source.description=datasource_description +#app.data.source.password=datasource_password_dev +#app.data.source.username=datasource_username_text_dev +#app.data.source.add.button=Submit +#app.property.name=property_name +#app.property.type=property_type +#app.property.description=property_description +#app.property.value=property_value +#app.factory.registry.page.link=Endpoints & Registry +#app.factory.data.source.page.link=Datasources +#app.db.details.id=dbSection +#app.db.user.id=dbUsrSection +#app.db.template.id=dbTempSection +#app.factory.new.data.source.page.button=//button[@type='button'] +#app.factory.api.panel.text=/html/body/div/div/article/section[3] +#app.factory.sign.out.email=span.icon-chevron-down +#app.factory.sing.out.text=Sign Out +#app.factory.subscribe=Subscribe to APIs +#app.factory.subscribe.api.element=li > div.thumbnail > a > img +#app.api.select.app.name=application-list +#app.api.subscribe.button=subscribe-button +#app.api.api.manager.button=gotoApiManagerbtn +#app.go.to.subscriptions.text=Go to My Subscriptions +#app.api.manager.class.name.text=title-section +#app.api.key.generate.text=Show Keys +#app.api.sandbox.details.id=sandTable0 +#app.api.production.details.id=prodTable0 +#app.api.page.link.text=APIs +#app.api.page.resource.list.id=keySection +#app.factory.subscription.page=My Subscriptions +#app.factory.list.view=a.icon-th-list.table_view +#app.overview.link.css=/html/body/div/div[2]/article/nav/ul/li/a +# +# +# +# +#login.username=username +#login.password=password +#login.sign.in.button=button +#login.header.div=header-div +# +#home.dashboard.middle.text.xpath=/html/body/div[3]/div[1]/div/span +#home.greg.sign.out.xpath=//*[@id="header-div"]/div[4]/div/ul/li[3]/a +#home.logged.user.dev=logged-user +# +#jaggery.Main.tab=menu-panel-button1 +#jaggery.Region1.tab=region1_manage_menu +#jaggery.dashboard.middle.text=middle +#add.jaggery.href=Jaggery +#jaggery.war.file.upload.name=warFileName +#jaggery.upload.button.name=upload +#jaggery.upload.successful.message=messagebox-info +#jaggery.upload.successful.button=ui-dialog-titlebar-close +# +# +#carbon.Main.tab=menu-panel-button1 +#carbon.Region1.tab=region1_manage_menu +#carbon.add.href=Add +#carbon.dashboard.middle.text=middle +#carbon.file.upload.field=filename +#carbon.upload.button=upload +#carbon.upload.successful.message=messagebox-info +#carbon.upload.successful.button=ui-dialog-titlebar-close +# +# +#resource.Main.tab=menu-panel-button1 +#resource.Region3.tab=region3_registry_menu +#resource.browse.link=Browse +#resource.dashboard.middle.text=middle +#resource.detailed.view=stdView +#resource.add.resource.link=Add Resource +#resource.add.collection.link=Add Collection +#resource.add.resource.input.field=uResourceFile +#resource.add.Collection.input.field=collectionName +#resource.add.Url.input.id=irFetchURL +#resource.add.collection.description=colDesc +#resource.add.resource.name=uResourceName +#Resource.add.resource.description=description +#resource.add.button=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td/div[2]/div[3]/div[3]/div[5]/table/tbody/tr[2]/td/form/table/tbody/tr[6]/td/input +#resource.add.Url.button.xpath=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td/div[2]/div[3]/div[3]/div[5]/table/tbody/tr[3]/td/form/table/tbody/tr[6]/td/input +#resource.collection.add.button=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td/div[2]/div[3]/div[3]/div[7]/form/table/tbody/tr[5]/td/input +#resource.upload.successful.message=messagebox-info +#resource.upload.successful.collection.message=messagebox-info +#resource.upload.successful.button=ui-dialog-titlebar-close +#resource.upload.collection.successful.close.button=/html/body/div[5]/div/div/a +#resource.add.Url.Successful.close=/html/body/div[4]/div/div/a +# +# +# +#service.add.link=Service +#service.dashboard.middle.text=middle +#service.list.dashboard.middle.text=middle +#service.add.name.id=id_Overview_Name +#service.add.namespace.id=id_Overview_Namespace +#service.check.save.service=Services +# +# +#wsdl.dashboard.middle.text=middle +#wsdl.list.dashboard.middle.text=middle +#wsdl.add.link=WSDL +#wsdl.add.url=irFetchURL +#wsdl.add.name=irResourceName +#wsdl.add.file.id=uResourceFile +#wsdl.add.file.name.id=uResourceName +# +# +#schema.add.link=Schema +#schema.dashboard.middle.text=middle +#schema.list.dashboard.middle.text=middle +#schema.add.url=irFetchURL +#schema.add.name=irResourceName +#schema.add.schema.name.id=uResourceName +# +# +#wsPolicy.add.link=Policy +#wsPolicy.dashboard.middle.text=middle +#ws.policy.list.dashboard.middle.text=middle +#wsPolicy.add.url=irFetchURL +#wsPolicy.add.name=irResourceName +#wsPolicy.add.file.id=uResourceFile +#wsPolicy.add.schema.name.id=uResourceName +# +# +#api.add.link=API +#api.dashboard.middle.text=middle +#api.provider.id=id_Overview_Provider +#api.name.id=id_Overview_Name +#api.context.id=id_Overview_Context +#api.version.id=id_Overview_Version +#api.list.link=APIs +# +# +#uri.add.link=URI +#uri.add.list.id=URIs +#uri.dashboard.middle.text=middle +#uri.add.uri=id_Overview_URI +#uri.add.uri.name=id_Overview_Name +#uri.list.link=URIs +# +# +#my.profile.region.tab.id=region5_my_identity_menu +#my.profile.add.page.link=My Profiles +#my.profile.dashboard.middle.text=middle +#my.profile.new.profile.add.link=Add New Profile +#my.profile.name.id=profile +#my.profile.first.name.id=http://wso2.org/claims/givenname +#my.profile.last.name.id=http://wso2.org/claims/lastname +#my.profile.email.id=http://wso2.org/claims/emailaddress +#my.profile.successful.save.pane=/html/body/div[3]/div/div/a +# +# +#search.activity.link=Activities +#search.activity.id=user +#search.activity.name.id=path +#search.activity.exists.id=activityList +# +# +#search.page.link=Search +#search.resource.name=resourcePath +#search.results.id=1 +#filter.search.button=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form[3]/table/tbody/tr/td[8]/table/tbody/tr/td/a +# +#users.add.new.user.link.id=Add New User +#users.and.roles.link.text=Users and Roles +#users.adn.roles.add.page.middle.text=middle +#users.add.link.id=Users +#users.add.new.user.name.id=username +#users.add.new.user.password.name=password +#users.add.new.user.password.retype.name=retype +#users.admin.tick.name=userRoles +#users.save=//input[contains(@value,'Finish')] +#users.page.next.id=2 +# +# +# +# +#roles.add.link.id=Roles +#role.add.new.user.link.id=Add New Role +#role.add.new.user.name.id=roleName +#role.permission.id=ygtvspacer +#role.add.user.to.role.name=org.wso2.carbon.role.assign.filter +#role.search.button=td.buttonRow > input.button +#role.add.ok.button.css=button[type="button"] +#role.add.user.to.role.name.tick=selectedUsers +#role.add.user.finish.button=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form[2]/table/tbody/tr[2]/td/input[2] +# +# +#pass.word.change.link=Change My Password +#pass.word.current.name=currentPassword +#pass.word.new.name=newPassword +#pass.word.check.name=checkPassword +#pass.word.change.save.xpath=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form/table/tbody/tr[2]/td/input +#password.change.dialog.xpath=/html/body/div[3]/div/div/a +# +# +# +#features.add.link=Features +#repository.add.tab.text=Repository Management +#repositories.table.id=_table_manage_repositories +#repository.add.link.text=Add Repository +#repository.url.name=_txt_repository_location_url +#repository.save.id=_btn_add_repository +#repository.name.id=_txt_repository_name +#installed.features.tab.linkText=Installed Features +#repositories.dashboard.text=middle +#features.filter.id=_txt_IF_filterString +#feature.checkbox.click.name=chkSelectFeaturesToUninstall +#feature.uninstall.next.button.id=_btn_next_review_uninstall_features +#feature.uninstall.finish.button.id=_btn_uc_finish +# +# +# +#server.shutdown.link.text=Shutdown/Restart +#feature.revert.tab=Installation History +#feature.find.feature.text=Available Features +#feature.install.name.id=_txt_AF_filterString +#feature.find.id=_btn_next_filter_repositories +#feature.install.click=chkSelectFeaturesToInstall +#feature.install.accept.button=_radio_af_accept_licenses +# +# +#key.store.add.link=KeyStores +#key.store.dashboard.middle.text=middle +#key.store.add.new.link.text=Add New KeyStore +#key.store.file.path.id=keystoreFile +#key.store.password.name=ksPassword +#key.store.provider.name=provider +#key.store.next.button=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form/table/tbody/tr[2]/td/input +#key.store.pass.key=keyPass +#key.store.successful.xpath=/html/body/div[3]/div/div/a +# +# +#logging.add.link=Logging +#logging.dashboard.middle.text=middle +#logging.update.button.id=globalLog4jUpdate +#log4j.appender.update.id=appenderUpdate +#log4j.global.success.xpath=/html/body/div[3]/div[2]/button +#log4j.appender.sucess.xpath=/html/body/div[4]/div[2]/button +# +# +#log4j.logger.search.id=filterText +#log4j.logger.successful.button.xpath=/html/body/div[3]/div/div/a +# +# +#notification.adding.link=Notifications +#notification.dashboard.middle.text=middle +#notification.add.edit.link.text=Add Subscription to Resource/Collection +#notification.add.email.id=subscriptionInput +# +#registry.subscription.middle.text=middle +#registry.subscription.path.id=subscriptionPath +#registry.subscription.event.id=eventList +#registry.subscription.notification.id=notificationMethodList +#registry.subscription.email.id=subscriptionInput +#registry.subscription.digest.id=subscriptionDigestTypeInput +#registry.subscription.hsmethod.id=hierarchicalSubscriptionList +#registry.subscription.subscribe.button.id=subscribeButton +# +# +#uri.configure.add.link=URIs +#uri.configure.dashboard.middle.text=middle +# +# +# +#api.configure.add.link=APIs +#api.configure.dashboard.middle.text=middle +# +#service.configure.add.link=Services +#service.configure.dashboard.middle.text=middle +# +#server.role.add.link=Server Roles +#server.role.dashboard.middle.text=middle +#server.role.add.link.text=Add New Server Role +#server.role.name.id=_serverRoleName +# +# +#add.new.tenant.link.text=Add New Tenant +#tenant.role.dashboard.middle.text=middle +#tenant.domain=domain +#tenant.first.name=admin-firstname +#tenant.last.name=admin-lastname +#tenant.admin.user.name=admin +#tenant.admin.password=admin-password +#tenant.admin.password.repeat=admin-password-repeat +#tenant.admin.email.id=admin-email +#add.new.tenant.success.button=/html/body/div[3]/div/div/a +#view.tenant.link=View Tenants +# +# +# +#add.new.extension.dashboard.middle.text=middle +#extension.tab.id=menu-panel-button5 +#extension.list.page.dashboard.middle.text=middle +#extensions.add.link=Add +#extension.add.text.box=uResourceFile +# +#life.cycle.tab.id=menu-panel-button5 +#life.cycle.add.link=Lifecycles +#add.new.lifecycle.dashboard.middle.text=middle +#add.new.lifecycle.link.text=Add New Lifecycle +#add.new.lifecycle.text.area=//*[@id="textarea"] +#add.new.lifecycle.save.css=input.button.registryWriteOperation +#resource.lifecycle.minimized=//*[@id="lifecycleIconMinimized"] +#resource.lifecycle.add=//*[@id="lifecycleExpanded"]/div[2]/a +#resource.lifecycle.add.select=//*[@id="aspect"] +#resource.lifecycle.add.select.id=aspect +#resource.lifecycle.add.button.add=//*[@id="add-lifecycle-div"]/form/table/tbody/tr[2]/td/input[1] +#resource.lifecycle.add.button.cancel=//*[@id="add-lifecycle-div"]/form/table/tbody/tr[2]/td/input[2] +# +# +# +#artifact.add.tab.id=menu-panel-button5 +#artifacts.add.link=Artifact Types +#add.new.artifact.dashboard.middle.text=middle +#add.new.artifact.type.link=Add new Artifact +#add.new.artifact.text.area=textarea +#add.new.artifact.save.xpath=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form/table/tbody/tr[2]/td/input +# +#add.new.artifact.dialog.box=button[type="button"] +# +# +# +#handler.add.tab.id=menu-panel-button5 +#handler.add.link=Handlers +#add.new.handler.dashboard.middle.text=middle +#add.new.handler.link.text=Add New Handler +#add.new.handler.text.area=textarea +#add.new.handler.save.xpath=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/form/table/tbody/tr[2]/td/input +#add.new.handler.dialog.box=button[type="button"] +#configure.tab.id=menu-panel-button3 +# +# +# +#manage.report.page.link=Reports +#manage.report.list.dashboard.middle.text=middle +#add.report.list.dashboard.middle.text=middle +#add.report.name=reportName +#add.report.template=reportTemplate +#add.report.type=reportType +#add.report.class=reportClass +#report.add.link=Add Report +# +#life.cycle.expand.id=lifecycleIconMinimized +#life.cycle.add=Add Lifecycle +#life.cycle.add.option=option0 +#life.cycle.add.option1=option1 +#life.cycle.add.option2=option2 +#life.cycle.promote=Promote +#life.cycle.publish=Publish +#life.cycle.stage=/html/body/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[4]/div[14]/div[3]/div[2]/table/tbody/tr/td/div[2]/table/tbody/tr[2]/td +#life.cycle.promote.ok.button=button[type="\button\"] +# +#webapp.list.xpath=.//*[@id='menu']/ul/li[7]/ul/li[2]/ul/li[1]/a +# +#webapp.list.page.middle=middle +#webapp.add.xpath=//*[@id="menu"]/ul/li[5]/ul/li[2]/ul/li[3]/ul/li[1]/a +#webapp.add.page.middle=middle +# +#endpoints.tab.id=//*[@id="menu"]/ul/li[5]/ul/li[4]/ul/li[4]/a +#endpoints.page.middle=middle +# +# +#bam.dashboard.tab.id=//*[@id="menu"]/ul/li[3]/ul/li/a +#bam.dashboard.signin.xpath=//*[@id="wrap"]/div[2]/div/div/h1 diff --git a/modules/integration/tests-integration/pom.xml b/modules/integration/tests-integration/pom.xml new file mode 100644 index 00000000..124c5b2a --- /dev/null +++ b/modules/integration/tests-integration/pom.xml @@ -0,0 +1,270 @@ + + + + + org.wso2.iot + wso2iot-integration + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.iot.test.integration + WSO2 IOT - Integration Test Module + Backend Integration Tests for WSO2 IOT Server. + jar + + + + + maven-surefire-plugin + false + + -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m + + + src/test/resources/testng-server-mgt.xml + src/test/resources/testng.xml + + + ${skipTests} + + + + maven.test.haltafterfailure + false + + + java.io.tmpdir + ${basedir}/target/ + + + carbon.zip + + ${basedir}/../../distribution/target/wso2iot-${project.version}.zip + + + + framework.resource.location + + ${basedir}/src/test/resources/ + + + + server.list + + IOT + + + + usedefaultlisteners + false + + ${basedir}/target/security-verifier/ + ${basedir}/target/iot + ${basedir}/src/test/resources/instrumentation.txt + ${basedir}/src/test/resources/filters.txt + ${basedir}/target/iot + + ${basedir}/target + + + + maven-dependency-plugin + + + + copy-emma-dependencies + compile + + copy-dependencies + + + ${project.build.directory}/emma + jar + emma + + + + + copy-secVerifier + compile + + copy-dependencies + + + ${basedir}/target/security-verifier + aar + SecVerifier + true + + + + + unpack-mar-jks + compile + + unpack + + + + + org.wso2.iot + wso2iot + ${project.version} + zip + true + ${basedir}/target/tobeCopied/ + **/*.jks,**/*.mar,**/axis2_client.xml + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + + maven-resources-plugin + 2.6 + + + copy-resources-jks + compile + + copy-resources + + + ${basedir}/src/test/resources/keystores/products + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/resources/security/ + + + **/*.jks + + + + + + + copy-stratos-jks + compile + + copy-resources + + + ${basedir}/src/test/resources/keystores/stratos + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/resources/security/ + + + **/*.jks + + + + + + + copy-axis2files + compile + + copy-resources + + + ${basedir}/src/test/resources/axis2config + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/conf/axis2/ + + + **/*.xml + + + + + + + copy-resources-mar + compile + + copy-resources + + + ${basedir}/src/test/resources/client/modules + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/deployment/client/modules + + + **/*.mar + + + + + + + + + + + + + org.wso2.carbon.automation + org.wso2.carbon.automation.engine + + + org.wso2.carbon.automation + org.wso2.carbon.automation.test.utils + + + org.wso2.carbon.automationutils + org.wso2.carbon.integration.common.extensions + + + com.google.code.gson + gson + + + + + true + + + diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/AssertUtil.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/AssertUtil.java new file mode 100644 index 00000000..5a7874b1 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/AssertUtil.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.testng.Assert; + +/** + * This class contains methods to make assertions easier and which are not available out of the box, from testng. + */ +public class AssertUtil { + /** + * This can be used to compare if to json strings are matched or not. + * + * @param expectedJsonPayload the expected json string. + * @param realPayload real json string. + * @param mustMatch If the real and expected must match, in order to become the test successful or not. + */ + public static void jsonPayloadCompare(String expectedJsonPayload, String realPayload, boolean mustMatch) { + JsonElement jsonElement = new JsonParser().parse(expectedJsonPayload); + JsonObject expectedPayloadObject = jsonElement.getAsJsonObject(); + jsonElement = new JsonParser().parse(realPayload); + JsonObject realPayloadObject = jsonElement.getAsJsonObject(); + if (mustMatch) { + Assert.assertTrue(realPayloadObject.equals(expectedPayloadObject)); + } else { + Assert.assertFalse(realPayloadObject.equals(expectedPayloadObject)); + } + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/Constants.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/Constants.java new file mode 100644 index 00000000..03e58241 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/Constants.java @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import java.io.File; + +/** + * Constants used through out the test suite are defined here. + */ +public final class Constants { + + public static final String DEVICE_ID = "d24f870f390352a41234"; + public static final String NUMBER_NOT_EQUAL_TO_DEVICE_ID = "1111"; + public static final String DEVICE_IMEI = "123123123"; + public static final String AUTOMATION_CONTEXT = "IOT"; + public static final String APPLICATION_JSON = "application/json"; + public static final String APPLICATION_URL_ENCODED = "application/x-www-form-urlencoded"; + public static final String OAUTH_CLIENT_ID = "client_id"; + public static final String OAUTH_CLIENT_SECRET = "client_secret"; + public static final String OAUTH_ACCESS_TOKEN = "access_token"; + public static final String SCOPE = "scope"; + public static final String ANDROID_DEVICE_TYPE = "android"; + public static final String HTTP_METHOD_POST = "POST"; + public static final String HTTP_METHOD_PUT = "PUT"; + public static final String HTTP_METHOD_GET = "GET"; + public static final String HTTP_METHOD_DELETE = "DELETE"; + public static final String DEVICE_IDENTIFIER_KEY = "deviceIdentifier"; + public static final String DEVICE_IDENTIFIERS_KEY = "deviceIDs"; + public static final String CONTENT_TYPE = "Content-Type"; + public static final String APPLICATION_SOAP_XML = "application/soap+xml; charset=utf-8"; + public static final String UTF8 = "UTF-8"; + public static final String ZERO = "0"; + public static final String NULL = "[]"; + public static final String INACTIVE = "INACTIVE"; + + public static final String HTTPS = "https"; + public static final String HTTP = "http"; + + public static final int HTTPS_GATEWAY_PORT = 8243; + public static final int HTTP_GATEWAY_PORT = 8280; + + public static final class APIApplicationRegistration { + public static final String API_APP_REGISTRATION_ENDPOINT = "/api-application-registration/register"; + public static final String TOKEN_ENDPOINT = "/token"; + public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin&grant_type=password&scope=perm:android:enroll perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin"; + private static StringBuffer dynamicClientPayloadBuffer = new StringBuffer(); + public static final String API_APP_REGISTRATION_PAYLOAD = dynamicClientPayloadBuffer.append("{ \n" + + " \"applicationName\":\"app_12345\",\n" + " \"isAllowedToAllDomains\":false,\n" + + " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n" + + "}").toString(); + public static final String PERMISSION_LIST = "default perm:admin-groups:count perm:admin-groups:view " + + "perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete " + + "perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view " + + "perm:admin:devices:view perm:android:blacklist-applications perm:android:change-lock-code " + + "perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi " + + "perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage " + + "perm:android:enroll perm:android:enterprise-wipe perm:android:info " + + "perm:android:install-application perm:android:location perm:android:lock-devices " + + "perm:android:logcat perm:android:manage-configuration perm:android:mute perm:android:reboot " + + "perm:android:ring perm:android:send-notification perm:android:set-password-policy " + + "perm:android:set-webclip perm:android:uninstall-application perm:android:unlock-devices " + + "perm:android:update-application perm:android:upgrade-firmware perm:android:view-configuration " + + "perm:android:wipe perm:applications:install perm:applications:uninstall perm:dashboard:by-groups " + + "perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts " + + "perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant " + + "perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities perm:device-types:features " + + "perm:device-types:types perm:devices:applications perm:devices:compliance-data perm:devices:delete" + + " perm:devices:details perm:devices:effective-policy perm:devices:features perm:devices:operations " + + "perm:devices:search perm:devices:update perm:devices:view perm:get-activity perm:groups:add " + + "perm:groups:assign perm:groups:count perm:groups:device perm:groups:devices " + + "perm:groups:devices-add perm:groups:devices-count perm:groups:devices-remove perm:groups:groups " + + "perm:groups:groups-view perm:groups:remove perm:groups:roles perm:groups:share perm:groups:update " + + "perm:manage-configuration perm:notifications:mark-checked perm:notifications:view " + + "perm:policies:activate perm:policies:changes perm:policies:deactivate perm:policies:get-details " + + "perm:policies:get-policy-details perm:policies:manage perm:policies:priorities " + + "perm:policies:remove perm:policies:update perm:roles:add perm:roles:add-users " + + "perm:roles:create-combined-role perm:roles:delete perm:roles:details perm:roles:permissions " + + "perm:roles:update perm:roles:view perm:users:add perm:users:count perm:users:credentials " + + "perm:users:delete perm:users:details perm:users:is-exist perm:users:roles perm:users:search " + + "perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration " + + "perm:devices:change-status"; + + private APIApplicationRegistration() { + throw new AssertionError(); + } + } + + public static final class AndroidEnrollment { + public static final String ENROLLMENT_PAYLOAD_FILE_NAME = "android-enrollment-payloads.json"; + public static final String ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME = "android-enrollment-response-payloads.json"; + public static final String ENROLLMENT_ENDPOINT = "/api/device-mgt/android/v1.0/devices"; + public static final String ENROLLMENT_GROUP = "android-enrollment"; + + private AndroidEnrollment() { + throw new AssertionError(); + } + } + + public static final class AndroidPolicy { + public static final String POLICY_RESPONSE_PAYLOAD_FILE_NAME = "android-policy-response-payloads.json"; + public static final String POLICY_ENDPOINT = "/mdm-android-agent/policy/"; + public static final String POLICY_GROUP = "android-policy"; + public static final String GET_EFFECTIVE_POLICY = "getEffectivePolicy"; + + private AndroidPolicy() { + throw new AssertionError(); + } + } + + public static final class WindowsEnrollment { + public static final String DISCOVERY_GET_URL = "/mdm-windows-agent/services/discovery/get"; + public static final String DISCOVERY_POST_URL = "/mdm-windows-agent/services/discovery/post"; + public static final String BSD_URL = "/mdm-windows-agent/services/federated/bst/authentication"; + public static final String MS_EXCEP = "/mdm-windows-agent/services/certificatepolicy/xcep"; + public static final String WINDOWS_ENROLLMENT_GROUP = "windows-enrollment"; + public static final String WSTEP_URL = "/mdm-windows-agent/services/deviceenrolment/wstep"; + public static final String SYNC_ML_URL = "/mdm-windows-agent/services/syncml/devicemanagement/request"; + public static final String DISCOVERY_POST_FILE = "windows" + File.separator + "enrollment" + File + .separator + "discovery-post.xml"; + public static final String MS_XCEP_FILE = + "windows" + File.separator + "enrollment" + File.separator + "ms_xcep.xml"; + public static final String WS_STEP_FILE = + "windows" + File.separator + "enrollment" + File.separator + "wstep.xml"; + public static final String BSD_PAYLOAD = "{\"credentials\" : {\"username\" : \"admin\", \"email\" : \"admin@wso2.com\", " + + "\"password\" : \"admin\", \"ownership\" : \"BYOD\", " + + "\"token\" : \"cbe53efd46ec612c456540f8dfef5428\"}}"; + + private WindowsEnrollment() { + throw new AssertionError(); + } + } + + public static final class AndroidOperations { + private static final String PAYLOAD_COMMON = "["+DEVICE_ID+"]"; + + public static final String OPERATION_PAYLOAD_FILE_NAME = "android-operation-payloads.json"; + public static final String OPERATIONS_GROUP = "operations"; + + public static final String CAMERA_OPERATION = "control-camera"; + public static final String CAMERA_OPERATION_PAYLOAD = "{\n" + " \"operation\": {\n" + + " \"enabled\": false\n" + " },\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\" \n" + + " ]\n" + "}"; + + public static final String WIPE_DATA_OPERATION = "wipe_data"; + public static final String WIPE_DATA_OPERATION_PAYLOAD = "wipe_data"; + + public static final String INSTALL_APPS_OPERATION = "install_apps"; + public static final String NOTIFICATION_OPERATION = "notification"; + public static final String WIFI_OPERATION = "wifi"; + public static final String ENCRYPT_OPERATION = "encrypt"; + public static final String CHANGE_LOCK_OPERATION = "unlock-devices"; + public static final String PASSWORD_POLICY_OPERATION = "password_policy"; + public static final String WEB_CLIP_OPERATION = "web_clip"; + public static final String OPERATION_ENDPOINT = "/api/device-mgt/android/v1.0/admin/devices/"; + public static final String UNLOCK_ENDPOINT = "unlock-devices"; + public static final String UNLOCK_OPERATION_PAYLOAD = PAYLOAD_COMMON; + + public static final String LOCK_ENDPOINT = "lock-devices"; + public static final String LOCK_OPERATION_PAYLOAD = "{ \"deviceIDs\": [\""+DEVICE_ID+"\"]," + + "\"operation\": { \"message\": \"string\", \"hardLockEnabled\": false }}"; + + public static final String LOCATION_ENDPOINT = "location"; + public static final String LOCATION_PAYLOAD = PAYLOAD_COMMON; + + public static final String CLEAR_PASSWORD_ENDPOINT = "clear-password"; + public static final String CLEAR_PASSWORD_PAYLOAD = PAYLOAD_COMMON; + + public static final String DEVICE_INFO_ENDPOINT = "/info"; + public static final String DEVICE_INFO_PAYLOAD = "[\""+DEVICE_ID+"\"]"; + + public static final String ENTERPRISE_WIPE_ENDPOINT = "enterprise-wipe"; + public static final String ENTERPRISE_WIPE_PAYLOAD = PAYLOAD_COMMON; + + public static final String WIPE_DATA_ENDPOINT = "wipe"; + public static final String WIPE_DATA_PAYLOAD = "{\n" + " \"operation\": {\n" + " \"pin\": \"string\"\n" + + " },\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + " ]\n" + "}"; + + public static final String APPLICATION_LIST_ENDPOINT = "applications"; + public static final String APPLICATION_LIST_PAYLOAD = PAYLOAD_COMMON; + + public static final String RING_ENDPOINT = "ring"; + public static final String RING_PAYLOAD = PAYLOAD_COMMON; + + public static final String MUTE_ENDPOINT = "mute"; + public static final String MUTE_PAYLOAD = PAYLOAD_COMMON; + + public static final String INSTALL_APPS_ENDPOINT = "install-application"; + public static final String INSTALL_APPS_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + + " ],\n" + " \"operation\": {\n" + " \"appIdentifier\": \"string\",\n" + + " \"type\": \"string\",\n" + " \"url\": \"string\"\n" + " }\n" + "}"; + + public static final String UNINSTALL_APPS_ENDPOINT = "uninstall-application"; + public static final String UNINSTALL_APPS_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + + " \""+DEVICE_ID+"\"\n" + " ],\n" + " \"operation\": {\n" + + " \"appIdentifier\": \"string\",\n" + " \"type\": \"string\",\n" + " \"url\": \"string\",\n" + + " \"name\": \"string\"\n" + " }\n" + "}"; + + public static final String BLACKLIST_APPS_ENDPOINT = "blacklist-applications"; + + public static final String NOTIFICATION_ENDPOINT = "send-notification"; + public static final String NOTIFICATION_PAYLOAD = "{\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + + " ],\n" + " \"operation\": {\n" + " \"messageText\": \"string\",\n" + + " \"messageTitle\": \"string\"\n" + " }\n" + "}"; + + public static final String WIFI_ENDPOINT = "configure-wifi"; + public static final String WIFI_PAYLOAD = "{\n" + " \"operation\": {\n" + " \"ssid\": \"string\",\n" + + " \"password\": \"string\"\n" + " },\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + + " ]\n" + "}"; + + public static final String ENCRYPT_ENDPOINT = "encrypt-storage"; + public static final String ENCRYPT_PAYLOAD = "{\n" + " \"operation\": {\n" + " \"encrypted\": false\n" + + " },\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + " ]\n" + "}"; + + public static final String REBOOT_ENDPOINT = "reboot"; + public static final String REBOOT_PAYLOAD = PAYLOAD_COMMON;; + + public static final String CHANGE_LOCK_ENDPOINT = "change-lock-code"; + public static final String CHANGE_LOCK_PAYLOAD = "{\n" + " \"operation\": {\n" + " \"lockCode\": \"0000\"\n" + + " },\n" + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + " ]\n" + "}\n"; + + public static final String PASSWORD_POLICY_ENDPOINT = "set-password-policy"; + public static final String PASSWORD_POLICY_PAYLOAD = "{\n" + " \"operation\": {\n" + + " \"maxFailedAttempts\": 0,\n" + " \"minLength\": 0,\n" + " \"pinHistory\": 0,\n" + + " \"minComplexChars\": 0,\n" + " \"maxPINAgeInDays\": 0,\n" + + " \"requireAlphanumeric\": false,\n" + " \"allowSimple\": false\n" + " },\n" + + " \"deviceIDs\": [\n" + " \""+DEVICE_ID+"\"\n" + " ]\n" + "}"; + + public static final String WEB_CLIP_ENDPOINT = "set-webclip"; + public static final String WEB_CLIP_PAYLOAD = "{\n" + " \"operation\": {\n" + " \"identity\": \"string\",\n" + + " \"title\": \"string\",\n" + " \"type\": \"string\"\n" + " },\n" + " \"deviceIDs\": [\n" + + " \""+DEVICE_ID+"\"\n" + " ]\n" + "}"; + + private AndroidOperations() { + throw new AssertionError(); + } + } + + public static final class AndroidDeviceManagement { + public static final String DEVICE_MANAGEMENT_GROUP = "device-mgt"; + public static final String KEY_DEVICE_ID = "deviceIdentifier"; + public static final String KEY_DEVICE_NAME = "name"; + public static final String DEVICE_MGT_ENDPOINT = "/mdm-android-agent/device/"; + public static final String LICENSE_SECTION = "This"; + public static final String LICENSE_ENDPOINT = DEVICE_MGT_ENDPOINT + "license"; + public static final String APP_LIST_ENDPOINT = DEVICE_MGT_ENDPOINT + "appList/" + + Constants.DEVICE_ID; + public static final String REQUEST_MODIFY_DEVICE_EXPECTED = "{\"responseMessage\":\"Device information " + + "has modified successfully.\"}"; + public static final String APPLIST_PAYLOAD = "{\"id\":\"1\"," + + "\"applicationIdentifier\": \"appid\",\"\"platform\": \"android\"," + + "\"name\": \"testapp\"}"; + public static final String RESPONSE_PAYLOAD_FILE_NAME = "android-device-mgt-response-payloads.json"; + + private AndroidDeviceManagement() { + throw new AssertionError(); + } + } + + public static final class AndroidConfigurationManagement { + public static final String DEVICE_CONFIGURATION_GROUP = "android-config-mgt"; + public static final String CONFIG_MGT_ENDPOINT = "/mdm-android-agent/configuration/"; + public static final String PAYLOAD_FILE_NAME = "android-configuration-payloads.json"; + public static final String RESPONSE_PAYLOAD_FILE_NAME = "android-config-response-payloads.json"; + + private AndroidConfigurationManagement() { + throw new AssertionError(); + } + } + + public static final class OperationManagement { + public static final String PATH_APPS = "/apps"; + public static final String OPERATION_MANAGEMENT_GROUP = "api-policy-mgt"; + public static final String GET_DEVICE_APPS_ENDPOINT = "/mdm-admin/operations/android/"; + public static final String GET_DEVICE_OPERATIONS_ENDPOINT = "/mdm-admin/operations/android/"; + + private OperationManagement() { + throw new AssertionError(); + } + } + + public static final class MobileDeviceManagement { + public static final String MOBILE_DEVICE_MANAGEMENT_GROUP = "mobile-device-mgt"; + public static final String GET_DEVICE_COUNT_ENDPOINT = "/api/device-mgt/v1.0/devices"; + public static final String CHANGE_DEVICE_STATUS_ENDPOINT = "/api/device-mgt/v1.0/devices/"; + public static final String NO_OF_DEVICES = "1"; + public static final String GET_ALL_DEVICES_ENDPOINT = "/mdm-admin/devices"; + public static final String VIEW_DEVICE_TYPES_ENDPOINT = "/mdm-admin/devices/types"; + public static final String VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME = + "mobile-device-mgt-view-device-types-response-payloads.json"; + public static final String NO_DEVICE = "{\"devices\":[],\"count\":0}"; + + private MobileDeviceManagement() { + throw new AssertionError(); + } + } + + + public static final class UserManagement { + public static final String USER_MANAGEMENT_GROUP = "user-mgt"; + public static final String USER_NAME = "username123"; + public static final String USER_ENDPOINT = "/mdm-admin/users"; + public static final String USER_PAYLOAD_FILE_NAME = "user-payloads.json"; + public static final String USER_RESPONSE_PAYLOAD_FILE_NAME = "user-response-payloads.json"; + public static final String VIEW_USER_ENDPOINT = "/mdm-admin/users/view"; + + private UserManagement() { + throw new AssertionError(); + } + + } + + public static final class RoleManagement { + public static final String ROLE_MANAGEMENT_GROUP = "role-mgt"; + public static final String ADD_ROLE_ENDPOINT = "/mdm-admin/roles"; + public static final String ROLE_PAYLOAD_FILE_NAME = "role-payloads.json"; + public static final String UPDATE_ROLE_PERMISSION_ENDPOINT = "/mdm-admin/roles?rolename=administration"; + public static final String UPDATE_ROLE_PERMISSION_PAYLOAD_FILE_NAME = "role-payloads.json"; + public static final String REMOVE_ROLE_ENDPOINT = "/mdm-admin/roles?rolename=administration"; + + private RoleManagement() { + throw new AssertionError(); + } + + } + + public static final class PolicyManagement { + public static final String POLICY_MANAGEMENT_GROUP = "policy-mgt"; + public static final String ADD_POLICY_ENDPOINT = "/mdm-admin/policies/active-policy"; + public static final String POLICY_PAYLOAD_FILE_NAME = "policy-payloads.json"; + public static final String POLICY_RESPONSE_PAYLOAD_FILE_NAME = "policy-response-payloads.json"; + public static final String UPDATE_POLICY_ENDPOINT = "/mdm-admin/policies/1"; + public static final String REMOVE_POLICY_ENDPOINT = "/mdm-admin/policies/bulk-remove"; + public static final String REMOVE_POLICY_PAYLOAD_FILE_NAME = "[1]"; + public static final String VIEW_POLICY_LIST_ENDPOINT = "/mdm-admin/policies"; + + private PolicyManagement() { + throw new AssertionError(); + } + } + + public static final class FeatureManagement { + public static final String FEATURE_MANAGEMENT_GROUP = "feature-mgt"; + public static final String VIEW_FEATURES_ENDPOINT = "/mdm-admin/features/android"; + + private FeatureManagement() { + throw new AssertionError(); + } + } + + public static final class LicenseManagement { + public static final String LICENSE_MANAGEMENT_GROUP = "license-mgt"; + public static final String GET_LICENSE_ENDPOINT = "/mdm-admin/license/android/en_US"; + public static final String LICENSE_RESPONSE_PAYLOAD_FILE_NAME = "license-response-payloads.json"; + + private LicenseManagement() { + throw new AssertionError(); + } + + } + + public static final class ConfigurationManagement { + public static final String CONFIGURATION_MANAGEMENT_GROUP = "configuration-mgt"; + public static final String CONFIGURATION_ENDPOINT = "/mdm-admin/configuration"; + public static final String CONFIGURATION_PAYLOAD_FILE_NAME = "configuration-payloads.json"; + public static final String CONFIGURATION_RESPONSE_PAYLOAD_FILE_NAME = "configuration-response-payloads.json"; + + private ConfigurationManagement() { + throw new AssertionError(); + } + } + + public static final class NotificationManagement { + public static final String NOTIFICATION_MANAGEMENT_GROUP = "notification-mgt"; + public static final String NOTIFICATION_ENDPOINT = "/mdm-admin/notifications"; + public static final String NOTIFICATION_PAYLOAD_FILE_NAME = "notification-payloads.json"; + public static final String NOTIFICATION_RESPONSE_PAYLOAD_FILE_NAME = "notification-response-payloads.json"; + public static final String NOTIFICATION_UPDATE_ENDPOINT = "/mdm-admin/notifications/1234/NEW"; + + private NotificationManagement() { + throw new AssertionError(); + } + + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTHttpClient.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTHttpClient.java new file mode 100644 index 00000000..76ec1137 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTHttpClient.java @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + + +import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; +import org.apache.commons.httpclient.methods.*; +import org.apache.commons.httpclient.params.HttpMethodParams; +import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.HashMap; +import java.util.Map; + +/** + * This class creates a customised Http Client Class + */ +public class IOTHttpClient { + + private static final String AUTHORIZATION = "Authorization"; + private static Log log = LogFactory.getLog(IOTHttpClient.class); + private String backEndUrl; + private String authorizationString; + private Map requestHeaders = new HashMap(); + + public IOTHttpClient(String backEndUrl, String contentType, String authorization) { + + this.backEndUrl = backEndUrl; + this.requestHeaders.put(Constants.CONTENT_TYPE, contentType); + if (authorization != null || !authorization.isEmpty()) { + this.authorizationString = authorization; + this.requestHeaders.put(AUTHORIZATION, authorization); + } + } + + public String getAuthorizationString() { + return authorizationString; + } + + public void setAuthorizationString(String authorizationString) { + this.authorizationString = authorizationString; + } + + public void setHttpHeader(String headerName, String value) { + this.requestHeaders.put(headerName, value); + } + + public String getHttpHeader(String headerName) { + return this.requestHeaders.get(headerName); + } + + public void removeHttpHeader(String headerName) { + this.requestHeaders.remove(headerName); + } + + public IOTResponse post(String endpoint, String body) { + HttpClient client = new HttpClient(); + try { + ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); + Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT); + Protocol.registerProtocol(Constants.HTTPS, https); + String url = backEndUrl + endpoint; + PostMethod method = new PostMethod(url); + method.setRequestHeader(AUTHORIZATION, authorizationString); + StringRequestEntity requestEntity = new StringRequestEntity(body, + requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8); + method.setRequestEntity(requestEntity); + IOTResponse iotResponse = new IOTResponse(); + iotResponse.setStatus(client.executeMethod(method)); + iotResponse.setBody(method.getResponseBodyAsString()); + return iotResponse; + + } catch (GeneralSecurityException e) { + log.error("Failure occurred at IOTResponse post for GeneralSecurityException", e); + } catch (IOException e) { + log.error("Failure occurred at IOTResponse post for IOException", e); + } + return null; + } + + public IOTResponse put(String endpoint, String body) { + HttpClient client = new HttpClient(); + try { + ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); + Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT); + Protocol.registerProtocol(Constants.HTTPS, https); + String url = backEndUrl + endpoint; + PutMethod method = new PutMethod(url); + method.setRequestHeader(AUTHORIZATION, authorizationString); + StringRequestEntity requestEntity = new StringRequestEntity( + body, requestHeaders.get(Constants.CONTENT_TYPE), Constants.UTF8); + method.setRequestEntity(requestEntity); + IOTResponse iotResponse = new IOTResponse(); + iotResponse.setStatus(client.executeMethod(method)); + iotResponse.setBody(method.getResponseBodyAsString()); + return iotResponse; + + } catch (GeneralSecurityException e) { + log.error("Failure occurred at IOTResponse put for GeneralSecurityException", e); + } catch (IOException e) { + log.error("Failure occurred at IOTResponse put for IO Exception", e); + } + return null; + } + + public IOTResponse get(String endpoint) { + HttpClient client = new HttpClient(); + try { + ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); + + Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT); + Protocol.registerProtocol(Constants.HTTPS, https); + String url = backEndUrl + endpoint; + GetMethod method = new GetMethod(url); + method.setRequestHeader(AUTHORIZATION, authorizationString); + method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, + new DefaultHttpMethodRetryHandler(3, false)); + IOTResponse iotResponse = new IOTResponse(); + iotResponse.setStatus(client.executeMethod(method)); + iotResponse.setBody(new String(method.getResponseBody())); + return iotResponse; + + } catch (GeneralSecurityException e) { + log.error("Failure occurred at IOTResponse get for GeneralSecurityException", e); + } catch (IOException e) { + log.error("Failure occurred at IOTResponse get for IOException", e); + } + + return null; + } + + public IOTResponse delete(String endpoint) { + + HttpClient client = new HttpClient(); + + try { + ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); + + Protocol https = new Protocol(Constants.HTTPS, socketFactory, Constants.HTTPS_GATEWAY_PORT); + Protocol.registerProtocol(Constants.HTTPS, https); + + String url = backEndUrl + endpoint; + + DeleteMethod method = new DeleteMethod(url); + method.setRequestHeader(AUTHORIZATION, authorizationString); + method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, + new DefaultHttpMethodRetryHandler(3, false)); + + IOTResponse iotResponse = new IOTResponse(); + iotResponse.setStatus(client.executeMethod(method)); + iotResponse.setBody(method.getResponseBodyAsString()); + return iotResponse; + + } catch (GeneralSecurityException e) { + log.error("Failure occurred at IOTResponse delete for GeneralSecurityException", e); + } catch (IOException e) { + log.error("Failure occurred at IOTResponse delete for IOException", e); + } + return null; + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTResponse.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTResponse.java new file mode 100644 index 00000000..8affc40a --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/IOTResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +/** + * This class contains the functions to handle a HTTP Response + */ +public class IOTResponse { + + private int status; + private String body; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java new file mode 100644 index 00000000..7935d017 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import org.apache.commons.net.util.Base64; +import org.json.JSONObject; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +/** + * This Util class holds method necessary to get an OAuth token. + */ +public class OAuthUtil { + + + public static String getScopes(String backendHTTPURL, String backendHTTPSURL) throws Exception { + return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.SCOPE).toString(); + } + + public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) throws Exception { + return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.OAUTH_ACCESS_TOKEN).toString(); + } + + public static JSONObject getOAuthTokenPair(String backendHTTPURL, String backendHTTPSURL) throws Exception { + String AuthString = "Basic YWRtaW46YWRtaW4="; + RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString); + HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT, + Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD); + JSONObject jsonObj = new JSONObject(oAuthData.getData()); + String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString(); + String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString(); + byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes()); + String basicAuthString = "Basic " + new String(bytesEncoded); + //Initiate a RestClient to get OAuth token + client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString); + oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT, + Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD); + jsonObj = new JSONObject(oAuthData.getData()); + return jsonObj; + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/PayloadGenerator.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/PayloadGenerator.java new file mode 100644 index 00000000..c7c82e59 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/PayloadGenerator.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.commons.io.IOUtils; + +import java.io.*; +import java.net.URL; + +/** + * This class is used to load the necessary payloads from payload files for integration tests. + */ +public class PayloadGenerator { + + private static final String PAYLOAD_LOCATION = "payloads/"; + private static JsonParser parser = new JsonParser(); + + public static JsonObject getJsonPayload(String fileName, String method) + throws FileNotFoundException { + URL url = PayloadGenerator.class.getClassLoader().getResource(PAYLOAD_LOCATION + fileName); + JsonObject jsonObject = parser.parse(new FileReader(url.getPath())).getAsJsonObject(); + return jsonObject.get(method).getAsJsonObject(); + } + + public static String getJsonPayloadToString(String fileName) throws IOException { + URL url = Thread.currentThread().getContextClassLoader().getResource(PAYLOAD_LOCATION + fileName); + FileInputStream fisTargetFile = new FileInputStream(new File(url.getPath())); + String returnString = IOUtils.toString(fisTargetFile, Constants.UTF8); + return returnString; + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/RestClient.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/RestClient.java new file mode 100644 index 00000000..5767f486 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/RestClient.java @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * This is the rest client that is used to calls to APIs. + */ +public class RestClient { + + private static final String AUTHORIZATION = "Authorization"; + private String backEndUrl; + private String authrizationString; + private Map requestHeaders = new HashMap(); + + public RestClient(String backEndUrl, String contentType) { + this.backEndUrl = backEndUrl; + this.requestHeaders.put(Constants.CONTENT_TYPE, contentType); + } + + public RestClient(String backEndUrl, String contentType, String authorization) { + this.backEndUrl = backEndUrl; + this.requestHeaders.put(Constants.CONTENT_TYPE, contentType); + if (authorization != null || !authorization.isEmpty()) { + this.authrizationString = authorization; + this.requestHeaders.put(AUTHORIZATION, authorization); + } + } + + public String getAuthrizationString() { + return authrizationString; + } + + public void setAuthrizationString(String authrizationString) { + this.authrizationString = authrizationString; + } + + public void setHttpHeader(String headerName, String value) { + this.requestHeaders.put(headerName, value); + } + + public String getHttpHeader(String headerName) { + return this.requestHeaders.get(headerName); + } + + public void removeHttpHeader(String headerName) { + this.requestHeaders.remove(headerName); + } + + public HttpResponse post(String endpoint, String body) throws MalformedURLException, AutomationFrameworkException { + return HttpRequestUtil.doPost(new URL(backEndUrl + endpoint), body, requestHeaders); + } + + public HttpResponse put(String endpoint, String body) throws Exception { + HttpURLConnection urlConnection = null; + try { + urlConnection = (HttpURLConnection) new URL(backEndUrl + endpoint).openConnection(); + try { + urlConnection.setRequestMethod("PUT"); + } catch (ProtocolException e) { + throw new Exception("Shouldn\'t happen: HttpURLConnection doesn\'t support POST?? " + e.getMessage(), + e); + } + + urlConnection.setDoOutput(true); + urlConnection.setDoInput(true); + urlConnection.setUseCaches(false); + urlConnection.setAllowUserInteraction(false); + Iterator entryIterator = this.requestHeaders.entrySet().iterator(); + while (entryIterator.hasNext()) { + Map.Entry sb = (Map.Entry) entryIterator.next(); + urlConnection.setRequestProperty((String) sb.getKey(), (String) sb.getValue()); + } + OutputStream outputStream = urlConnection.getOutputStream(); + try { + OutputStreamWriter sb1 = new OutputStreamWriter(outputStream, "UTF-8"); + sb1.write(body); + sb1.close(); + } catch (IOException e) { + throw new Exception("IOException while sending data " + e.getMessage(), e); + } finally { + if (outputStream != null) { + outputStream.close(); + } + } + StringBuilder sb2 = new StringBuilder(); + BufferedReader rd = null; + try { + rd = new BufferedReader( + new InputStreamReader(urlConnection.getInputStream(), Charset.defaultCharset())); + String itr; + while ((itr = rd.readLine()) != null) { + sb2.append(itr); + } + } catch (FileNotFoundException e) { + throw new Exception("IOException while reading put request data " + e.getMessage(), e); + } finally { + if (rd != null) { + rd.close(); + } + } + Iterator iterator = urlConnection.getHeaderFields().keySet().iterator(); + HashMap responseHeaders = new HashMap(); + while (iterator.hasNext()) { + String key = (String) iterator.next(); + if (key != null) { + responseHeaders.put(key, urlConnection.getHeaderField(key)); + } + } + HttpResponse httpResponse = + new HttpResponse(sb2.toString(), urlConnection.getResponseCode(), responseHeaders); + return httpResponse; + } catch (IOException e) { + throw new Exception("Connection error (Is server running at " + endpoint + " ?): " + e.getMessage(), e); + } finally { + if (urlConnection != null) { + urlConnection.disconnect(); + } + + } + } + + public HttpResponse get(String endpoint) throws Exception { + return HttpRequestUtil.doGet(backEndUrl + endpoint, requestHeaders); + } + + public HttpResponse delete(String endpoint) throws Exception { + HttpURLConnection conn = null; + + HttpResponse httpResponse1; + try { + URL url = new URL(backEndUrl + endpoint); + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("DELETE"); + conn.setDoOutput(true); + conn.setReadTimeout(30000); + Iterator entryIterator = this.requestHeaders.entrySet().iterator(); + + while (entryIterator.hasNext()) { + Map.Entry rd = (Map.Entry) entryIterator.next(); + conn.setRequestProperty((String) rd.getKey(), (String) rd.getValue()); + } + + conn.connect(); + StringBuilder sb1 = new StringBuilder(); + BufferedReader rd1 = null; + + HttpResponse httpResponse; + try { + rd1 = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.defaultCharset())); + + String ignored; + while ((ignored = rd1.readLine()) != null) { + sb1.append(ignored); + } + + httpResponse = new HttpResponse(sb1.toString(), conn.getResponseCode()); + httpResponse.setResponseMessage(conn.getResponseMessage()); + } catch (IOException e) { + rd1 = new BufferedReader(new InputStreamReader(conn.getErrorStream(), Charset.defaultCharset())); + + String line; + while ((line = rd1.readLine()) != null) { + sb1.append(line); + } + + httpResponse = new HttpResponse(sb1.toString(), conn.getResponseCode()); + httpResponse.setResponseMessage(conn.getResponseMessage()); + } finally { + if (rd1 != null) { + rd1.close(); + } + + } + + httpResponse1 = httpResponse; + } finally { + if (conn != null) { + conn.disconnect(); + } + + } + + return httpResponse1; + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/TestBase.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/TestBase.java new file mode 100644 index 00000000..a4f2c05e --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/TestBase.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.common; + +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; +import org.wso2.carbon.integration.common.utils.LoginLogoutClient; + +import javax.xml.xpath.XPathExpressionException; + +/** + * This is the base test class that provides common details necessary for other test cases. + */ +public class TestBase { + protected AutomationContext automationContext; + protected String backendHTTPSURL; + protected String backendHTTPURL; + + protected void init(TestUserMode userMode) throws Exception { + automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); + backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants + .HTTPS_GATEWAY_PORT)); + backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants + .HTTP_GATEWAY_PORT)); + } + + protected void initPublisher(String productGroupName, String instanceName, + TestUserMode userMode) + throws XPathExpressionException { + automationContext = new AutomationContext(productGroupName, instanceName, userMode); + backendHTTPSURL = automationContext.getContextUrls().getBackEndUrl(); + } + + public String getBackendHTTPURL() { + return backendHTTPURL; + } + + public void setBackendHTTPURL(String backendHTTPURL) { + this.backendHTTPURL = backendHTTPURL; + } + + protected String getBackendHTTPSURL() throws XPathExpressionException { + return backendHTTPSURL; + } + + protected String getSessionCookie() throws Exception { + LoginLogoutClient loginLogoutClient = new LoginLogoutClient(automationContext); + return loginLogoutClient.login(); + } + + protected String getServiceURL() throws XPathExpressionException { + return automationContext.getContextUrls().getServiceUrl(); + } + + protected String getTestArtifactLocation() { + return FrameworkPathUtil.getSystemResourceLocation(); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/configuration/ConfigurationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/configuration/ConfigurationManagement.java new file mode 100644 index 00000000..0fe0525d --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/configuration/ConfigurationManagement.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.configuration; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for configuration management backend services. + */ +public class ConfigurationManagement extends TestBase { + + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.ConfigurationManagement.CONFIGURATION_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test save configuration.") + public void testSaveConfiguration() throws Exception { + HttpResponse response = client.post(Constants.ConfigurationManagement.CONFIGURATION_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.ConfigurationManagement.CONFIGURATION_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.ConfigurationManagement.CONFIGURATION_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true); + } + + @Test(description = "Test get configuration.", dependsOnMethods = {"testSaveConfiguration"}) + public void testGetConfiguration() throws Exception { + HttpResponse response = client.get(Constants.ConfigurationManagement.CONFIGURATION_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.ConfigurationManagement.CONFIGURATION_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_GET).toString(), response.getData().toString(), true); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java new file mode 100644 index 00000000..11d8ca8a --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/configuration/AndroidConfigurationManagement.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.configuration; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for Android configuration management backend services. + */ +public class AndroidConfigurationManagement extends TestBase { + + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.AndroidConfigurationManagement.DEVICE_CONFIGURATION_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test add android platform configuration.") + public void testAddConfiguration() throws Exception { + HttpResponse response = client.post(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString() + ); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidConfigurationManagement.RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), + response.getData().toString(), true + ); + } + + @Test(description = "Test update android configuration.", dependsOnMethods = {"testAddConfiguration"}) + public void testModifyConfiguration() throws Exception { + HttpResponse response = client.put(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString() + ); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidConfigurationManagement.RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), + response.getData().toString(), true + ); + } + +// @Test(description = "Test get android configuration.", +// dependsOnMethods = { "testAddConfiguration", "testModifyConfiguration" }) +// public void testGetConfiguration() throws Exception { +// HttpResponse response = client.get(Constants.AndroidConfigurationManagement.CONFIG_MGT_ENDPOINT); +// Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); +// AssertUtil.jsonPayloadCompare( +// PayloadGenerator.getJsonPayload(Constants.AndroidConfigurationManagement.PAYLOAD_FILE_NAME, +// Constants.HTTP_METHOD_PUT).toString(), +// response.getData().toString(), true +// ); +// } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java new file mode 100644 index 00000000..4687ad44 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/AndroidEnrollment.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.enrollment; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This contains testing of Android device enrollment which is necessary to run prior to all other Android related + * tests. + */ +public class AndroidEnrollment extends TestBase { + private RestClient client; + private String deviceId; + + @BeforeClass(alwaysRun = true, groups = { Constants.AndroidEnrollment.ENROLLMENT_GROUP}, dependsOnGroups = + Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test an Android device enrollment.") + public void testEnrollment() throws Exception { + String enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment + .ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString(); + HttpResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData); + JsonParser jsonParser = new JsonParser(); + JsonElement element = jsonParser.parse(response.getData()); + JsonObject jsonObject = element.getAsJsonObject(); + JsonElement msg = jsonObject.get("responseMessage"); + deviceId = msg.getAsString().split("\'")[1].split("\'")[0]; + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getData(), true); + } + + @Test(description = "Test an Android device is enrolled.", dependsOnMethods = {"testEnrollment"}) + public void testIsEnrolled() throws Exception { + HttpResponse response = client.get(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId + "/status"); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_GET).toString(), response.getData(), true); + } + + @Test(description = "Test modify enrollment.", dependsOnMethods = {"testIsEnrolled"}) + public void testModifyEnrollment() throws Exception { + JsonObject enrollmentData = PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT); + HttpResponse response = client.put(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId, + enrollmentData.toString()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), response.getData(), true); + } + + @Test(description = "Test disEnrollment.", dependsOnMethods = {"testModifyEnrollment"}) + public void testDisEnrollDevice() throws Exception { + HttpResponse response = client.delete(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT + "/" + deviceId); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_DELETE).toString(), response.getData(), true); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/WindowsEnrollment.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/WindowsEnrollment.java new file mode 100644 index 00000000..fe465ae4 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/enrollment/WindowsEnrollment.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.enrollment; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.io.FileUtils; +import org.json.JSONObject; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.RestClient; +import org.wso2.iot.integration.common.TestBase; + +import java.io.File; +import java.net.URL; + +/** + * This contains testing of Windows device enrollment which is necessary to run prior to all other Windows related + * tests. + */ +public class WindowsEnrollment extends TestBase { + private static final String BSD_PLACEHOLDER = "{BinarySecurityToken}"; + private static String bsd; + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + /** + * Test the Windows Discovery Get endpoint to see if the server is available. + * + * @throws Exception + */ + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery get.") + public void testServerAvailability() throws Exception { + client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML); + HttpResponse response = client.get(Constants.WindowsEnrollment.DISCOVERY_GET_URL); + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK); + } + + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery post.") + public void testDiscoveryPost() throws Exception { + String xml = readXML(Constants.WindowsEnrollment.DISCOVERY_POST_FILE, Constants.UTF8); + client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML); + HttpResponse response = client.post(Constants.WindowsEnrollment.DISCOVERY_POST_URL, xml); + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK); + } + + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows BST.") + public void testBST() throws Exception { + JSONObject bsdObject = new JSONObject(Constants.WindowsEnrollment.BSD_PAYLOAD); + JSONObject childObject = bsdObject.getJSONObject("credentials"); + + JSONObject modifiedObject = new JSONObject(); + modifiedObject.put("token", OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL)); + + childObject.put("token", modifiedObject); + + HttpResponse response = client.post(Constants.WindowsEnrollment.BSD_URL, Constants.WindowsEnrollment.BSD_PAYLOAD); + bsd = response.getData(); + + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK); + } + + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows MS XCEP post.", + dependsOnMethods = "testBST") + public void testMSXCEP() throws Exception { + String xml = readXML(Constants.WindowsEnrollment.MS_XCEP_FILE, Constants.UTF8); + String payload = xml.replace(BSD_PLACEHOLDER, bsd); + client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML); + HttpResponse response = client.post(Constants.WindowsEnrollment.MS_EXCEP, payload); + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED); + } + + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows WSETP post.", + dependsOnMethods = "testMSXCEP") + public void testWSETP() throws Exception { + String xml = readXML(Constants.WindowsEnrollment.WS_STEP_FILE, Constants.UTF8); + String payload = xml.replace(BSD_PLACEHOLDER, bsd); + client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML); + HttpResponse response = client.post(Constants.WindowsEnrollment.WSTEP_URL, payload); + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED); + } + + + private String readXML(String fileName, String characterEncoding) throws Exception { + URL url = ClassLoader.getSystemResource(fileName); + File folder = new File(url.toURI()); + return FileUtils.readFileToString(folder, characterEncoding); + } +/* + @Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows WSETP post.", + dependsOnMethods = "testWSETP") + public void testInitialDeviceInfo() throws Exception { + URL url = ClassLoader.getSystemResource("windows/enrollment/inital_device_info.xml"); + File folder = new File(url.toURI()); + String xml = FileUtils.readFileToString(folder, "UTF-16"); + client.setHttpHeader("Content-Type", "application/vnd.syncml.dm+xml;charset=utf-8"); + HttpResponse response = client.post(Constants.WindowsEnrollment.SYNC_ML_URL, xml); + + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK); + } + */ + +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java new file mode 100644 index 00000000..5b20f691 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/mgt/AndroidDeviceManagement.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.mgt; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for Android device management backend services. + */ +public class AndroidDeviceManagement extends TestBase { + private RestClient client; + private JsonObject device; + + @BeforeClass(alwaysRun = true, groups = {Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test get all android devices.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) + public void testGetAllDevices() throws Exception { + HttpResponse response = client.get(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT); + JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonArray(); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + Assert.assertEquals(jsonArray.size(), 1); + } + + @Test(description = "Test get android device.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) + public void testGetDevice() throws Exception { + HttpResponse response = client.get(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT + Constants.DEVICE_ID); + device = new JsonParser().parse(response.getData()).getAsJsonObject(); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + Assert.assertEquals(device.get(Constants.AndroidDeviceManagement.KEY_DEVICE_ID).getAsString(), Constants.DEVICE_ID); + } + + @Test(description = "Test update android device.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP, + dependsOnMethods = {"testGetDevice"}) + public void testUpdateDevice() throws Exception { + device.addProperty(Constants.AndroidDeviceManagement.KEY_DEVICE_NAME, "UpdatedName"); + HttpResponse response = client.put(Constants.AndroidDeviceManagement.DEVICE_MGT_ENDPOINT + Constants.DEVICE_ID, + device.toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidDeviceManagement.RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), + response.getData().toString(), true); + } + + + @Test(description = "Test get android license.", groups = Constants.AndroidDeviceManagement.DEVICE_MANAGEMENT_GROUP) + public void testGetLicense() throws Exception { + HttpResponse response = client.get(Constants.AndroidDeviceManagement.LICENSE_ENDPOINT); + CharSequence sequence = Constants.AndroidDeviceManagement.LICENSE_SECTION; + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + Assert.assertTrue(response.getData().contains(sequence)); + } + + /* + @Test(description = "Test update android device applist.", groups = Constants.DeviceManagement.DEVICE_MANAGEMENT_GROUP, + dependsOnMethods = {"testGetDevice"} ) + public void testUpdateAppList() throws Exception { + HttpResponse response = client.post(Constants.DeviceManagement.APP_LIST_ENDPOINT, + Constants.DeviceManagement.APPLIST_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(Constants.DeviceManagement.REQUEST_MODIFY_DEVICE_EXPECTED, + response.getData().toString(), true); + }*/ + +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java new file mode 100644 index 00000000..43e4fa12 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/operation/AndroidOperation.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.operation; + +import com.google.gson.JsonObject; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This contain tests to check operations supported by Android. Test are executed against a previously enrolled device + */ +public class AndroidOperation extends TestBase { + private RestClient client; + + @BeforeTest(alwaysRun = true, groups = { Constants.AndroidOperations.OPERATIONS_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + //Enroll a device + JsonObject enrollmentData = PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST); + client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device lock operation.") + public void testLock() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.LOCK_ENDPOINT, + Constants.AndroidOperations.LOCK_OPERATION_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + +/* + @Test(groups = Constants.AndroidOperations.OPERATIONS_GROUP, description = "Test Android getPendingOperations.") + public void testGetPendingOperations() throws Exception { + HttpResponse response = client.put(Constants.AndroidOperations.OPERATION_ENDPOINT + Constants.DEVICE_ID, + "[]"); + Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_CREATED); + }*/ + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device location " + + "operation.") + public void testLocation() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.LOCATION_ENDPOINT, + Constants.AndroidOperations.LOCATION_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device clear password " + + "operation.") + public void testClearPassword() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.CLEAR_PASSWORD_ENDPOINT, + Constants.AndroidOperations.CLEAR_PASSWORD_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device camera " + + "operation.") + public void testCamera() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.CAMERA_OPERATION, + Constants.AndroidOperations.CAMERA_OPERATION_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + +// //404 +// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android device information " +// + "operation.") +// public void testDeviceInfo() throws Exception { +// +// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + +// Constants.AndroidOperations.DEVICE_INFO_ENDPOINT, +// Constants.AndroidOperations.DEVICE_INFO_PAYLOAD); +// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); +// } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android enterprise-wipe " + + "operation.") + public void testEnterpriseWipe() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.ENTERPRISE_WIPE_ENDPOINT, + Constants.AndroidOperations.ENTERPRISE_WIPE_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android wipe data operation.") + public void testWipeData() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.WIPE_DATA_ENDPOINT, + Constants.AndroidOperations.WIPE_DATA_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + +// //400 +// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android application list " +// + "operation.") +// public void testApplicationList() throws Exception { +// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + +// Constants.AndroidOperations.APPLICATION_LIST_ENDPOINT, +// Constants.AndroidOperations.APPLICATION_LIST_PAYLOAD); +// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); +// } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android ring operation.") + public void testRing() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.RING_ENDPOINT, + Constants.AndroidOperations.RING_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android mute operation.") + public void testMute() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.MUTE_ENDPOINT, + Constants.AndroidOperations.MUTE_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + +// //400 +// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android install apps operation.") +// public void testInstallApps() throws Exception { +// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + +// Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, +// Constants.AndroidOperations.INSTALL_APPS_PAYLOAD); +// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); +// } + +// //400 +// @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android uninstall apps " +// + "operation.") +// public void testUninstallApps() throws Exception { +// HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + +// Constants.AndroidOperations.UNINSTALL_APPS_ENDPOINT, +// Constants.AndroidOperations.UNINSTALL_APPS_PAYLOAD); +// Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); +// } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android notification operation.") + public void testNotification() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.NOTIFICATION_ENDPOINT, + Constants.AndroidOperations.NOTIFICATION_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android WiFi operation.") + public void testWiFi() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.WIFI_ENDPOINT, + Constants.AndroidOperations.WIFI_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android encrypt operation.") + public void testEncrypt() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.ENCRYPT_ENDPOINT, + Constants.AndroidOperations.ENCRYPT_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android change lock operation.") + public void testChangeLock() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.CHANGE_LOCK_ENDPOINT, + Constants.AndroidOperations.CHANGE_LOCK_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android password policy operation.") + public void testPasswordPolicy() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.PASSWORD_POLICY_ENDPOINT, + Constants.AndroidOperations.PASSWORD_POLICY_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(groups = {Constants.AndroidOperations.OPERATIONS_GROUP}, description = "Test Android web clip operation.") + public void testWebClip() throws Exception { + HttpResponse response = client.post(Constants.AndroidOperations.OPERATION_ENDPOINT + + Constants.AndroidOperations.WEB_CLIP_ENDPOINT, + Constants.AndroidOperations.WEB_CLIP_PAYLOAD); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/policy/AndroidPolicy.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/policy/AndroidPolicy.java new file mode 100644 index 00000000..ab3d6ea1 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/device/policy/AndroidPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.device.policy; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This contain tests to check policy endpoints supported by Android. + * Test are executed against a previously enrolled device. + */ +public class AndroidPolicy extends TestBase { + + private RestClient client; + + @BeforeTest(alwaysRun = true, groups = { Constants.AndroidEnrollment.ENROLLMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(groups = Constants.AndroidPolicy.POLICY_GROUP, description = "Test Android getEffectivePolicy.") + public void testGetEffectivePolicy() throws Exception { + HttpResponse response = client.get(Constants.AndroidPolicy.POLICY_ENDPOINT + Constants.DEVICE_ID); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidPolicy.POLICY_RESPONSE_PAYLOAD_FILE_NAME, + Constants.AndroidPolicy.GET_EFFECTIVE_POLICY).toString(), + response.getData().toString(), true); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/AnalyticsServerExtension.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/AnalyticsServerExtension.java new file mode 100644 index 00000000..a4248b10 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/AnalyticsServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.extensions; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the DAS. + * This will set the carbon_home to {carbonHome}/core and port offset : 2 + */ +public class AnalyticsServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "2"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("analytics"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/BrokerServerExtension.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/BrokerServerExtension.java new file mode 100644 index 00000000..2bb86d87 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/BrokerServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.extensions; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the Broker. + * This will set the carbon_home to {carbonHome}/core and port offset : 3 + */ +public class BrokerServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "3"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("broker"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/CustomTestServerManager.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/CustomTestServerManager.java new file mode 100644 index 00000000..7f383780 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/CustomTestServerManager.java @@ -0,0 +1,147 @@ +/* +* Copyright (c) 2005-2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.wso2.iot.integration.extensions; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.FrameworkConstants; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerManager; + +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class CustomTestServerManager { + protected CarbonServerManager carbonServer; + protected String carbonZip; + protected int portOffset; + protected Map commandMap = new HashMap(); + private static final Log log = LogFactory.getLog(CustomTestServerManager.class); + protected String carbonHome; + + public CustomTestServerManager(AutomationContext context) { + carbonServer = new CarbonServerManager(context); + } + + public CustomTestServerManager(AutomationContext context, String carbonZip) { + carbonServer = new CarbonServerManager(context); + this.carbonZip = carbonZip; + } + + public CustomTestServerManager(AutomationContext context, int portOffset) { + carbonServer = new CarbonServerManager(context); + this.portOffset = portOffset; + commandMap.put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, String.valueOf(portOffset)); + } + + public CustomTestServerManager(AutomationContext context, String carbonZip, + Map commandMap) { + carbonServer = new CarbonServerManager(context); + this.carbonZip = carbonZip; + if (commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) != null) { + this.portOffset = Integer.parseInt(commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND)); + } else { + throw new IllegalArgumentException("portOffset value must be set in command list"); + } + this.commandMap = commandMap; + } + + public String getCarbonZip() { + return carbonZip; + } + + public String getCarbonHome() { + return carbonHome; + } + + public int getPortOffset() { + return portOffset; + } + + public void configureServer() throws AutomationFrameworkException { + + } + + + public Map getCommands() { + return commandMap; + } + + /** + * This method is called for starting a Carbon server in preparation for execution of a + * TestSuite + *

+ * Add the @BeforeSuite TestNG annotation in the method overriding this method + * @param server : The server which needs to be start. + * @return The CARBON_HOME + * @throws IOException If an error occurs while copying the deployment artifacts into the + * Carbon server + */ + public String startServer(String server) + throws AutomationFrameworkException, IOException, XPathExpressionException { + if(carbonHome == null) { + if (carbonZip == null) { + carbonZip = System.getProperty(FrameworkConstants.SYSTEM_PROPERTY_CARBON_ZIP_LOCATION); + } + if (carbonZip == null) { + throw new IllegalArgumentException("carbon zip file cannot find in the given location"); + } + carbonHome = carbonServer.setUpCarbonHome(carbonZip) + "/" + server; + configureServer(); + } + log.info("Carbon Home - " + carbonHome ); + if (commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) != null) { + this.portOffset = Integer.parseInt(commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND)); + } else { + this.portOffset = 0; + } + carbonServer.startServerUsingCarbonHome(carbonHome, commandMap); + return carbonHome; + } + + /** + * Restarting server already started by the method startServer + * @throws AutomationFrameworkException + */ + public void restartGracefully() throws AutomationFrameworkException { + if(carbonHome == null) { + throw new AutomationFrameworkException("No Running Server found to restart. " + + "Please make sure whether server is started"); + } + carbonServer.restartGracefully(); + } + + /** + * This method is called for stopping a Carbon server + *

+ * Add the @AfterSuite annotation in the method overriding this method + * + * @throws AutomationFrameworkException If an error occurs while shutting down the server + */ + public void stopServer() throws AutomationFrameworkException { + carbonServer.serverShutdown(portOffset); + } + + + + +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/IOTServerExtension.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/IOTServerExtension.java new file mode 100644 index 00000000..e8df4bad --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/extensions/IOTServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.extensions; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the IOT core. + * This will set the carbon_home to {carbonHome}/core and port offset : 0 + */ +public class IOTServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "0"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("core"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/feature/FeatureManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/feature/FeatureManagement.java new file mode 100644 index 00000000..64511e45 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/feature/FeatureManagement.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.feature; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.OAuthUtil; +import org.wso2.iot.integration.common.RestClient; +import org.wso2.iot.integration.common.TestBase; + +/** + * This class contains integration tests for feature management backend services. + */ +public class FeatureManagement extends TestBase { + + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.FeatureManagement.FEATURE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test view features.") + public void testViewFeatures() throws Exception { + HttpResponse response = client.get(Constants.FeatureManagement.VIEW_FEATURES_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/license/LicenseManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/license/LicenseManagement.java new file mode 100644 index 00000000..a96e2abd --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/license/LicenseManagement.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.license; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for license management backend services. + */ +public class LicenseManagement extends TestBase { + + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.LicenseManagement.LICENSE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test get license.") + public void testGetLicense() throws Exception { + HttpResponse response = client.get(Constants.LicenseManagement.GET_LICENSE_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.LicenseManagement.LICENSE_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_GET).toString(), response.getData().toString(), true); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagement.java new file mode 100644 index 00000000..f68daca4 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagement.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.mobileDevice; + +import com.google.gson.JsonObject; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for API Device management backend services. + */ +public class MobileDeviceManagement extends TestBase { + private IOTHttpClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Add an Android device.") + public void addEnrollment() throws Exception { + JsonObject enrollmentData = PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST); + enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID); + IOTResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getBody(), true); + } + + @Test(dependsOnMethods = {"addEnrollment"}, description = "Test count devices") + public void testCountDevices() throws Exception { + IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertTrue(response.getBody().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES)); + + } + + @Test(dependsOnMethods = {"addEnrollment"}, description = "Test view devices") + public void testViewDevices() throws Exception { + IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_ALL_DEVICES_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + } + + @Test(dependsOnMethods = {"addEnrollment"}, description = "Test view device types") + public void testViewDeviceTypes() throws Exception { + IOTResponse response = client.get(Constants.MobileDeviceManagement.VIEW_DEVICE_TYPES_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(PayloadGenerator.getJsonPayloadToString + (Constants.MobileDeviceManagement.VIEW_DEVICE_RESPONSE_PAYLOAD_FILE_NAME), response.getBody()); + //Response has two device types, because in windows enrollment a windows device is previously enrolled. + } + + @Test(description = "Change device status") + public void testRemoveDevices() throws Exception { + String endpointUrl = Constants.MobileDeviceManagement.CHANGE_DEVICE_STATUS_ENDPOINT + Constants.ANDROID_DEVICE_TYPE + + "/" + Constants.DEVICE_ID + "/changestatus?newStatus=" + Constants.INACTIVE; + IOTResponse response = client.put(endpointUrl, ""); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java new file mode 100644 index 00000000..eeaa37a9 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.mobileDevice; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.junit.experimental.theories.Theories; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.iot.integration.common.*; + +import java.util.concurrent.TimeUnit; + +/** + * This class contains integration tests for API Mobile Device Management with No Devices Enrolled. + */ +public class MobileDeviceManagementWithNoDevices extends TestBase { + private IOTHttpClient client; + + /** + * @BeforeSuite annotation is added to run this verification before the test suite starts. + * As in IoT server, apis are published after the server startup. Due to that the generated token doesn't get + * required scope. + * This method delays test suit startup until the tokens get required scopes. + * @throws Exception + */ + @BeforeSuite + public void verifyApiPublishing() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + + while (!checkScopes(Constants.APIApplicationRegistration.PERMISSION_LIST)) { + TimeUnit.SECONDS.sleep(5); + } + } + + @BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test count devices with no added devices") + public void testCountDevicesWithNoDevices() throws Exception { + IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(Constants.MobileDeviceManagement.NO_DEVICE, response.getBody()); + } + + private boolean checkScopes(String permissionsList) throws Exception { + String tokenString = OAuthUtil.getScopes(backendHTTPSURL, backendHTTPSURL); + return tokenString.contains(permissionsList); + } + +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/notification/NotificationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/notification/NotificationManagement.java new file mode 100644 index 00000000..9056f8a0 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/notification/NotificationManagement.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.notification; + +import com.google.gson.JsonObject; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for notification management backend services. + */ +public class NotificationManagement extends TestBase { + + private RestClient client; + + @BeforeTest(alwaysRun = true, groups = {Constants.NotificationManagement.NOTIFICATION_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + //Enroll a device + JsonObject enrollmentData = PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST); + enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID); + client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); + } + + @Test(description = "Test add notification.") + public void testAddNotification() throws Exception { + HttpResponse response = client.post(Constants.NotificationManagement.NOTIFICATION_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.NotificationManagement.NOTIFICATION_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.NotificationManagement.NOTIFICATION_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), + response.getData().toString(), true); + } + + @Test(description = "Test update notification.", dependsOnMethods = {"testAddNotification"}) + public void testUpdateNotification() throws Exception { + HttpResponse response = client.put(Constants.NotificationManagement.NOTIFICATION_UPDATE_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.NotificationManagement.NOTIFICATION_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.NotificationManagement.NOTIFICATION_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), + response.getData().toString(), true); + + } + + @Test(description = "Test get notification.", dependsOnMethods = {"testUpdateNotification"}) + public void testGetNotification() throws Exception { + HttpResponse response = client.get(Constants.NotificationManagement.NOTIFICATION_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + } +} diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/operation/OperationManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/operation/OperationManagement.java new file mode 100644 index 00000000..a7e39941 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/operation/OperationManagement.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.operation; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * This class contains integration tests for API Operation management backend services. + */ +public class OperationManagement extends TestBase { + + private JsonObject device; + private IOTHttpClient client; + private RestClient rclient; + + @BeforeClass(alwaysRun = true, groups = { Constants.OperationManagement.OPERATION_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + this.rclient = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Add an Android device.") + public void testEnrollment() throws Exception { + JsonObject enrollmentData = PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST); + enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID); + IOTResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload( + Constants.AndroidEnrollment.ENROLLMENT_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getBody(), true); + } + + @Test(dependsOnMethods = {"testEnrollment"}, description = "Test Android install apps operation.") + public void testInstallApps() throws Exception { + JsonObject operationData = PayloadGenerator.getJsonPayload( + Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME, + Constants.AndroidOperations.INSTALL_APPS_OPERATION); + JsonArray deviceIds = new JsonArray(); + JsonPrimitive deviceID = new JsonPrimitive(Constants.DEVICE_ID); + deviceIds.add(deviceID); + operationData.add(Constants.DEVICE_IDENTIFIERS_KEY, deviceIds); + HttpResponse response = rclient.post(Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, + operationData.toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + } + + @Test(dependsOnMethods = {"testInstallApps"}, description = "Test get device apps with wrong Device ID") + public void testGetDeviceAppsWithWrongDeviceID() throws Exception { + IOTResponse response = client.get(Constants.OperationManagement.GET_DEVICE_APPS_ENDPOINT + + Constants.NUMBER_NOT_EQUAL_TO_DEVICE_ID + Constants.OperationManagement.PATH_APPS); + Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); + + } + + @Test(dependsOnMethods = {"testInstallApps"}, description = "Test get operations for device with wrong Device ID") + public void testGetDeviceOperationsWithWrongDeviceID() throws Exception { + IOTResponse response = client.get(Constants.OperationManagement.GET_DEVICE_OPERATIONS_ENDPOINT + Constants.DEVICE_IMEI); + Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/policy/PolicyManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/policy/PolicyManagement.java new file mode 100644 index 00000000..70ec513a --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/policy/PolicyManagement.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.policy; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for policy management backend services. + */ +public class PolicyManagement extends TestBase { + + private IOTHttpClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.PolicyManagement.POLICY_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test add policy.") + public void testAddPolicy() throws Exception { + + IOTResponse response = client.post(Constants.PolicyManagement.ADD_POLICY_ENDPOINT, + PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getBody()); + + } + + @Test(description = "Test view policy list.", dependsOnMethods = {"testAddPolicy"}) + public void testViewPolicyList() throws Exception { + IOTResponse response = client.get(Constants.PolicyManagement.VIEW_POLICY_LIST_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + + } + + @Test(description = "Test update policy.", dependsOnMethods = {"testViewPolicyList"}) + public void testUpdatePolicy() throws Exception { + + IOTResponse response = client.put(Constants.PolicyManagement.UPDATE_POLICY_ENDPOINT, + PayloadGenerator.getJsonPayload( + Constants.PolicyManagement.POLICY_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), response.getBody()); + } + + @Test(description = "Test remove policy.", dependsOnMethods = {"testUpdatePolicy"}) + public void testRemovePolicy() throws Exception { + + IOTResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT, + Constants.PolicyManagement.REMOVE_POLICY_PAYLOAD_FILE_NAME); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_DELETE).toString(), response.getBody()); + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java new file mode 100644 index 00000000..185bca4c --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/role/RoleManagement.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.role; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for role management backend services. + */ +public class RoleManagement extends TestBase { + + private IOTHttpClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.RoleManagement.ROLE_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test add role.") + public void testAddRole() throws Exception { + IOTResponse response = client.post(Constants.RoleManagement.ADD_ROLE_ENDPOINT, + PayloadGenerator.getJsonPayload(Constants.RoleManagement.ROLE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + } + + @Test(description = "Test update permission role.", dependsOnMethods = {"testAddRole"}) + public void testUpdateRolePermission() throws Exception { + IOTResponse response = client.put(Constants.RoleManagement.UPDATE_ROLE_PERMISSION_ENDPOINT, + PayloadGenerator.getJsonPayload(Constants.RoleManagement.UPDATE_ROLE_PERMISSION_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + } + + @Test(description = "Test remove user.", dependsOnMethods = {"testUpdateRolePermission"}) + public void testRemoveRole() throws Exception { + IOTResponse response = client.delete(Constants.RoleManagement.REMOVE_ROLE_ENDPOINT); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java new file mode 100644 index 00000000..debc6222 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/user/UserManagement.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.iot.integration.user; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.*; + +/** + * This class contains integration tests for user management backend services. + */ +public class UserManagement extends TestBase { + + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "Test add user.") + public void testAddUser() throws Exception { + HttpResponse response = client.post(Constants.UserManagement.USER_ENDPOINT, + PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_POST).toString(), response.getData().toString(), true); + } + + @Test(description = "Test update user.", dependsOnMethods = {"testAddUser"}) + public void testUpdateUser() throws Exception { + String url = GetURL(Constants.UserManagement.USER_ENDPOINT); + HttpResponse response = client.put(url, + PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString()); + Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_PUT).toString(), response.getData().toString(), true); + + } + + @Test(description = "Test view user.", dependsOnMethods = {"testUpdateUser"}) + public void testViewUser() throws Exception { + String url = GetURL(Constants.UserManagement.VIEW_USER_ENDPOINT); + HttpResponse response = client.get(url); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_GET).toString(), response.getData().toString(), true); + } + + @Test(description = "Test remove user.", dependsOnMethods = {"testViewUser"}) + public void testRemoveUser() throws Exception { + String url = GetURL(Constants.UserManagement.USER_ENDPOINT); + HttpResponse response = client.delete(url); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + AssertUtil.jsonPayloadCompare(PayloadGenerator.getJsonPayload(Constants.UserManagement.USER_RESPONSE_PAYLOAD_FILE_NAME, + Constants.HTTP_METHOD_DELETE).toString(), response.getData().toString(), true); + + } + + private String GetURL(String endPoint) { + return endPoint + "?username=" + Constants.UserManagement.USER_NAME; + } + +} diff --git a/modules/integration/tests-integration/src/test/resources/automation.xml b/modules/integration/tests-integration/src/test/resources/automation.xml new file mode 100644 index 00000000..5e6200ee --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/automation.xml @@ -0,0 +1,224 @@ + + + + + + + + + 100000 + + standalone + + false + + false + + + + + + + http://10.100.2.51:4444/wd/hub/ + + + + firefox + + /home/test/name/webDriver + + + + + + + jdbc:h2:testDB + wso2carbon + wso2carbon + org.h2.Driver + + + jdbc:h2:testDB + wso2carbon + wso2carbon + org.h2.Driver + + + + + + + keystores/products/wso2carbon.jks + + JKS + + wso2carbon + + wso2carbon + + wso2carbon + + + + + client-truststore.jks + + JKS + + wso2carbon + + + + + + https://wso2.org/repo + file:///home/krishantha/test + + + + + + + + + + admin + admin + + + + + testuser11 + testuser11 + + + testuser21 + testuser21 + + + + + + + + + admin + admin + + + + + testuser11 + testuser11 + + + testuser21 + testuser21 + + + + + + + + + + + + + localhost + + + 9763 + + 9443 + + + + + + + + + + + + + + + + + org.wso2.iot.integration.extensions.IOTServerExtension + + org.wso2.carbon.integration.common.extensions.usermgt.UserPopulateExtension + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-integration/src/test/resources/automationSchema.xsd b/modules/integration/tests-integration/src/test/resources/automationSchema.xsd new file mode 100644 index 00000000..c3bd1b35 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/automationSchema.xsd @@ -0,0 +1,565 @@ + + + + + + + + + ================================================= + Parameters ================================================= + Browser type with used by framework to execute UI test, supported types + - chrome|firefox|opera|ie|htmlUnit + + + + + + + Change this to edit wait time for test + artifact deployment + + + + + + Change this to product|platform/cloud to + execute test on specific environment + + + + + + Change this to user/tenant to execute test + with user mode or tenant mode + + + + + + Change this to true if you want to generate + coverage statistics + + + + + + Change this to true if you want to enable + framework dashboard + + + + + + + + + + + + + + + Change to enable remote webDriver + URL of remote webDriver server + + + + + + + + + + + + + Type of the browser selenium tests + are running" + + + + + + + + path to webDriver + executable - required only for + chrome + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KeyStore which will be used for + encrypting/decrypting passwords + and other sensitive information. + + + + + + + Keystore file location + + + + + + Keystore type (JKS/PKCS12 etc.) + + + + + + Keystore password + + + + + + Private Key alias + + + + + + Private Key password + + + + + + + + + + System wide trust-store which is used to + maintain the certificates of all + the trusted parties. + + + + + + + trust-store file location + + + + + + trust-store type (JKS/PKCS12 + etc.) + + + + + + trust-store password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/filters.txt b/modules/integration/tests-integration/src/test/resources/filters.txt new file mode 100644 index 00000000..8813e634 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/filters.txt @@ -0,0 +1,23 @@ +-org.wso2.carbon.caching.core.identity.* +-org.wso2.carbon.caching.core.permissiontree.* +-org.wso2.carbon.caching.infinispan.* +-org.wso2.carbon.event.core.internal.delivery.jms.* +-org.wso2.carbon.event.core.qpid.* +-org.wso2.carbon.registry.synchronization.* +-*.stub* +-*.stub_ +-*.stub_4.0.0 +-*.stub- +-org.eclipse.* +-*.equinox.* +-org.wso2.carbon.user.core.* +-samples.* +-*.log4j* +-*.axis2* +-*.ui* +-*.tenant* +-*.stratos* +-*.eventing* +-*tests-transports* +-org.wso2.carbon.mediation.statistics* +-*startup* diff --git a/modules/integration/tests-integration/src/test/resources/instrumentation.txt b/modules/integration/tests-integration/src/test/resources/instrumentation.txt new file mode 100644 index 00000000..f9f1894a --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/instrumentation.txt @@ -0,0 +1,41 @@ +org.wso2.carbon.caching.core_ +org.wso2.carbon.discovery.core_ +org.wso2.carbon.discovery.proxy_ +org.wso2.carbon.email.verification_ +org.wso2.carbon.event.core_ +org.wso2.carbon.governance.custom.lifecycles.checklist_ +org.wso2.carbon.governance.gadgets.impactanalysis_ +org.wso2.carbon.governance.gadgetsource_ +org.wso2.carbon.governance.gadgets.resourceimpact_ +org.wso2.carbon.governance.generic_ +org.wso2.carbon.governance.lcm_ +org.wso2.carbon.governance.list_ +org.wso2.carbon.governance.platform.extensions_ +org.wso2.carbon.governance.registry.eventing_ +org.wso2.carbon.governance.registry.extensions_ +org.wso2.carbon.governance.services_ +org.wso2.carbon.identity.user.profile_ +org.wso2.carbon.mashup.javascript.hostobjects.registry_ +org.wso2.carbon.registry.activities_ +org.wso2.carbon.registry.common_ +org.wso2.carbon.registry.core_ +org.wso2.carbon.registry.eventing_ +org.wso2.carbon.registry.extensions_ +org.wso2.carbon.registry.handler_ +org.wso2.carbon.registry.indexing_ +org.wso2.carbon.registry.info_ +org.wso2.carbon.registry.profiles_ +org.wso2.carbon.registry.properties_ +org.wso2.carbon.registry.relations_ +org.wso2.carbon.registry.reporting_ +org.wso2.carbon.registry.resource_ +org.wso2.carbon.registry.search_ +org.wso2.carbon.registry.server_ +org.wso2.carbon.registry.servlet_ +org.wso2.carbon.registry.task_ +org.wso2.carbon.registry.uddi_ +org.wso2.carbon.registry.webdav_ +org.wso2.carbon.registry.ws.api_ +org.wso2.carbon.reporting.api_ +org.wso2.carbon.reporting.core_ +org.wso2.carbon.reporting.util_ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/products/client-truststore.jks b/modules/integration/tests-integration/src/test/resources/keystores/products/client-truststore.jks new file mode 100644 index 00000000..ab222fdd Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/products/client-truststore.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/products/wso2carbon.jks b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2carbon.jks new file mode 100644 index 00000000..79784a5e Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2carbon.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/products/wso2certs.jks b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2certs.jks new file mode 100644 index 00000000..eb27997d Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2certs.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/products/wso2mdm.jks b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2mdm.jks new file mode 100644 index 00000000..66b68ea3 Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/products/wso2mdm.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/stratos/client-truststore.jks b/modules/integration/tests-integration/src/test/resources/keystores/stratos/client-truststore.jks new file mode 100644 index 00000000..ab222fdd Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/stratos/client-truststore.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2carbon.jks b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2carbon.jks new file mode 100644 index 00000000..79784a5e Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2carbon.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2certs.jks b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2certs.jks new file mode 100644 index 00000000..eb27997d Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2certs.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2emm.jks b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2emm.jks new file mode 100644 index 00000000..ae5670b0 Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/keystores/stratos/wso2emm.jks differ diff --git a/modules/integration/tests-integration/src/test/resources/log4j.properties b/modules/integration/tests-integration/src/test/resources/log4j.properties new file mode 100644 index 00000000..bc395345 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/log4j.properties @@ -0,0 +1,45 @@ +# +# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=INFO, console, Default + +log4j.logger.org.wso2=INFO +log4j.logger.org.apache.axis2.deployment.ModuleDeployer=ERROR +#Automation file apender +log4j.appender.Default=org.apache.log4j.RollingFileAppender +log4j.appender.Default.File=logs/automation.log +log4j.appender.Default.Append=true +log4j.appender.Default.MaxFileSize=10MB +log4j.appender.Default.MaxBackupIndex=10 +log4j.appender.Default.layout=org.apache.log4j.PatternLayout +log4j.appender.Default.layout.ConversionPattern=%d{ISO8601} %-5p [%c] - %m%n + + +#Automation console apender +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%-5p [%c] - %m%n diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json new file mode 100644 index 00000000..5e8353b5 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-config-response-payloads.json @@ -0,0 +1,10 @@ +{ + "POST": { + "responseCode": "Created", + "responseMessage": "Android platform configuration saved successfully." + }, + "PUT": { + "responseCode": "Accepted", + "responseMessage": "Android platform configuration has updated successfully." + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-configuration-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-configuration-payloads.json new file mode 100644 index 00000000..0bdff5a6 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-configuration-payloads.json @@ -0,0 +1,42 @@ +{ + "POST": { + "type": "android", + "configuration": [ + { + "name": "notifierType", + "value": "1", + "contentType": "text" + }, + { + "name": "notifierFrequency", + "value": "100000", + "contentType": "text" + }, + { + "name": "androidEula", + "value": "This End User License Agreement.", + "contentType": "text" + } + ] + }, + "PUT": { + "type": "android", + "configuration": [ + { + "name": "notifierType", + "value": "1", + "contentType": "text" + }, + { + "name": "notifierFrequency", + "value": "500000", + "contentType": "text" + }, + { + "name": "androidEula", + "value": "This End User License Agreement is Eula.", + "contentType": "text" + } + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-device-mgt-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-device-mgt-response-payloads.json new file mode 100644 index 00000000..17080c95 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-device-mgt-response-payloads.json @@ -0,0 +1,5 @@ +{ + "PUT": { + "responseMessage": "Device information has modified successfully." + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json new file mode 100644 index 00000000..ca0c8a6b --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-payloads.json @@ -0,0 +1,186 @@ +{ + "POST": { + "id": 101234, + "name": "androiddevice1234", + "type": "android", + "description": "this is an android device", + "deviceIdentifier": "d24f870f390352a41234", + "enrolmentInfo": { + "id": 101234, + "device": { + }, + "dateOfEnrolment": 0, + "dateOfLastUpdate": 0, + "ownership": "BYOD", + "status": "CREATED", + "owner": "admin" + }, + "features": [ + { + "id": 10, + "code": "aaaa1111", + "name": "newfeature1", + "description": "this is the new feature 1", + "deviceType": "android", + "metadataEntries": [ + { + "id": 10, + "value": { + } + } + ] + } + ], + "properties": [ + { + "name": "property1", + "value": "value1" + } + ], + "deviceInfo": { + "deviceModel": "S8", + "vendor": "SAMSUNG", + "osVersion": "5.1", + "batteryLevel": 1, + "internalTotalMemory": 32, + "internalAvailableMemory": 24, + "externalTotalMemory": 64, + "externalAvailableMemory": 60, + "operator": "dialog", + "connectionType": "GSM", + "mobileSignalStrength": 1, + "ssid": "picassowifi", + "cpuUsage": 0, + "totalRAMMemory": 2, + "availableRAMMemory": 1, + "pluggedIn": false, + "location": { + "deviceId": 0, + "deviceIdentifier": { + "id": "string", + "type": "string" + }, + "latitude": 0, + "longitude": 0, + "street1": "string", + "street2": "string", + "city": "string", + "state": "string", + "zip": "string", + "country": "string" + }, + "deviceDetailsMap": { + }, + "imei": "string", + "imsi": "string" + }, + "applications": [ + { + "id": 0, + "platform": "string", + "category": "string", + "name": "string", + "locationUrl": "string", + "imageUrl": "string", + "version": "string", + "type": "string", + "appProperties": { + }, + "applicationIdentifier": "string", + "memoryUsage": 0 + } + ] + }, + "PUT": { + "id": 101234, + "name": "androiddevice1234", + "type": "android", + "description": "this is an android device", + "deviceIdentifier": "d24f870f390352a41234", + "enrolmentInfo": { + "id": 101234, + "device": { + }, + "dateOfEnrolment": 0, + "dateOfLastUpdate": 0, + "ownership": "BYOD", + "status": "CREATED", + "owner": "admin" + }, + "features": [ + { + "id": 10, + "code": "aaaa1111", + "name": "newfeature2", + "description": "this is the new feature 2", + "deviceType": "android", + "metadataEntries": [ + { + "id": 10, + "value": { + } + } + ] + } + ], + "properties": [ + { + "name": "property2", + "value": "value2" + } + ], + "deviceInfo": { + "deviceModel": "S8", + "vendor": "SAMSUNG", + "osVersion": "5.1", + "batteryLevel": 1, + "internalTotalMemory": 32, + "internalAvailableMemory": 24, + "externalTotalMemory": 64, + "externalAvailableMemory": 60, + "operator": "dialog", + "connectionType": "GSM", + "mobileSignalStrength": 1, + "ssid": "picassowifi", + "cpuUsage": 0, + "totalRAMMemory": 2, + "availableRAMMemory": 1, + "pluggedIn": false, + "location": { + "deviceId": 0, + "deviceIdentifier": { + "id": "string", + "type": "string" + }, + "latitude": 0, + "longitude": 0, + "street1": "string", + "street2": "string", + "city": "string", + "state": "string", + "zip": "string", + "country": "string" + }, + "deviceDetailsMap": { + }, + "imei": "string", + "imsi": "string" + }, + "applications": [ + { + "id": 0, + "platform": "string", + "category": "string", + "name": "string", + "locationUrl": "string", + "imageUrl": "string", + "version": "string", + "type": "string", + "appProperties": { + }, + "applicationIdentifier": "string", + "memoryUsage": 0 + } + ] + } +} diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-response-payloads.json new file mode 100644 index 00000000..2b158a47 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-enrollment-response-payloads.json @@ -0,0 +1,19 @@ +{ + "POST": { + "responseCode": "OK", + "responseMessage": "Android device, which carries the id \u0027d24f870f390352a41234\u0027 has successfully been enrolled" + }, + "GET": { + "responseCode": "OK", + "responseMessage": "Android device that carries the id \u0027d24f870f390352a41234\u0027 is enrolled" + }, + "PUT": { + "responseCode": "Accepted", + "responseMessage": "Enrollment of Android device that carries the id \u0027d24f870f390352a41234\u0027 has successfully updated" + }, + "DELETE" : { + "responseCode":"OK", + "responseMessage":"Android device that carries id \u0027d24f870f390352a41234\u0027 has successfully dis-enrolled" + } + +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json new file mode 100644 index 00000000..b6bd861c --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-operation-payloads.json @@ -0,0 +1,68 @@ +{ + "camera": { + "operation": { + "enabled": false + }, + "deviceIDs": [] + }, + "wipe_data": { + "operation": { + "pin": "1234" + }, + "deviceIDs": [] + }, + "install_apps": { + "operation": { + "appIdentifier": "package_name", + "type": "enterprise/public/webapp", + "url": "https://www.youtube.com", + "name": "youtube" + }, + "deviceIDs": [] + }, + "notification": { + "operation": { + "message": "message" + }, + "deviceIDs": [] + }, + "wifi": { + "operation": { + "ssid": "ssid", + "password": "password" + }, + "deviceIDs": [] + }, + "encrypt": { + "operation": { + "encrypted": false + }, + "deviceIDs": [] + }, + "change_lock": { + "operation": { + "lockCode": "lock_code" + }, + "deviceIDs": [] + }, + "password_policy": { + "operation": { + "maxFailedAttempts": 1, + "minLength": 5, + "pinHistory": 1, + "minComplexChars": 4, + "maxPINAgeInDays": 1, + "requireAlphanumeric": true, + "allowSimple": true + }, + "deviceIDs": [] + }, + "web_clip": { + "operation": { + "identity": "identity", + "title": "title", + "type": "install" + }, + "deviceIDs": [] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-response-payloads.json new file mode 100644 index 00000000..eac7f5f8 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-response-payloads.json @@ -0,0 +1,6 @@ +{ + "getEffectivePolicy": { + "responseCode": "No Content", + "responseMessage": "No effective policy found" + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/configuration-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/configuration-payloads.json new file mode 100644 index 00000000..c6fb2505 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/configuration-payloads.json @@ -0,0 +1,11 @@ +{ + "POST": { + "configuration": [ + { + "name": "notifierFrequency", + "value": "5", + "contentType": "text" + } + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/configuration-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/configuration-response-payloads.json new file mode 100644 index 00000000..5a51ed40 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/configuration-response-payloads.json @@ -0,0 +1,15 @@ +{ + "POST": { + "statusCode": 201, + "messageFromServer": "Tenant configuration saved successfully." + }, + "GET": { + "configuration": [ + { + "name": "notifierFrequency", + "contentType": "text", + "value": "5" + } + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/get-notifications-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/get-notifications-response-payloads.json new file mode 100644 index 00000000..fd3007e5 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/get-notifications-response-payloads.json @@ -0,0 +1,12 @@ +[ + { + "notificationId": 1, + "deviceIdentifier": { + "id": "1234", + "type": "android" + }, + "description": "test notification", + "operationId": 1, + "status": "NEW" + } +] \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/license-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/license-response-payloads.json new file mode 100644 index 00000000..7ffcf40d --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/license-response-payloads.json @@ -0,0 +1,7 @@ +{ + "GET": { + "statusCode": 200, + "messageFromServer": "License for \u0027android\u0027 was retrieved successfully", + "responseContent": "This End User License Agreement is Eula." + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/mobile-device-mgt-view-device-types-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/mobile-device-mgt-view-device-types-response-payloads.json new file mode 100644 index 00000000..e473a3a9 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/mobile-device-mgt-view-device-types-response-payloads.json @@ -0,0 +1,10 @@ +[ + { + "id": 1, + "name": "android" + }, + { + "id": 2, + "name": "windows" + } +] \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/notification-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/notification-payloads.json new file mode 100644 index 00000000..a7b7729c --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/notification-payloads.json @@ -0,0 +1,20 @@ +{ + "POST": { + "description": "test notification", + "operationId": 1, + "deviceIdentifier": { + "id": "1234", + "type": "android" + }, + "status": "NEW" + }, + "PUT": { + "description": "test notification changed", + "operationId": 1, + "deviceIdentifier": { + "id": "1234", + "type": "android" + }, + "status": "NEW" + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/notification-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/notification-response-payloads.json new file mode 100644 index 00000000..189e5d7c --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/notification-response-payloads.json @@ -0,0 +1,10 @@ +{ + "POST": { + "statusCode": 201, + "messageFromServer": "Notification has added successfully." + }, + "PUT": { + "statusCode": 202, + "messageFromServer": "Notification status updated successfully." + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/permissions.json b/modules/integration/tests-integration/src/test/resources/payloads/permissions.json new file mode 100644 index 00000000..7b3f663a --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/permissions.json @@ -0,0 +1,3 @@ +{ + "default perm:admin-groups:count perm:admin-groups:view perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view perm:admin:devices:view perm:android:blacklist-applications perm:android:change-lock-code perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage perm:android:enroll perm:android:enterprise-wipe perm:android:info perm:android:install-application perm:android:location perm:android:lock-devices perm:android:logcat perm:android:manage-configuration perm:android:mute perm:android:reboot perm:android:ring perm:android:send-notification perm:android:set-password-policy perm:android:set-webclip perm:android:uninstall-application perm:android:unlock-devices perm:android:update-application perm:android:upgrade-firmware perm:android:view-configuration perm:android:wipe perm:applications:install perm:applications:uninstall perm:dashboard:by-groups perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities perm:device-types:features perm:device-types:types perm:devices:applications perm:devices:compliance-data perm:devices:delete perm:devices:details perm:devices:effective-policy perm:devices:features perm:devices:operations perm:devices:search perm:devices:update perm:devices:view perm:get-activity perm:groups:add perm:groups:assign perm:groups:count perm:groups:device perm:groups:devices perm:groups:devices-add perm:groups:devices-count perm:groups:devices-remove perm:groups:groups perm:groups:groups-view perm:groups:remove perm:groups:roles perm:groups:share perm:groups:update perm:manage-configuration perm:notifications:mark-checked perm:notifications:view perm:policies:activate perm:policies:changes perm:policies:deactivate perm:policies:get-details perm:policies:get-policy-details perm:policies:manage perm:policies:priorities perm:policies:remove perm:policies:update perm:roles:add perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details perm:roles:permissions perm:roles:update perm:roles:view perm:users:add perm:users:count perm:users:credentials perm:users:delete perm:users:details perm:users:is-exist perm:users:roles perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration" +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-payloads.json new file mode 100644 index 00000000..e7f27daf --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-payloads.json @@ -0,0 +1,56 @@ +{ + "POST": { + "policyName": "Camera", + "description": "Optional", + "compliance": "enforce", + "ownershipType": "ANY", + "profile": { + "profileName": "Camera", + "deviceType": { + "id": 1 + }, + "profileFeaturesList": [ + { + "featureCode": "CAMERA", + "deviceTypeId": 1, + "content": { + "enabled": true + } + } + ] + }, + "users": [], + "roles": [] + }, + "PUT": { + "policyName": "Camera", + "description": "Optional", + "compliance": "enforce", + "ownershipType": "ANY", + "profile": { + "profileName": "Camera", + "deviceType": { + "id": 1 + }, + "profileFeaturesList": [ + { + "featureCode": "CAMERA", + "deviceTypeId": 1, + "content": { + "enabled": true + } + }, + { + "featureCode": "ENCRYPT_STORAGE", + "deviceTypeId": 1, + "content": { + "encrypted": true + } + } + ] + }, + "roles": [ + "ANY" + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json new file mode 100644 index 00000000..396a639c --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json @@ -0,0 +1,14 @@ +{ + "POST": { + "statusCode": 201, + "messageFromServer": "Policy has been added successfully." + }, + "PUT": { + "statusCode": 201, + "messageFromServer": "Policy has been updated successfully." + }, + "DELETE": { + "statusCode": 200, + "messageFromServer": "Policies have been successfully deleted." + } +} diff --git a/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json new file mode 100644 index 00000000..6d7ace6b --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/role-payloads.json @@ -0,0 +1,15 @@ +{ + "POST": { + "roleName": "administration", + "users": [ + "admin" + ] + }, + "PUT": { + "permissions": [ + "permission/admin/device-mgt/android/operations/disenroll", + "permission/admin/device-mgt/android/operations/notification", + "/permission/admin/device-mgt/windows/operation/lock" + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/user-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/user-payloads.json new file mode 100644 index 00000000..94d37f88 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/user-payloads.json @@ -0,0 +1,22 @@ +{ + "POST": { + "username": "PRIMARY/username123", + "firstname": "userfirstname", + "lastname": "userlastname", + "emailAddress": "user123@gmail.com", + "roles": [ + "admin" + ] + }, + "PUT": { + "username": "username123", + "firstname": "userfname", + "lastname": "userlname", + "emailAddress": "user1234@gmail.com", + "password": "username", + "roles": [ + "admin", + "Internal/everyone" + ] + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/user-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/user-response-payloads.json new file mode 100644 index 00000000..1c7279e6 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/payloads/user-response-payloads.json @@ -0,0 +1,24 @@ +{ + "POST": { + "statusCode": 201, + "messageFromServer": "User by username: PRIMARY/username123 was successfully added." + }, + "PUT": { + "statusCode": 201, + "messageFromServer": "User by username: username123 was successfully updated." + }, + "GET": { + "statusCode": 200, + "messageFromServer": "User information was retrieved successfully.", + "responseContent": { + "username": "username123", + "firstname": "userfname", + "lastname": "userlname", + "emailAddress": "user1234@gmail.com" + } + }, + "DELETE": { + "statusCode": 200, + "messageFromServer": "User by username: username123 was successfully removed." + } +} \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/testng-server-mgt.xml b/modules/integration/tests-integration/src/test/resources/testng-server-mgt.xml new file mode 100644 index 00000000..fa3a3fa7 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/testng-server-mgt.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/testng.xml b/modules/integration/tests-integration/src/test/resources/testng.xml new file mode 100644 index 00000000..7e3bfa15 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/testng.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/windows/enrollment/additional_device_info.xml b/modules/integration/tests-integration/src/test/resources/windows/enrollment/additional_device_info.xml new file mode 100644 index 00000000..fcc381d2 Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/windows/enrollment/additional_device_info.xml differ diff --git a/modules/integration/tests-integration/src/test/resources/windows/enrollment/discovery-post.xml b/modules/integration/tests-integration/src/test/resources/windows/enrollment/discovery-post.xml new file mode 100644 index 00000000..175bd7f9 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/windows/enrollment/discovery-post.xml @@ -0,0 +1,42 @@ + + + + + + http://schemas.microsoft.com/windows/management/2012/01/enrollment/IDiscoveryService/Discover + + urn:uuid:748132ec-a575-4329-b01b-6171a9cf8478 + + http://www.w3.org/2005/08/addressing/anonymous + + + https://EnterpriseEnrollment.wso2.com:443/EnrollmentServer/Discovery.svc + + + + + + admin@wso2.com + 2.0 + WindowsPhone + + + + \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/windows/enrollment/inital_device_info.xml b/modules/integration/tests-integration/src/test/resources/windows/enrollment/inital_device_info.xml new file mode 100644 index 00000000..7dab635c Binary files /dev/null and b/modules/integration/tests-integration/src/test/resources/windows/enrollment/inital_device_info.xml differ diff --git a/modules/integration/tests-integration/src/test/resources/windows/enrollment/ms_xcep.xml b/modules/integration/tests-integration/src/test/resources/windows/enrollment/ms_xcep.xml new file mode 100644 index 00000000..361edb2d --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/windows/enrollment/ms_xcep.xml @@ -0,0 +1,67 @@ + + + + + + http://schemas.microsoft.com/windows/pki/2009/01/enrollmentpolicy/IPolicy/GetPolicies + + + urn:uuid:72048B64-0F19-448F-8C2E-B4C661860AA0 + + + + http://www.w3.org/2005/08/addressing/anonymous + + + + https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/PolicyEnrollmentWebservice.svc + + + + {BinarySecurityToken} + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/windows/enrollment/wstep.xml b/modules/integration/tests-integration/src/test/resources/windows/enrollment/wstep.xml new file mode 100644 index 00000000..14fcec55 --- /dev/null +++ b/modules/integration/tests-integration/src/test/resources/windows/enrollment/wstep.xml @@ -0,0 +1,83 @@ + + + + + + http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RST/wstep + + + urn:uuid:0d5a1441-5891-453b-becf-a2e5f6ea3749 + + + + http://www.w3.org/2005/08/addressing/anonymous + + + + https://EnterpriseEnrollment.wso2.com/ENROLLMENTSERVER/DeviceEnrollmentWebservice.svc + + + + {BinarySecurityToken} + + + + + + + http://schemas.microsoft.com/5.0.0.0/ConfigurationManager/Enrollment/DeviceEnrollmentToken + + + http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue + + + [truncated] + MIICcTCCAV0CAQAwMDEuMCwGA1UEAxMlQjFDNDNDRDAtMTYyNC01RkJCLThFNTQtMzRDRjE3REZEM0ExADCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ1kKlZn4RIoFAWgkeK3ysI3GKWi2epQG6niWNxth4O/YQBLybPaF6TVJWp8U5FSeaN9+NoEi51hPa8vosKMYd94TEEeKykLb08Bpvj + + + + + WindowsPhone + + + + + 8.10.12397.895 + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/pom.xml b/modules/integration/tests-iot-web-ui/pom.xml new file mode 100644 index 00000000..779940fb --- /dev/null +++ b/modules/integration/tests-iot-web-ui/pom.xml @@ -0,0 +1,273 @@ + + + + + org.wso2.iot + wso2iot-integration + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + WSO2 IoT - Integration Test UI Module + org.wso2.carbon.iot.integration.test.web.ui.integration + jar + + + + + maven-surefire-plugin + false + + + -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m + + + src/test/resources/testng-server-mgt.xml + src/test/resources/testng.xml + + + ${skipTests} + + + + maven.test.haltafterfailure + false + + + java.io.tmpdir + ${basedir}/target/ + + + carbon.zip + + ${basedir}/../../distribution/target/wso2iot-${project.version}.zip + + + + framework.resource.location + + ${basedir}/src/test/resources/ + + + + server.list + + IOT + + + + usedefaultlisteners + false + + ${basedir}/target/security-verifier/ + ${basedir}/target/iot + ${basedir}/src/test/resources/instrumentation.txt + ${basedir}/src/test/resources/filters.txt + ${basedir}/target/iot + + ${basedir}/target + + + + maven-dependency-plugin + + + + copy-emma-dependencies + compile + + copy-dependencies + + + ${project.build.directory}/emma + jar + emma + + + + + copy-secVerifier + compile + + copy-dependencies + + + ${basedir}/target/security-verifier + aar + SecVerifier + true + + + + + unpack-mar-jks + compile + + unpack + + + + + org.wso2.iot + wso2iot + ${project.version} + zip + true + ${basedir}/target/tobeCopied/ + **/*.jks,**/*.mar,**/axis2_client.xml + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + + maven-resources-plugin + 2.6 + + + copy-resources-jks + compile + + copy-resources + + + ${basedir}/src/test/resources/keystores/products + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/resources/security/ + + + **/*.jks + + + + + + + copy-stratos-jks + compile + + copy-resources + + + ${basedir}/src/test/resources/keystores/stratos + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/resources/security/ + + + **/*.jks + + + + + + + copy-axis2files + compile + + copy-resources + + + ${basedir}/src/test/resources/axis2config + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/conf/axis2/ + + + **/*.xml + + + + + + + copy-resources-mar + compile + + copy-resources + + + ${basedir}/src/test/resources/client/modules + + + + + ${basedir}/target/tobeCopied/wso2iot-${project.version}/repository/deployment/client/modules + + + **/*.mar + + + + + + + + + + + + + org.wso2.iot + org.wso2.carbon.iot.core.integration.ui.pages + ${product.iot.version} + + + org.wso2.carbon.automation + org.wso2.carbon.automation.engine + + + org.wso2.carbon.automation + org.wso2.carbon.automation.test.utils + + + org.wso2.carbon.automationutils + org.wso2.carbon.integration.common.extensions + + + + + true + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/Constants.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/Constants.java new file mode 100644 index 00000000..4942663c --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/Constants.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.common; + +public class Constants { + public static final String IOT_LOGIN_PATH = "/devicemgt/login"; + 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 IOT_HOME_URL = "/devicemgt/"; + public static final String IOT_ENROLL_CONNECTED_CUP = "/device/connectedcup/enroll"; + public static final String IOT_DEVICES_URL = "/devicemgt/devices"; + public static final String IOT_CONNECTED_CUP_NAME = "testDevice"; + + public static final String GROUP_NAME_FIELD_ERROR = "Group Name is a required field. It cannot be empty."; + public static final String GROUP_NAME = "group1"; + public static final String GROUP_DESCRIPTION = "This is a test group"; + + public static final String ALERT_NOT_PRESENT = "Alert is not present."; + + public static final String CARBON_HOME = "carbon.home"; + + public static final String OS_NAME = "os.name"; + public static final String BUILD_SUCCESS_MSG = "BUILD SUCCESS"; + + public static final int IOT_RESTART_THREAD_TIMEOUT = 30; + + public static final String IOT_GRAPH_X_AXIS = "x"; + public static final String IOT_GRAPH_Y_AXIS = "y"; + + public static class ConnectedCup { + + public static final String COFFEE_LEVEl = "35"; + + public static final String TEMPERATURE = "53"; + public static final String COFFEE_LEVEL_ID = "Coffee Level"; + + public static final String COFFEE_LEVEL_LEGEND = "Coffee Level"; + public static final String COFFEE_LEVEL_GRAPH_ID = "coffeelevel"; + public static final String COFFEE_LEVEL_Y_AXIS = "Coffeelevel"; + public static final String COFFEE_LEVEL_X_AXIS = "time"; + public static final String TEMPERATURE_ID = "Temperature"; + + public static final String TEMPERATURE_LEGEND = "Temperature"; + public static final String TEMPERATURE_GRAPH_ID = "temperature"; + public static final String TEMPERATURE_Y_AXIS = "Temperature"; + public static final String TEMPERATURE_X_AXIS = "time"; + + } + + public static class User { + + public static class Login { + + public static final String USER_NAME_ERROR = "Please enter a username"; + public static final String PASSWORD_ERROR = "Please provide a password"; + public static final String FAILED_ERROR = "LOGIN\n" + + "Login failed! Please recheck the username and password and try again.!\n" + "Username *\n" + + "Password *\n" + "LOGIN\n" + "Create an account"; + public static final String SHORT_PASSWORD_ERROR = "Your password must be at least 3 characters long"; + public static final String WRONG_USER_NAME = "admnnn"; + public static final String WRONG_USER_PASSWORD = "admmmm"; + public static final String SHORT_PASSWORD = "ad"; + public static final String PAGE_TITLE = "Login | CDMF"; + + } + + public static class Add { + + public static final String FIRST_NAME = "User"; + public static final String LAST_NAME = "User"; + public static final String EMAIL = "user@wso2.com"; + public static final String EMAIL_ERROR = "user.com"; + public static final String USER_NAME = "user"; + public static final String SHORT_USER_NAME = "us"; + public static final String SHORT_USER_NAME_ERROR_MSG = "Provided username is invalid."; + public static final String FIRST_NAME_ERROR_MSG = "Firstname is a required field. It cannot be empty."; + public static final String LAST_NAME_ERROR_MSG = "Lastname is a required field. It cannot be empty."; + public static final String NO_EMAIL_ERROR_MSG = "Email is a required field. It cannot be empty."; + public static final String WRONG_EMAIL_ERROR_MSG = "Provided email is invalid."; + + } + + public static class Register { + + public static final String FIRST_NAME = "Firstname"; + public static final String LAST_NAME = "Lastname"; + public static final String USER_NAME = "testUser"; + public static final String PASSWORD = "testPassword"; + public static final String CONFIRM_PASSWORD = "testPassword"; + public static final String EMAIL = "userName@wso2.com"; + + } + + } + + public static class TestSample { + + public static final String SAMPLE_INSTALL = "iot.sample"; + public static final String INSTALL_VERIFY = "iot.sample.install"; + public static final String VERIFY = "iot.sample.install.verify"; + public static final String ENROLL = "iot.sample.enroll"; + public static final String ENROLL_VERIFY = "iot.sample.enroll.verify"; + public static final String TEMPERATURE = "iot.sample.temp"; + public static final String COFFEE_LEVEL = "iot.sample.level"; + + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/IOTIntegrationUIBaseTestCase.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/IOTIntegrationUIBaseTestCase.java new file mode 100644 index 00000000..f0de6e10 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/IOTIntegrationUIBaseTestCase.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.common; + +import org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.common.HomePageGenerator; +import org.wso2.carbon.integration.common.admin.client.AuthenticatorClient; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; +import java.rmi.RemoteException; + + +public class IOTIntegrationUIBaseTestCase { + + protected AutomationContext automationContext; + + protected void init() throws IOException, XMLStreamException, XPathExpressionException { + automationContext = new AutomationContext("IOT", "iot001", TestUserMode.SUPER_TENANT_ADMIN); + } + + protected String getBackendURL() throws XPathExpressionException { + return automationContext.getContextUrls().getBackEndUrl(); + } + + protected String getWebAppURL() throws XPathExpressionException { + return automationContext.getContextUrls().getWebAppURL(); + } + + protected String getSessionCookie(AutomationContext context) + throws RemoteException, XPathExpressionException, LoginAuthenticationExceptionException { + AuthenticatorClient authenticationAdminClient = new AuthenticatorClient(context.getContextUrls().getBackEndUrl()); + return authenticationAdminClient.login(automationContext.getSuperTenant(). + getTenantAdmin().getUserName(), automationContext.getSuperTenant(). + getTenantAdmin().getPassword(), + automationContext.getDefaultInstance().getHosts().get("default")); + } + + protected String getServiceURL() throws XPathExpressionException { + String serviceURL = automationContext.getContextUrls().getServiceUrl(); + return automationContext.getContextUrls().getServiceUrl(); + } + + protected String getLoginURL() throws XPathExpressionException { + return HomePageGenerator.getProductHomeURL(automationContext); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/LoginUtils.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/LoginUtils.java new file mode 100644 index 00000000..118e3db8 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/common/LoginUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.common; + +import org.openqa.selenium.WebDriver; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.iot.integration.ui.pages.login.LoginPage; + +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * This class is used to login to the server as the Admin. + */ +public class LoginUtils { + + /** + * This method is used to login as admin. + * + * @param driver The selenium web driver + * @param automationContext Test Automation context + * @param webAppURL The server url + */ + public static void login(WebDriver driver, AutomationContext automationContext, + String webAppURL) throws IOException, XPathExpressionException { + driver.get(webAppURL + Constants.IOT_LOGIN_PATH); + LoginPage test = new LoginPage(driver); + test.loginAsAdmin(automationContext.getSuperTenant().getTenantAdmin().getUserName(), + automationContext.getSuperTenant().getTenantAdmin().getPassword()); + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/error/InitialErrorTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/error/InitialErrorTest.java new file mode 100644 index 00000000..ac7ecda6 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/error/InitialErrorTest.java @@ -0,0 +1,39 @@ +package org.wso2.carbon.iot.integration.web.ui.test.error; + +import junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.error.IOTErrorPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +public class InitialErrorTest extends IOTIntegrationUIBaseTestCase{ + + private WebDriver driver; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH); + } + + @Test(description = "Test for initial login error.") + public void ErrorPageTest() throws IOException { + IOTErrorPage errorPage = new IOTErrorPage(driver); + Assert.assertTrue(errorPage.isErrorPresent()); + } + + @AfterClass(alwaysRun = true) + 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/extension/AnalyticsServerExtension.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/AnalyticsServerExtension.java new file mode 100644 index 00000000..03bdca0e --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/AnalyticsServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.extension; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the DAS. + * This will set the carbon_home to {carbonHome}/core and port offset : 2 + */ +public class AnalyticsServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "2"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("analytics"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/BrokerServerExtension.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/BrokerServerExtension.java new file mode 100644 index 00000000..d9657b41 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/BrokerServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.extension; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the Broker. + * This will set the carbon_home to {carbonHome}/core and port offset : 3 + */ +public class BrokerServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "3"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("broker"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/CustomTestServerManager.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/CustomTestServerManager.java new file mode 100644 index 00000000..fa9c34d8 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/CustomTestServerManager.java @@ -0,0 +1,147 @@ +/* +* Copyright (c) 2005-2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.extension; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.FrameworkConstants; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerManager; + +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class CustomTestServerManager { + protected CarbonServerManager carbonServer; + protected String carbonZip; + protected int portOffset; + protected Map commandMap = new HashMap(); + private static final Log log = LogFactory.getLog(CustomTestServerManager.class); + protected String carbonHome; + + public CustomTestServerManager(AutomationContext context) { + carbonServer = new CarbonServerManager(context); + } + + public CustomTestServerManager(AutomationContext context, String carbonZip) { + carbonServer = new CarbonServerManager(context); + this.carbonZip = carbonZip; + } + + public CustomTestServerManager(AutomationContext context, int portOffset) { + carbonServer = new CarbonServerManager(context); + this.portOffset = portOffset; + commandMap.put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, String.valueOf(portOffset)); + } + + public CustomTestServerManager(AutomationContext context, String carbonZip, + Map commandMap) { + carbonServer = new CarbonServerManager(context); + this.carbonZip = carbonZip; + if (commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) != null) { + this.portOffset = Integer.parseInt(commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND)); + } else { + throw new IllegalArgumentException("portOffset value must be set in command list"); + } + this.commandMap = commandMap; + } + + public String getCarbonZip() { + return carbonZip; + } + + public String getCarbonHome() { + return carbonHome; + } + + public int getPortOffset() { + return portOffset; + } + + public void configureServer() throws AutomationFrameworkException { + + } + + + public Map getCommands() { + return commandMap; + } + + /** + * This method is called for starting a Carbon server in preparation for execution of a + * TestSuite + *

+ * Add the @BeforeSuite TestNG annotation in the method overriding this method + * @param server : The server which needs to be start. + * @return The CARBON_HOME + * @throws java.io.IOException If an error occurs while copying the deployment artifacts into the + * Carbon server + */ + public String startServer(String server) + throws AutomationFrameworkException, IOException, XPathExpressionException { + if(carbonHome == null) { + if (carbonZip == null) { + carbonZip = System.getProperty(FrameworkConstants.SYSTEM_PROPERTY_CARBON_ZIP_LOCATION); + } + if (carbonZip == null) { + throw new IllegalArgumentException("carbon zip file cannot find in the given location"); + } + carbonHome = carbonServer.setUpCarbonHome(carbonZip) + "/" + server; + configureServer(); + } + log.info("Carbon Home - " + carbonHome ); + if (commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) != null) { + this.portOffset = Integer.parseInt(commandMap.get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND)); + } else { + this.portOffset = 0; + } + carbonServer.startServerUsingCarbonHome(carbonHome, commandMap); + return carbonHome; + } + + /** + * Restarting server already started by the method startServer + * @throws AutomationFrameworkException + */ + public void restartGracefully() throws AutomationFrameworkException { + if(carbonHome == null) { + throw new AutomationFrameworkException("No Running Server found to restart. " + + "Please make sure whether server is started"); + } + carbonServer.restartGracefully(); + } + + /** + * This method is called for stopping a Carbon server + *

+ * Add the @AfterSuite annotation in the method overriding this method + * + * @throws AutomationFrameworkException If an error occurs while shutting down the server + */ + public void stopServer() throws AutomationFrameworkException { + carbonServer.serverShutdown(portOffset); + } + + + + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/IOTServerExtension.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/IOTServerExtension.java new file mode 100644 index 00000000..c7992a47 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/extension/IOTServerExtension.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.extension; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.context.AutomationContext; +import org.wso2.carbon.automation.engine.context.ContextXpathConstants; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension; +import org.wso2.carbon.automation.extensions.ExtensionConstants; +import org.wso2.carbon.automation.extensions.servers.carbonserver.CarbonServerExtension; + +import javax.xml.xpath.XPathExpressionException; + +/** + * Test Automation server extension to start the IOT core. + * This will set the carbon_home to {carbonHome}/core and port offset : 0 + */ +public class IOTServerExtension extends ExecutionListenerExtension { + + private CustomTestServerManager serverManager; + private static final Log log = LogFactory.getLog(CarbonServerExtension.class); + private String executionEnvironment; + private AutomationContext automationContext; + + + @Override + public void initiate() throws AutomationFrameworkException { + try { + automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER); + if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) { + getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "0"); + } + serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters()); + executionEnvironment = + automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT); + + } catch (XPathExpressionException e) { + handleException("Error while initiating test environment", e); + } + } + + @Override + public void onExecutionStart() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + String carbonHome = serverManager.startServer("core"); + log.info(carbonHome); + System.setProperty(ExtensionConstants.CARBON_HOME, carbonHome); + } + } catch (Exception e) { + handleException("Fail to start carbon server ", e); + } + } + + @Override + public void onExecutionFinish() throws AutomationFrameworkException { + try { + if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { + serverManager.stopServer(); + } + } catch (Exception e) { + handleException("Fail to stop carbon server ", e); + } + } + + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new RuntimeException(msg, e); + } +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupFailTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupFailTest.java new file mode 100644 index 00000000..57f899b6 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupFailTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.group; + +import org.junit.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage; + +/** + * 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; + + @BeforeClass(alwaysRun = true) + public void setup() throws Exception { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + } + + @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); + + Assert.assertEquals(addGroupPage.submitEmptyForm(), Constants.GROUP_NAME_FIELD_ERROR); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java new file mode 100644 index 00000000..d3e52f21 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/group/DeviceGroupTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.group; + +import org.openqa.selenium.WebDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.groups.DeviceAddGroupPage; +import org.wso2.iot.integration.ui.pages.groups.DeviceGroupsPage; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; + +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test cases for grouping feature of IOT server. + */ +public class DeviceGroupTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + private IOTAdminDashboard adminDashboard; + + @BeforeClass(alwaysRun = true) + public void setup() throws Exception { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + adminDashboard = new IOTAdminDashboard(driver); + } + + @Test(description = "Test for adding a new device group.") + public void addNewGroupTest() throws IOException { + DeviceAddGroupPage addGroupPage = adminDashboard.addGroup(); + addGroupPage.addNewGroup(Constants.GROUP_NAME, Constants.GROUP_DESCRIPTION); + } + + @Test(description = "Check whether the created group exists", dependsOnMethods = {"addNewGroupTest"}) + public void isGroupCreatedTest() throws IOException, XPathExpressionException { + driver.get(getWebAppURL() + Constants.IOT_HOME_URL); + DeviceGroupsPage groupsPage = adminDashboard.viewGroups(); + Assert.assertTrue(groupsPage.isGroupCreated(Constants.GROUP_NAME)); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginFormValidationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginFormValidationTest.java new file mode 100644 index 00000000..9b478a8c --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginFormValidationTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.login; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + + +/** + * Test cases to test the incorrect login from submissions. + * Ex: + * 1. Empty form + * 2. Incorrect username or password + * 3. short password + */ +public class LoginFormValidationTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + + WebElement userNameField; + WebElement passwordField; + WebElement loginButton; + + @BeforeClass(alwaysRun = true) + public void setup() throws Exception { + super.init(); + driver = BrowserManager.getWebDriver(); + clearForm(); + } + + @Test(description = "Test for incorrect username") + public void incorrectUserNameTest() throws Exception { + clearForm(); + userNameField.sendKeys(Constants.User.Login.WRONG_USER_NAME); + passwordField.sendKeys(automationContext.getSuperTenant().getTenantAdmin().getPassword()); + loginButton.click(); + + WebElement alert = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath"))); + if (alert.isDisplayed()) { + Assert.assertEquals(alert.getText(), Constants.User.Login.FAILED_ERROR); + } else { + Assert.assertTrue(false, Constants.ALERT_NOT_PRESENT); + } + + } + + @Test(description = "Test for incorrect password") + public void incorrectPasswordTest() throws Exception { + clearForm(); + userNameField.sendKeys(automationContext.getSuperTenant().getTenantAdmin().getPassword()); + passwordField.sendKeys(Constants.User.Login.WRONG_USER_PASSWORD); + loginButton.click(); + + WebElement alert = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath"))); + if (alert.isDisplayed()) { + Assert.assertEquals(alert.getText(), Constants.User.Login.FAILED_ERROR); + } else { + Assert.assertTrue(false, Constants.ALERT_NOT_PRESENT); + } + } + + public void clearForm() throws Exception { + driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH); + uiElementMapper = UIElementMapper.getInstance(); + + userNameField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.login.input.username.xpath"))); + passwordField = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.login.input.password.xpath"))); + loginButton = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.user.login.button.xpath"))); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java new file mode 100644 index 00000000..ba219038 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/login/LoginTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.login; + +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import org.wso2.iot.integration.ui.pages.login.LoginPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test Login as Admin + */ +public class LoginTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH); + } + + @Test(description = "Verify logins to IOT server dashboard") + public void testAdminLogin() throws IOException, XPathExpressionException { + LoginPage loginPage = new LoginPage(driver); + IOTAdminDashboard dashboard = loginPage.loginAsAdmin( + automationContext.getSuperTenant().getTenantAdmin().getUserName(), + automationContext.getSuperTenant().getTenantAdmin().getPassword()); + dashboard.logout(); + } + + @AfterClass(alwaysRun = true) + 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/samples/SampleEnrollmentTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java new file mode 100644 index 00000000..c906eb26 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrollmentTest.java @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.samples; + +import junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.devices.EnrollDevicePage; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceTypeViewPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test cases to verify the enrolment process. + */ +public class SampleEnrollmentTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + private ConnectedCupDeviceTypeViewPage connectedCupDeviceTypeViewPage; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver); + EnrollDevicePage enrollDevicePage = adminDashboard.enrollNewDevice(); + connectedCupDeviceTypeViewPage = enrollDevicePage.gotoConnectedCupDeviceTypeViewPage(); + } + + @Test(description = "Verify the pop up modal is displayed.", + groups = Constants.TestSample.ENROLL, + dependsOnGroups = Constants.TestSample.INSTALL_VERIFY) + public void enrollDevicePopUpModalTest() throws InterruptedException, IOException { + Assert.assertTrue(connectedCupDeviceTypeViewPage.isPopUpPresent()); + } + + @Test(description = "Test case for device enrolment", + groups = Constants.TestSample.ENROLL, + dependsOnMethods = {"enrollDevicePopUpModalTest"}) + public void enrollDeviceTest() throws InterruptedException { + Assert.assertTrue(connectedCupDeviceTypeViewPage.enrollDevice(Constants.IOT_CONNECTED_CUP_NAME)); + } + + @AfterClass(alwaysRun = true) + 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/samples/SampleEnrolmentVerificationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrolmentVerificationTest.java new file mode 100644 index 00000000..1dc592bc --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleEnrolmentVerificationTest.java @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.samples; + +import junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.devices.DevicesPage; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceViewPage; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceInterface; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test cases to check whether the sample is enrolled correctly. + */ +public class SampleEnrolmentVerificationTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver webDriver; + private DevicesPage devicesPage; + private ConnectedCupDeviceViewPage connectedCupDeviceViewPage; + + @BeforeClass(alwaysRun = true) + public void setUp() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + webDriver = BrowserManager.getWebDriver(); + LoginUtils.login(webDriver, automationContext, getWebAppURL()); + webDriver.get(getWebAppURL() + Constants.IOT_DEVICES_URL); + devicesPage = new DevicesPage(webDriver); + } + + @Test(description = "Verify enrolment of the sample device", + groups = Constants.TestSample.ENROLL_VERIFY, + dependsOnGroups = Constants.TestSample.ENROLL) + public void verifyEnrollmentTest() { + Assert.assertTrue(devicesPage.isDeviceEnrolled(Constants.IOT_CONNECTED_CUP_NAME)); + } + + @Test(description = "Verify navigation to device view", + dependsOnMethods = "verifyEnrollmentTest", + groups = Constants.TestSample.ENROLL_VERIFY) + public void verifyNavigationTest() throws IOException { + connectedCupDeviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME); + Assert.assertNotNull(connectedCupDeviceViewPage); + } + + @Test(description = "Verify sample functions", + dependsOnMethods = {"verifyNavigationTest"}) + public void sampleStartUpTest() throws IOException { + ConnectedCupDeviceInterface sampleViewPage = connectedCupDeviceViewPage.gotoDevice(); + Assert.assertNotNull(sampleViewPage); + } + + @AfterClass(alwaysRun = true) + public void tearDown() { + webDriver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleFunctionalityTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleFunctionalityTest.java new file mode 100644 index 00000000..d8bde532 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleFunctionalityTest.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.samples; + +import junit.framework.Assert; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.devices.DevicesPage; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceViewPage; +import org.wso2.iot.integration.ui.pages.samples.ConnectedCupDeviceInterface; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test cases for test the functionality of the connected cup sample. + * In these test cases following features are tested. + * 1. Setting temperature and Coffee level + * 2. Order coffee + * 3. Test the stat graphs + */ +public class SampleFunctionalityTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driverDevice; + private WebDriver driverServer; + private ConnectedCupDeviceInterface sampleViewPage; + private ConnectedCupDeviceViewPage deviceViewPage; + + @BeforeClass(alwaysRun = true) + public void setUp() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driverDevice = BrowserManager.getWebDriver(); + driverServer = BrowserManager.getWebDriver(); + LoginUtils.login(driverServer, automationContext, getWebAppURL()); + driverServer.get(getWebAppURL() + Constants.IOT_DEVICES_URL); + DevicesPage devicesPage = new DevicesPage(driverServer); + deviceViewPage = devicesPage.viewDevice(Constants.IOT_CONNECTED_CUP_NAME); + + //Opens the connected cup device interface in the browser. + driverDevice.get(deviceViewPage.getDeviceLink()); + sampleViewPage = new ConnectedCupDeviceInterface(driverDevice); + } + + @Test(description = "Set the temperature level.", + groups = Constants.TestSample.VERIFY, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY) + public void setTemperatureTest() { + Assert.assertTrue(sampleViewPage.changeTemperature(Constants.ConnectedCup.TEMPERATURE)); + } + + @Test(description = "Set the coffee level.", + groups = Constants.TestSample.VERIFY, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY) + public void setCoffeeLevelTest() throws IOException { + Assert.assertTrue(sampleViewPage.changeCoffeeLevel(Constants.ConnectedCup.COFFEE_LEVEl)); + } + + @Test(description = "Verify order coffee function.", + groups = Constants.TestSample.VERIFY, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY) + public void orderCoffeeTest() throws IOException, InterruptedException { + Assert.assertTrue(sampleViewPage.orderCoffee()); + } + + @Test(description = "Test the graphs are present in device view.", + groups = Constants.TestSample.VERIFY, + dependsOnMethods = {"setTemperatureTest", "setCoffeeLevelTest", "orderCoffeeTest"}) + public void verifyGraphs() throws IOException { + Assert.assertTrue(deviceViewPage.isGraphsAvailable(2)); + } + + @Test(description = "Test the Y axis name of Temperature graph.", + groups = {Constants.TestSample.VERIFY, + Constants.TestSample.TEMPERATURE}, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY, + dependsOnMethods = {"verifyGraphs"}) + public void temperatureGraphYAxisNameTest() throws IOException { + Assert.assertTrue(deviceViewPage.graphAxisName(Constants.IOT_GRAPH_Y_AXIS, + Constants.ConnectedCup.TEMPERATURE_ID, + Constants.ConnectedCup.TEMPERATURE_Y_AXIS)); + } + + @Test(description = "Test the X axis name of Temperature graph.", + groups = {Constants.TestSample.VERIFY, + Constants.TestSample.TEMPERATURE}, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY, + dependsOnMethods = {"verifyGraphs"}) + public void temperatureGraphXAxisNameTest() throws IOException { + Assert.assertTrue(deviceViewPage.graphAxisName(Constants.IOT_GRAPH_X_AXIS, + Constants.ConnectedCup.TEMPERATURE_ID, + Constants.ConnectedCup.TEMPERATURE_X_AXIS)); + } + + @Test(description = "Test the whether the Coffee Level graph legend is present.", + groups = {Constants.TestSample.VERIFY, + Constants.TestSample.TEMPERATURE}, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY, + dependsOnMethods = {"verifyGraphs"}) + public void temperatureGraphLegendTest() { + Assert.assertTrue(deviceViewPage.graphLegendName(Constants.ConnectedCup.TEMPERATURE_ID, + Constants.ConnectedCup.TEMPERATURE_LEGEND)); + } + + @Test(description = "Test the whether the Temperature graph path is visible.", + groups = {Constants.TestSample.VERIFY, + Constants.TestSample.TEMPERATURE}, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY, + dependsOnMethods = {"verifyGraphs"}) + public void temperatureGraphPathTest() { + Assert.assertTrue(deviceViewPage.checkGraphPath(Constants.ConnectedCup.TEMPERATURE_GRAPH_ID)); + } + + @Test(description = "Test the whether the Temperature graph gets values.", + groups = {Constants.TestSample.VERIFY, + Constants.TestSample.TEMPERATURE}, + dependsOnGroups = Constants.TestSample.ENROLL_VERIFY, + dependsOnMethods = {"verifyGraphs"}) + public void temperatureGraphDataPublisherTest() { + Assert.assertTrue(deviceViewPage.checkGraphValues(Constants.ConnectedCup.TEMPERATURE_GRAPH_ID, + Constants.ConnectedCup.TEMPERATURE)); + } + + @Test(description = "Test the Y axis name of Coffee Level graph.", + groups = Constants.TestSample.COFFEE_LEVEL, + dependsOnGroups = Constants.TestSample.TEMPERATURE) + public void coffeeLevelGraphYAxisNameTest() { + Assert.assertTrue(deviceViewPage.graphAxisName(Constants.IOT_GRAPH_Y_AXIS, + Constants.ConnectedCup .COFFEE_LEVEL_ID, + Constants.ConnectedCup.COFFEE_LEVEL_Y_AXIS)); + } + + @Test(description = "Test the X axis name of Coffee Level graph.", + groups = Constants.TestSample.COFFEE_LEVEL, + dependsOnGroups = {Constants.TestSample.ENROLL_VERIFY, + Constants.TestSample.TEMPERATURE}) + public void coffeeLevelGraphXAxisNameTest() { + Assert.assertTrue(deviceViewPage.graphAxisName(Constants.IOT_GRAPH_X_AXIS, + Constants.ConnectedCup.COFFEE_LEVEL_ID, + Constants.ConnectedCup.COFFEE_LEVEL_X_AXIS)); + } + + @Test(description = "Test the whether the Coffee Level graph legend is present.", + groups = Constants.TestSample.COFFEE_LEVEL, + dependsOnGroups = {Constants.TestSample.TEMPERATURE}) + public void coffeeLevelGraphLegendTest() throws IOException { + Assert.assertTrue(deviceViewPage.graphLegendName(Constants.ConnectedCup.COFFEE_LEVEL_ID, + Constants.ConnectedCup.COFFEE_LEVEL_LEGEND)); + } + + @Test(description = "Test the whether the Coffee Level graph path is visible.", + groups = Constants.TestSample.COFFEE_LEVEL, + dependsOnGroups = {Constants.TestSample.TEMPERATURE}) + public void coffeeLevelGraphPathTest() { + Assert.assertTrue(deviceViewPage.checkGraphPath(Constants.ConnectedCup.COFFEE_LEVEL_GRAPH_ID)); + } + + @Test(description = "Test the whether the Coffee Level graph gets values.", + groups = Constants.TestSample.COFFEE_LEVEL, + dependsOnGroups = Constants.TestSample.TEMPERATURE) + public void coffeeLevelGraphDataPublisherTest() { + Assert.assertTrue(deviceViewPage.checkGraphValues(Constants.ConnectedCup.COFFEE_LEVEL_GRAPH_ID, + Constants.ConnectedCup.COFFEE_LEVEl)); + } + + @AfterClass(alwaysRun = true) + public void tearDown() { + driverServer.quit(); + driverDevice.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java new file mode 100644 index 00000000..1368e0b1 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationTest.java @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.samples; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException; +import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException; +import org.wso2.carbon.integration.common.admin.client.LogViewerClient; +import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; +import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException; +import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.rmi.RemoteException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * Test cases for building and installation of sample device types. + * When installing a custom device type to the IOT server, developer has to create the device type as a feature and + * put it in to the samples folder. + * Then build the device type created with maven. + * After that install the device type by running the device-deployer.xml. + * Then the server has to be restarted, in order to activate newly installed device type. + *

+ * In this test case, the build process of a new device type and installation to the server is tested. + */ +public class SampleInstallationTest extends IOTIntegrationUIBaseTestCase { + private Log log = LogFactory.getLog(SampleInstallationTest.class); + private Process tempProcess = null; + private Properties properties = System.getProperties(); + private String carbonHome = properties.getProperty(Constants.CARBON_HOME); + private String[] commands; + private LogViewerClient logViewerClient; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException, AutomationFrameworkException, + LoginAuthenticationExceptionException { + super.init(); + logViewerClient = new LogViewerClient(getBackendURL(), getSessionCookie(automationContext)); + } + + @Test(description = "Verify the sample build process", + groups = Constants.TestSample.SAMPLE_INSTALL) + public void sampleBuildTest() throws IOException { + String connectedCupDir = carbonHome + File.separator + "samples" + File.separator + "connectedcup"; + log.info("Connected cup Sample: " + connectedCupDir); + File dir = new File(connectedCupDir); + try { + if (System.getProperty(Constants.OS_NAME).toLowerCase().contains("windows")) { + log.info("Executing maven clean install --------------------------------"); + commands = new String[]{"cmd.exe", "/c", "mvn clean install"}; + tempProcess = Runtime.getRuntime().exec(commands, null, dir); + } else { + log.info("Executing maven clean install --------------------------------"); + commands = new String[]{"mvn", "clean", "install"}; + tempProcess = Runtime.getRuntime().exec(commands, null, dir); + } + + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), Constants.BUILD_SUCCESS_MSG); + Assert.assertTrue(buildStatus, "Building the sample was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Verify the sample installation process", + groups = Constants.TestSample.SAMPLE_INSTALL, + dependsOnMethods = {"sampleBuildTest"}) + public void sampleInstallationTest() throws IOException { + + log.info("CARBON_HOME: " + System.getProperty(Constants.CARBON_HOME)); + File dir = new File(carbonHome); + log.info("Sample installation started : mvn clean install -f device-deployer.xml"); + try { + if (System.getProperty(Constants.OS_NAME).toLowerCase().contains("windows")) { + commands = new String[]{"cmd.exe", "/c", "mvn clean install -f device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(commands, null, dir); + } else { + commands = new String[]{"mvn", "clean", "install", "-f", "device-deployer.xml"}; + tempProcess = Runtime.getRuntime().exec(commands, null, dir); + } + boolean buildStatus = waitForMessage(tempProcess.getInputStream(), Constants.BUILD_SUCCESS_MSG); + Assert.assertTrue(buildStatus, "Sample installation was not successful"); + } finally { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + } + + @Test(description = "Test restarting the server", + groups = Constants.TestSample.SAMPLE_INSTALL, + dependsOnMethods = {"sampleInstallationTest"}) + public void serverRestartTest() { + ServerConfigurationManager serverManager; + try { + serverManager = new ServerConfigurationManager(automationContext); + log.info("Restart Triggered -------------------------------------------------------------------"); + serverManager.restartGracefully(); + logViewerClient.getAllRemoteSystemLogs(); + waitForRestart(); + } catch (AutomationUtilException | XPathExpressionException | MalformedURLException e) { + log.error("Restart failed due to : " + e.getLocalizedMessage()); + } catch (RemoteException | LogViewerLogViewerException e) { + log.error("Cannot get server log due to : " + e.getLocalizedMessage()); + } + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + if (tempProcess != null) { + tempProcess.destroy(); + } + } + + /** + * Wait for a given message to be printed in terminal. Used for processes. + * @param inputStream : Input stream of the process + * @param message : The message which is to be look for + */ + private 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; + } + + /** + * Wait until the server restarts. + * This method looks for "Mgt console URL:" to be appeared in the terminal. + * If it does not appear within the given timeout an Exception will be thrown. + */ + private void waitForRestart() { + ExecutorService service = Executors.newSingleThreadExecutor(); + try { + Runnable r = new Runnable() { + @Override + public void run() { + try { + LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs(); + for (LogEvent event : logEvents) { + log.info(event.getMessage() + " @ " + event.getLogTime()); + if (event.getMessage().contains("Mgt Console URL : " )){ + log.info("Server restarted successfully"); + Assert.assertTrue(true); + } + } + } catch (RemoteException | LogViewerLogViewerException e) { + log.error("Error reading logs. \n" + e.getMessage()); + Assert.assertTrue(false); + } + } + }; + + Future f = service.submit(r); + + f.get(Constants.IOT_RESTART_THREAD_TIMEOUT, TimeUnit.MINUTES); + } catch (final InterruptedException e) { + log.error("Interrupted "+e.getMessage()); + Assert.assertTrue(false); + } catch (final TimeoutException e) { + log.error("Timeout " + e.getMessage()); + Assert.assertTrue(false); + } catch (final ExecutionException e) { + log.error("Execution failed " + e.getMessage()); + Assert.assertTrue(false); + } finally { + service.shutdown(); + } + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java new file mode 100644 index 00000000..6c9d54c6 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/samples/SampleInstallationVerification.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.samples; + +import org.openqa.selenium.WebDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.devices.EnrollDevicePage; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test cases to verify the sample installation is successful and device type is installed correctly. + */ +public class SampleInstallationVerification extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + private IOTAdminDashboard adminDashboard; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + adminDashboard = new IOTAdminDashboard(driver); + } + + @Test(description = "Verify the sample is available in Virtual devices section.", + groups = Constants.TestSample.INSTALL_VERIFY, + dependsOnGroups = Constants.TestSample.SAMPLE_INSTALL) + public void installationVerificationTest() throws IOException { + EnrollDevicePage enrollDevicePage = adminDashboard.enrollNewDevice(); + Assert.assertTrue(enrollDevicePage.isInstalled()); + } + + @AfterClass(alwaysRun = true) + 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/AddUserFormValidationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java new file mode 100644 index 00000000..44175b14 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AddUserFormValidationTest.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.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.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.UIElementMapper; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Class contains test cases for Add user form validation. + * 1. Empty form submission + * 2. Short user name + * 3. Empty First Name + * 4. Empty Last Name + * 5. Empty email + * 6. Incorrect email + */ +public class AddUserFormValidationTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + private UIElementMapper uiElementMapper; + 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 { + super.init(); + 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"))); + firstNameField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.firstName.id"))); + lastNameField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.lastName.id"))); + emailField = driver.findElement(By.id(uiElementMapper.getElement("iot.admin.addUser.email.id"))); + + addUserButton = driver.findElement(By.xpath(uiElementMapper.getElement("iot.admin.addUser.add.btn.xpath"))); + } + + @Test(description = "Test for empty form submission") + public void emptyFormTest() { + clearForm(); + + firstNameField.sendKeys(""); + lastNameField.sendKeys(""); + emailField.sendKeys(""); + userNameField.sendKeys(""); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for empty form not is displayed."); + } + + Assert.assertEquals(alert.getText(), "Username is a required field. It cannot be empty."); + } + + @Test(description = "Test for short user name") + public void shortUserNameTest() { + clearForm(); + + firstNameField.sendKeys(Constants.User.Add.FIRST_NAME); + lastNameField.sendKeys(Constants.User.Add.LAST_NAME); + emailField.sendKeys(Constants.User.Add.EMAIL); + userNameField.sendKeys(Constants.User.Add.SHORT_USER_NAME); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for short user name is not displayed."); + } + + Assert.assertEquals(alert.getText(), Constants.User.Add.SHORT_USER_NAME_ERROR_MSG); + } + + @Test(description = "Test for empty first name") + public void emptyFirstNameTest() { + clearForm(); + + firstNameField.sendKeys(""); + lastNameField.sendKeys(Constants.User.Add.LAST_NAME); + emailField.sendKeys(Constants.User.Add.EMAIL); + userNameField.sendKeys(Constants.User.Add.USER_NAME); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for First name is not displayed."); + } + + Assert.assertEquals(alert.getText(), Constants.User.Add.FIRST_NAME_ERROR_MSG); + } + + @Test(description = "Test for empty last name") + public void emptyLastNameTest() { + clearForm(); + + firstNameField.sendKeys(Constants.User.Add.FIRST_NAME); + lastNameField.sendKeys(""); + emailField.sendKeys(Constants.User.Add.EMAIL); + userNameField.sendKeys(Constants.User.Add.USER_NAME); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for Last name is not displayed."); + } + + Assert.assertEquals(alert.getText(), Constants.User.Add.LAST_NAME_ERROR_MSG); + } + + @Test(description = "Test for empty email name") + public void emptyEmailTest() { + clearForm(); + + firstNameField.sendKeys(Constants.User.Add.FIRST_NAME); + lastNameField.sendKeys(Constants.User.Add.LAST_NAME); + emailField.sendKeys(""); + userNameField.sendKeys(Constants.User.Add.USER_NAME); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for E-mail is not displayed."); + } + + Assert.assertEquals(alert.getText(), Constants.User.Add.NO_EMAIL_ERROR_MSG); + } + + @Test(description = "Test for incorrect email") + public void incorrectEmailTest() { + clearForm(); + + firstNameField.sendKeys(Constants.User.Add.FIRST_NAME); + lastNameField.sendKeys(Constants.User.Add.LAST_NAME); + emailField.sendKeys(Constants.User.Add.EMAIL_ERROR); + userNameField.sendKeys(Constants.User.Add.USER_NAME); + + addUserButton.click(); + + WebElement alert = driver.findElement(By.xpath( + uiElementMapper.getElement("iot.admin.addUser.formError.xpath"))); + + if (!alert.isDisplayed()) { + Assert.assertTrue(false, "Alert for incorrect E-mail is not displayed."); + } + + Assert.assertEquals(alert.getText(), Constants.User.Add.WRONG_EMAIL_ERROR_MSG); + } + + private void clearForm() { + firstNameField.clear(); + lastNameField.clear(); + emailField.clear(); + userNameField.clear(); + } + + @AfterClass(alwaysRun = true) + 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/AdminFunctionsTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AdminFunctionsTest.java new file mode 100644 index 00000000..e25740e9 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/AdminFunctionsTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.user; + +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.LoginUtils; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.home.IOTAdminDashboard; +import org.wso2.iot.integration.ui.pages.uesr.AddUserPage; +import org.wso2.iot.integration.ui.pages.uesr.UserListingPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test for check following admin capabilities. + * - Create a new User + * - Delete a user + */ +public class AdminFunctionsTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + + @BeforeClass(alwaysRun = true) + public void setup() throws IOException, XPathExpressionException, XMLStreamException { + super.init(); + driver = BrowserManager.getWebDriver(); + LoginUtils.login(driver, automationContext, getWebAppURL()); + } + + @Test(description = "Test for creating a new user") + public void createUserTest() throws IOException { + IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver); + AddUserPage addUserPage = adminDashboard.addUser(); + addUserPage.createNewUser("user1", "User", "User", "user@wso2.com"); + } + + @Test(description = "Test for deleting a created user", dependsOnMethods = {"createUserTest"}) + public void deleteUserTest() throws XPathExpressionException, IOException, InterruptedException { + driver.get(getWebAppURL() + Constants.IOT_HOME_URL); + IOTAdminDashboard adminDashboard = new IOTAdminDashboard(driver); + UserListingPage userListingPage = adminDashboard.viewUser(); + userListingPage.deleteUser(); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java new file mode 100644 index 00000000..3d66675f --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/NewUserRegistrationTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.wso2.carbon.iot.integration.web.ui.test.user; + +import org.openqa.selenium.WebDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.IOTIntegrationUIBaseTestCase; +import org.wso2.iot.integration.ui.pages.UIElementMapper; +import org.wso2.iot.integration.ui.pages.home.IOTHomePage; +import org.wso2.iot.integration.ui.pages.login.LoginPage; +import org.wso2.iot.integration.ui.pages.uesr.NewUserRegisterPage; + +import javax.xml.stream.XMLStreamException; +import javax.xml.xpath.XPathExpressionException; +import java.io.IOException; + +/** + * Test for registering a new user and login + */ +public class NewUserRegistrationTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + + @BeforeClass(alwaysRun = true) + public void setup() throws XPathExpressionException, XMLStreamException, IOException { + super.init(); + driver = BrowserManager.getWebDriver(); + driver.get(getWebAppURL() + Constants.IOT_LOGIN_PATH); + } + + @Test(description = "Verify new User registration") + public void userRegisterTest() throws IOException { + LoginPage login = new LoginPage(driver); + NewUserRegisterPage registerTest = login.registerNewUser(); + LoginPage loginPage = registerTest.registerUser(Constants.User.Register.FIRST_NAME, + Constants.User.Register.LAST_NAME, + Constants.User.Register.EMAIL, + Constants.User.Register.USER_NAME, + Constants.User.Register.PASSWORD, + Constants.User.Register.CONFIRM_PASSWORD); + + IOTHomePage homePage = loginPage.loginAsUser(Constants.User.Register.USER_NAME, + Constants.User.Register.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(); + Assert.assertEquals(driver.getTitle(), Constants.User.Login.PAGE_TITLE); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java new file mode 100644 index 00000000..ec088dd4 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/java/org/wso2/carbon/iot/integration/web/ui/test/user/RegistrationFormValidationTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.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.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.extensions.selenium.BrowserManager; +import org.wso2.carbon.iot.integration.web.ui.test.common.Constants; +import org.wso2.carbon.iot.integration.web.ui.test.common.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; +import java.io.IOException; + +/** + * These test cases check for following: + * - Submitting an empty form + * - Existing username + * - Non matching passwords + * - Password, username length + */ +public class RegistrationFormValidationTest extends IOTIntegrationUIBaseTestCase { + + private WebDriver driver; + 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(); + } + + @Test(description = "Test for submitting an empty registration form") + public void emptyFormTest() throws IOException { + registerPage.validateForm("", "", "", "", "", ""); + + WebElement alertFirstName = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.form.error"))); + + if (!alertFirstName.isDisplayed()) { + Assert.assertTrue(false, "Alert for first name is not displayed"); + } + + Assert.assertEquals(alertFirstName.getText(), "Firstname is a required field. It cannot be empty."); + } + + @Test(description = "Test for non matching passwords") + public void nonMatchingPasswordTest() { + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "password", "Password"); + WebElement alertConfPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.form.error"))); + + if (!alertConfPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for confirm password is not displayed"); + } + + Assert.assertEquals(alertConfPassword.getText(), "Please enter the same password for confirmation."); + } + + @Test(description = "Test for email") + public void incorrectEmailTest() { + registerPage.validateForm("user", "user", "user123", "user1", "password", "password"); + WebElement alertEmail = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.form.error"))); + if (!alertEmail.isDisplayed()) { + Assert.assertTrue(false, "Alert for email is not displayed"); + } + + Assert.assertEquals(alertEmail.getText(), "Provided email is invalid."); + } + + @Test(description = "Test for password length") + public void passwordLengthTest() { + registerPage.validateForm("user", "user", "user@wso2.com", "user1", "pass", "pass"); + WebElement alertPassword = driver.findElement(By.id( + uiElementMapper.getElement("iot.user.register.form.error"))); + if (!alertPassword.isDisplayed()) { + Assert.assertTrue(false, "Alert for password is not displayed"); + } + + Assert.assertEquals(alertPassword.getText(), "Password is a required field. It cannot be empty."); + } + + @AfterClass(alwaysRun = true) + public void tearDown() { + driver.quit(); + } + +} diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/automation.xml b/modules/integration/tests-iot-web-ui/src/test/resources/automation.xml new file mode 100644 index 00000000..5cfb0229 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/automation.xml @@ -0,0 +1,224 @@ + + + + + + + + + 300000 + + standalone + + false + + false + + + + + + + http://10.100.2.51:4444/wd/hub/ + + + + firefox + + /home/test/name/webDriver + + + + + + + jdbc:h2:testDB + wso2carbon + wso2carbon + org.h2.Driver + + + jdbc:h2:testDB + wso2carbon + wso2carbon + org.h2.Driver + + + + + + + keystores/products/wso2carbon.jks + + JKS + + wso2carbon + + wso2carbon + + wso2carbon + + + + + client-truststore.jks + + JKS + + wso2carbon + + + + + + https://wso2.org/repo + file:///home/krishantha/test + + + + + + + + + + admin + admin + + + + + testuser11 + testuser11 + + + testuser21 + testuser21 + + + + + + + + + admin + admin + + + + + testuser11 + testuser11 + + + testuser21 + testuser21 + + + + + + + + + + + + + localhost + + + 9763 + 9446 + 9443 + 9445 + + + + + + + + + + + + + + + org.wso2.carbon.iot.integration.web.ui.test.extension.BrokerServerExtension + org.wso2.carbon.iot.integration.web.ui.test.extension.IOTServerExtension + org.wso2.carbon.iot.integration.web.ui.test.extension.AnalyticsServerExtension + org.wso2.carbon.integration.common.extensions.usermgt.UserPopulateExtension + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/automationXMLSchema.xsd b/modules/integration/tests-iot-web-ui/src/test/resources/automationXMLSchema.xsd new file mode 100644 index 00000000..b800b2ba --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/automationXMLSchema.xsd @@ -0,0 +1,611 @@ + + + + + + + ================================================= + Parameters ================================================= + Browser type with used by framework to execute UI test, supported types + - chrome|firefox|opera|ie|htmlUnit + + + + + + + Change this to edit wait time for test + artifact deployment + + + + + + Change this to product|platform/cloud to + execute test on specific environment + + + + + + + Change this to true if you want to generate + coverage statistics + + + + + + Change this to true if you want to enable + framework dashboard + + + + + + + + + + + + + + + Change to enable remote webDriver + URL of remote webDriver server + + + + + + + + + + + + + Type of the browser selenium tests + are running" + + + + + + + + path to webDriver + executable - required only for + chrome + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KeyStore which will be used for + encrypting/decrypting passwords + and other sensitive information. + + + + + + + Keystore file location + + + + + + Keystore type (JKS/PKCS12 etc.) + + + + + + Keystore password + + + + + + Private Key alias + + + + + + Private Key password + + + + + + + + + + System wide trust-store which is used to + maintain the certificates of all + the trusted parties. + + + + + + + trust-store file location + + + + + + trust-store type (JKS/PKCS12 + etc.) + + + + + + trust-store password + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/axis2config/axis2_client.xml b/modules/integration/tests-iot-web-ui/src/test/resources/axis2config/axis2_client.xml new file mode 100644 index 00000000..a8b584d0 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/axis2config/axis2_client.xml @@ -0,0 +1,300 @@ + + + + + + + true + false + false + + + 500 + + 15000 + + + false + + + + true + + + + + + false + + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6071 + + + + + + + + + + + + + + + + + + + + + + HTTP/1.1 + chunked + 60000 + 60000 + + + HTTP/1.1 + chunked + 60000 + 60000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v10.mar b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v10.mar new file mode 100644 index 00000000..57f85764 Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v10.mar differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v11-20140908.185829-596.mar b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v11-20140908.185829-596.mar new file mode 100644 index 00000000..4ca7737a Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v11-20140908.185829-596.mar differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v15.mar b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v15.mar new file mode 100644 index 00000000..68f5cbd6 Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/addressing-1.6.1-wso2v15.mar differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/rampart-1.6.1-wso2v8.mar b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/rampart-1.6.1-wso2v8.mar new file mode 100644 index 00000000..60cd6cdf Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/client/modules/rampart-1.6.1-wso2v8.mar differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/emma.properties b/modules/integration/tests-iot-web-ui/src/test/resources/emma.properties new file mode 100644 index 00000000..9c48e81b --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/emma.properties @@ -0,0 +1,105 @@ +# ------------------------------------------------------------- +# +# for user-editable property overrides use one of these options: +# +# (1) option-specific command line overrides, e.g. +# -Dreport.txt.out.file=coverage.txt +# +# (2) '-p ' command line option, +# +# (3) 'emma.properties' resource placed somewhere in the classpath +# (e.g., in \classes directory -- note that it does +# not exist by default), +# +# (4) '-Demma.*' JVM options, e.g. +# -Demma.report.txt.out.file=coverage.txt +# +# (5) 'emma.properties' JVM option pointing to a properties file +# -Demma.properties=./myproperties.txt +# ------------------------------------------------------------- + +# ------------------------------------------------------------- +# logging properties: + +verbosity.level: none + +# classloading properties: + +#clsload.forced_delegation_filter: +#clsload.through_delegation_filter: -* + +# ------------------------------------------------------------- + +# instrumentation properties: + +instr.exclude_empty_classes: true +instr.exclude_synthetic_methods: true +instr.exclude_bridge_methods: true +instr.do_suid_compensation: true + +# ------------------------------------------------------------- + +# runtime properties: + +rt.control: false +rt.control.host: localhost +#rt.control.port: 44444 + +rt.filelock: true +#rt.filelock.portbase: 59141 +rt.filelock.maxtime: 120000 +rt.filelock.retries: 11 + +# ------------------------------------------------------------- + +# apprunner session data output properties: + +session.out.file: coverage.es +session.out.merge: true + +# ------------------------------------------------------------- + +# runtime coverage data output properties: + +coverage.out.file: coverage.ec +coverage.out.merge: true + +# ------------------------------------------------------------- + +# instr metadata output properties: + +metadata.out.file: coverage.em +metadata.out.merge: true + +# ------------------------------------------------------------- + +# common report defaults: + +report.units: instr +report.depth: method +report.columns: name, line, block, method, class +report.sort: -line,-block,-method,-class,+name +report.metrics: method:40,block:80,line:40,class:100 + +# ------------------------------------------------------------- +# txt report properties: + +report.txt.depth: all +report.txt.columns: class,method,block,line,name +report.txt.out.file: coverage.txt + +# ------------------------------------------------------------- +# html report properties: + +#report.html.out.dir: coverage +#report.html.out.file: /Users/azeez/Desktop/coverage/index.html +report.html.out.encoding: ISO-8859-1 + +# ------------------------------------------------------------- +# xml report properties: + +#report.xml.out.file: coverage.xml +report.xml.out.encoding: UTF-8 +# ------------------------------------------------------------- +# end of file + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/filters.txt b/modules/integration/tests-iot-web-ui/src/test/resources/filters.txt new file mode 100644 index 00000000..54913a22 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/filters.txt @@ -0,0 +1,17 @@ +-*.stub* +-*.stub_ +-*.stub_4.0.0 +-*.stub- +-org.eclipse.* +-*.equinox.* +-org.wso2.carbon.user.core.* +-samples.* +-*.log4j* +-*.axis2* +-*.ui* +-*.tenant* +-*.stratos* +-*.eventing* +-*transports* +-org.wso2.carbon.mediation.statistics* +-*startup* \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/instrumentation.txt b/modules/integration/tests-iot-web-ui/src/test/resources/instrumentation.txt new file mode 100644 index 00000000..917b2bb7 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/instrumentation.txt @@ -0,0 +1,11 @@ +org.wso2.carbon.datasource_ +org.wso2.carbon.dataservices.core_ +org.wso2.carbon.transaction.manager_ +org.wso2.carbon.dataservices.sql.driver_ +org.wso2.carbon.dataservices.task_ +org.wso2.carbon.ndatasource.common_ +org.wso2.carbon.ndatasource.core_ +org.wso2.carbon.ndatasource.rdbms_ +org.wso2.carbon.ntask.common_ +org.wso2.carbon.ntask.core_ +org.wso2.carbon.ntask.solutions_ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/client-truststore.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/client-truststore.jks new file mode 100644 index 00000000..ab222fdd Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/client-truststore.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2carbon.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2carbon.jks new file mode 100644 index 00000000..79784a5e Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2carbon.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2certs.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2certs.jks new file mode 100644 index 00000000..eb27997d Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2certs.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2mdm.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2mdm.jks new file mode 100644 index 00000000..66b68ea3 Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/products/wso2mdm.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/client-truststore.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/client-truststore.jks new file mode 100644 index 00000000..ab222fdd Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/client-truststore.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2carbon.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2carbon.jks new file mode 100644 index 00000000..79784a5e Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2carbon.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2certs.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2certs.jks new file mode 100644 index 00000000..eb27997d Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2certs.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2emm.jks b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2emm.jks new file mode 100644 index 00000000..ae5670b0 Binary files /dev/null and b/modules/integration/tests-iot-web-ui/src/test/resources/keystores/stratos/wso2emm.jks differ diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/log4j.properties b/modules/integration/tests-iot-web-ui/src/test/resources/log4j.properties new file mode 100644 index 00000000..6fc06a7e --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/log4j.properties @@ -0,0 +1,43 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# 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. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +log4j.rootLogger=INFO, console, Default + +log4j.logger.org.wso2=INFO + +#Automation file apender +log4j.appender.Default=org.apache.log4j.RollingFileAppender +log4j.appender.Default.File=logs/automation.log +log4j.appender.Default.Append=true +log4j.appender.Default.MaxFileSize=10MB +log4j.appender.Default.MaxBackupIndex=10 +log4j.appender.Default.layout=org.apache.log4j.PatternLayout +log4j.appender.Default.layout.ConversionPattern=%d{ISO8601} %-5p [%c] - %m%n + + +#Automation console apender +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%-5p [%c] - %m%n \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario-config.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario-config.xml new file mode 100644 index 00000000..79f018ca --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario-config.xml @@ -0,0 +1,201 @@ + + + + + + +

UsernameToken + Provides Authentication. Clients have Username Tokens + ut + + rampart + + UTOverTransport + basic + + + Non-repudiation + Provides Authentication and Integrity. Clients have X509 certificates + keystore + + rampart + + SigOnly + basic + + + Integrity + Provides Integrity. Clients do not have X509 certificates + keystore + + rampart + + SgnOnlyAnonymous + basic + + + Confidentiality + Provides Confidentiality. Clients do not have X509 certificates + keystore + + rampart + + EncrOnlyAnonymous + basic + + + + + Sign and encrypt - X509 Authentication + Provides Authentication, Integrity and Confidentiality. Clients have X509 certificates + + keystore + + rampart + + SigEncr + advanced + + + Sign and Encrypt - Anonymous clients + Provides Integrity and Confidentiality. + keystore + + rampart + + SgnEncrAnonymous + advanced + + + Encrypt only - Username Token Authentication + Provides Authentication and Confidentiality. Clients have Username Tokens + ut-keystore + + rampart + + EncrOnlyUsername + advanced + + + Sign and Encrypt - Username Token Authentication + Provides Authentication, Integrity and Confidentiality. Clients have Username Tokens + ut-keystore + + rampart + + SgnEncrUsername + advanced + + + SecureConversation - Sign only - Service as STS - Bootstrap policy - Sign and Encrypt , X509 + Authentication + + Provides Authentication and Integrity. Multiple message exchange.Clients have X509 certificates. + + keystore + + rampart + rahas + + SecConSignOnly + advanced + + + SecureConversation - Encrypt only - Service as STS - Bootstrap policy - + Sign and Encrypt , X509 Authentication + + Provides Confidentiality. Multiple message exchange.Clients have X509 certificates. + keystore + + rampart + rahas + + SecConEncrOnly + advanced + + + SecureConversation - Sign and Encrypt - Service as STS - Bootstrap policy - Sign and Encrypt , X509 + Authentication + + Provides Authentication, Integrity and Confidentiality. Multiple message exchange.Clients have X509 + certificates. + + keystore + + rampart + rahas + + SecConSgnEncr + advanced + + + SecureConversation - Sign Only - Service as STS - Bootstrap policy - Sign and Encrypt , Anonymous + clients + + Provides Integrity. Multiple message exchange. + keystore + + rampart + rahas + + SecConSignOnlyAnonymous + advanced + + + SecureConversation - Encrypt Only - Service as STS - Bootstrap policy - Sign and Encrypt , Anonymous + clients + + Provides Confidentiality. Multiple message exchange. + keystore + + rampart + rahas + + SecConEncrOnlyAnonymous + advanced + + + SecureConversation - Encrypt Only - Service as STS - Bootstrap policy - Sign and Encrypt , Username + Token Authentication + + Provides Authentication and Confidentiality. Multiple message exchange. Clients have Username + Tokens. + + ut-keystore + + rampart + rahas + + SecConEncrUsername + advanced + + + SecureConversation - Sign and Encrypt - Service as STS - Bootstrap policy - Sign and Encrypt , Username + Token Authentication + + Provides Authentication Integrity and Confidentiality. Multiple message exchange. Clients have + Username Tokens. + + ut-keystore + + rampart + rahas + + SecConSgnEncrUsername + advanced + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario1-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario1-policy.xml new file mode 100644 index 00000000..4a232f73 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario1-policy.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario10-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario10-policy.xml new file mode 100644 index 00000000..2d076e06 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario10-policy.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario11-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario11-policy.xml new file mode 100644 index 00000000..794d52ee --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario11-policy.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario12-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario12-policy.xml new file mode 100644 index 00000000..6ac14ecd --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario12-policy.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario13-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario13-policy.xml new file mode 100644 index 00000000..dbefeda8 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario13-policy.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario14-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario14-policy.xml new file mode 100644 index 00000000..bafd7263 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario14-policy.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario15-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario15-policy.xml new file mode 100644 index 00000000..47fb6711 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario15-policy.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario16-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario16-policy.xml new file mode 100644 index 00000000..dc383d79 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario16-policy.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ https://kirillgdev04/Security_Federation_SecurityTokenService_Indigo/Symmetric.svc/Scenario_1_IssuedTokenOverTransport_UsernameOverTransport +
+
+ + + urn:oasis:names:tc:SAML:1.0:assertion + + + http://schemas.xmlsoap.org/ws/2005/02/trust/SymmetricKey + + + 256 + + + + + +
+ + + +
+
+ + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario17-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario17-policy.xml new file mode 100644 index 00000000..637cf81d --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario17-policy.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + +
+ http://foo.bar/we/don/t/process/this/yet +
+
+ + + urn:oasis:names:tc:SAML:1.0:assertion + + + http://schemas.xmlsoap.org/ws/2005/02/trust/SymmetricKey + + 256 + + + + +
+
+
+ + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario2-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario2-policy.xml new file mode 100644 index 00000000..08a45d55 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario2-policy.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario3-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario3-policy.xml new file mode 100644 index 00000000..0bfd14eb --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario3-policy.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario4-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario4-policy.xml new file mode 100644 index 00000000..9ee47cc2 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario4-policy.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario5-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario5-policy.xml new file mode 100644 index 00000000..9454c745 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario5-policy.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario6-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario6-policy.xml new file mode 100644 index 00000000..7de14746 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario6-policy.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario7-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario7-policy.xml new file mode 100644 index 00000000..db95d371 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario7-policy.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario8-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario8-policy.xml new file mode 100644 index 00000000..1fdfd940 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario8-policy.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario9-policy.xml b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario9-policy.xml new file mode 100644 index 00000000..73fa833b --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/security/policies/scenario9-policy.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/testng-server-mgt.xml b/modules/integration/tests-iot-web-ui/src/test/resources/testng-server-mgt.xml new file mode 100644 index 00000000..b57f1223 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/testng-server-mgt.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml b/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml new file mode 100644 index 00000000..73139933 --- /dev/null +++ b/modules/integration/tests-iot-web-ui/src/test/resources/testng.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/integration/tests-platform/pom.xml b/modules/integration/tests-platform/pom.xml new file mode 100644 index 00000000..29157189 --- /dev/null +++ b/modules/integration/tests-platform/pom.xml @@ -0,0 +1,33 @@ + + + + + + org.wso2.iot + wso2iot-integration + 3.1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + tests-platform + pom + WSO2 IoT - Integration Test Platform + + diff --git a/pom.xml b/pom.xml index 39675a5e..042f9952 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ modules/tools modules/p2-profile modules/distribution + modules/integration