diff --git a/smoke-test/src/test/java/org/opennms/smoketest/KSCEditorIT.java b/smoke-test/src/test/java/org/opennms/smoketest/KSCEditorIT.java new file mode 100644 index 000000000000..ccdf3951c6d5 --- /dev/null +++ b/smoke-test/src/test/java/org/opennms/smoketest/KSCEditorIT.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * This file is part of OpenNMS(R). + * + * Copyright (C) 2017 The OpenNMS Group, Inc. + * OpenNMS(R) is Copyright (C) 1999-2017 The OpenNMS Group, Inc. + * + * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. + * + * OpenNMS(R) is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * OpenNMS(R) is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with OpenNMS(R). If not, see: + * http://www.gnu.org/licenses/ + * + * For more information contact: + * OpenNMS(R) Licensing + * http://www.opennms.org/ + * http://www.opennms.com/ + *******************************************************************************/ + +package org.opennms.smoketest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.apache.commons.io.FileUtils; +import org.apache.http.client.methods.HttpGet; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.opennms.core.xml.JaxbUtils; +import org.opennms.netmgt.model.OnmsNode; +import org.opennms.test.system.api.TestEnvironmentBuilder; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.Select; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class KSCEditorIT extends OpenNMSSeleniumTestCase { + private static final Logger LOG = LoggerFactory.getLogger(KSCEditorIT.class); + + private Integer m_nodeId; + private String m_shareDir = "/Users/ranger/git/opennms-foundation/target/opennms-19.0.0-SNAPSHOT/share"; // = "/home/ranger/git/opennms/target/opennms-19.0.0-SNAPSHOT/share" + private final Path m_targetDir = Paths.get(m_shareDir, "rrd", "response", "127.0.0.1"); + + public static void configureTestEnvironment(final TestEnvironmentBuilder builder) { + OpenNMSSeleniumTestCase.configureTestEnvironment(builder); + + builder.withOpenNMSEnvironment() + .addFiles(Paths.get("src/test/resources/ksc/"), "share/rrd/response/127.0.0.1/"); + } + + @Before + public void setUp() throws Exception { + createRequisition(); + + final ResponseData response = getRequest(new HttpGet(buildUrl("rest/nodes/" + REQUISITION_NAME + ":TestMachine1"))); + final OnmsNode node = JaxbUtils.unmarshal(OnmsNode.class, response.getResponseText()); + m_nodeId = node.getId(); + LOG.debug("created node {}", m_nodeId); + + Thread.sleep(5000); + if (!isDockerEnabled()) { + if (m_shareDir == null) { + throw new Exception("When running locally for testing, set m_shareDir to the path to your local OpenNMS 'share' directory."); + } + FileUtils.forceMkdir(m_targetDir.toFile()); + FileUtils.copyDirectory(Paths.get("src/test/resources/ksc/").toFile(), m_targetDir.toFile()); + } + } + + protected void goToMainPage() { + m_driver.get(getBaseUrl() + "opennms/KSC/index.jsp"); + } + + @Test + public void testKSCReports() throws Exception { + goToMainPage(); + checkMainPage(); + + goToMainPage(); + createReport(); + + goToMainPage(); + editExistingReport(); + + goToMainPage(); + deleteExistingReport(); + } + + protected void checkMainPage() throws Exception { + // main KSC page + assertEquals(3, countElementsMatchingCss("h3.panel-title")); + findElementByXpath("//h3[text()='Customized Reports']"); + findElementByXpath("//h3[text()='Node & Domain Interface Reports']"); + findElementByXpath("//h3[text()='Descriptions']"); + + assertElementDoesNotExist(By.name("report.0")); + assertEquals("TestMachine1", findElementByName("resource.0").getText()); + } + + protected void createReport() throws Exception { + // create a new report + clickElement(By.xpath("//button[text()='Create New']")); + + // set the title + enterText(By.name("report_title"), "Smoke Test Report 1"); + + // add the ICMP graph + clickElement(By.xpath("//button[text()='Add New Graph']")); + + // select the first subresource (TestMachine1) + clickElement(By.name("subresource.0")); + clickElement(By.xpath("//button[text()='View Child Resource']")); + + // select the first subresource (127.0.0.1) + clickElement(By.name("subresource.0")); + clickElement(By.xpath("//button[text()='View Child Resource']")); + + // choose the resource + clickElement(By.xpath("//button[text()='Choose this resource']")); + + // name the graph + enterText(By.name("title"), "Smoke Test Graph Title 1"); + + // finish up + clickElement(By.xpath("//button[text()='Done with edits to this graph']")); + clickElement(By.xpath("//button[text()='Save Report']")); + + assertEquals("Smoke Test Report 1", findElementByName("report.0").getText()); + + // view the report to confirm it's right + waitForElement(By.name("report.0")); + Thread.sleep(100); + clickElement(By.name("report.0")); + clickElement(By.xpath("//button[text()='View']")); + findElementByXpath("//h3[text()='Custom View: Smoke Test Report 1']"); + findElementByXpath("//div[contains(@class, 'graph-container')]"); + findElementByXpath("//img[contains(@class, 'graphImg')]"); + } + + protected void editExistingReport() throws Exception { + // edit report 0 (should be the Smoke Test Report 1 from b_test*) + clickElement(By.name("report.0")); + clickElement(By.xpath("//button[text()='Customize']")); + + // check that the defaults are set as expected + assertFalse(findElementByName("show_timespan").isSelected()); + assertFalse(findElementByName("show_graphtype").isSelected()); + final Select gpl = new Select(findElementByName("graphs_per_line")); + assertEquals("default", gpl.getFirstSelectedOption().getText()); + + // change graphs per line to 3, check "show timespan" and "show graphtype", and change the title + gpl.selectByVisibleText("3"); + clickElement(By.name("show_timespan")); + clickElement(By.name("show_graphtype")); + enterText(By.name("report_title"), "Smoke Test Report Uno"); + + // now confirm that the checkboxes got checked + assertTrue(findElementByName("show_timespan").isSelected()); + assertTrue(findElementByName("show_graphtype").isSelected()); + + // modify the graph and give it a new title + clickElement(By.xpath("//button[text()='Modify']")); + enterText(By.name("title"), "Smoke Test Graph Title I"); + + // update the timespan + final Select timespan = new Select(findElementByName("timespan")); + timespan.selectByVisibleText("3 month"); + + // then finish modifying the graph + clickElement(By.xpath("//button[text()='Done with edits to this graph']")); + + // then finish modifying the report + clickElement(By.xpath("//button[text()='Save Report']")); + } + + protected void deleteExistingReport() throws Exception { + // edit report 0 (should be the Smoke Test Report 1 from b_test*) + clickElement(By.name("report.0")); + clickElement(By.xpath("//button[text()='Delete']")); + assertElementDoesNotExist(By.name("report.0")); + } + + private void createRequisition() throws Exception { + final String req = "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + createRequisition(REQUISITION_NAME, req, 1); + } +} \ No newline at end of file diff --git a/smoke-test/src/test/resources/ksc/icmp.meta b/smoke-test/src/test/resources/ksc/icmp.meta new file mode 100644 index 000000000000..0ee5d9f84ad7 --- /dev/null +++ b/smoke-test/src/test/resources/ksc/icmp.meta @@ -0,0 +1,2 @@ +#Thu Jul 21 11:31:35 EDT 2016 +ICMP/192.168.211.1=icmp diff --git a/smoke-test/src/test/resources/ksc/icmp.rrd b/smoke-test/src/test/resources/ksc/icmp.rrd new file mode 100644 index 000000000000..0de09be25230 Binary files /dev/null and b/smoke-test/src/test/resources/ksc/icmp.rrd differ