diff --git a/agent/agent_common/.gitignore b/agent/agent_common/.gitignore new file mode 100644 index 000000000..aaf073c50 --- /dev/null +++ b/agent/agent_common/.gitignore @@ -0,0 +1,2 @@ +/target +/src/test/resources/tt.xml diff --git a/agent/agent_common/pom.xml b/agent/agent_common/pom.xml index 50c580074..689dc1f71 100644 --- a/agent/agent_common/pom.xml +++ b/agent/agent_common/pom.xml @@ -25,10 +25,6 @@ commons-fileupload commons-fileupload - - org.jdom - jdom2 - jakarta.xml.ws jakarta.xml.ws-api diff --git a/agent/agent_common/src/main/java/com/intuit/tank/http/xml/GenericXMLHandler.java b/agent/agent_common/src/main/java/com/intuit/tank/http/xml/GenericXMLHandler.java index 0310c6e32..ce44b13e9 100644 --- a/agent/agent_common/src/main/java/com/intuit/tank/http/xml/GenericXMLHandler.java +++ b/agent/agent_common/src/main/java/com/intuit/tank/http/xml/GenericXMLHandler.java @@ -13,30 +13,31 @@ * #L% */ -import java.io.File; -import java.io.StringReader; +import java.io.*; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.stream.Collectors; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPathFactory; +import java.util.stream.IntStream; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.jdom2.Attribute; -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.Namespace; -import org.jdom2.input.SAXBuilder; -import org.jdom2.input.sax.XMLReaders; -import org.jdom2.output.XMLOutputter; -import org.jdom2.xpath.XPath; +import org.w3c.dom.*; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; /** * Generic class to provide xml file reading and writing capabilities @@ -48,17 +49,16 @@ public class GenericXMLHandler implements Cloneable { protected File xmlFile = null; protected HashMap namespaces; protected String xml; - private org.w3c.dom.Document dDoc; /** * Constructor */ public GenericXMLHandler() { try { - this.xmlDocument = new Document(); + this.xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); this.namespaces = new HashMap(); - } catch (Exception ex) { - LOG.error("Error initializing handler: " + ex.getMessage(), ex); + } catch (ParserConfigurationException ex) { + LOG.error("Error initializing handler: {}", ex.getMessage(), ex); } } @@ -71,41 +71,33 @@ public GenericXMLHandler() { public GenericXMLHandler(File xmlFile) { try { this.xmlFile = xmlFile; - this.xmlDocument = new org.jdom2.Document(); - SAXBuilder builder = new SAXBuilder(); - builder.setXMLReaderFactory(XMLReaders.NONVALIDATING); - this.xmlDocument = builder.build(this.xmlFile); + DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + this.xmlDocument = builder.parse(this.xmlFile); this.namespaces = new HashMap(); - } catch (Exception ex) { + } catch (ParserConfigurationException | SAXException | IOException ex) { this.xmlDocument = null; - LOG.error("Error initializing handler: " + ex.getMessage(), ex); + LOG.error("Error initializing handler: {}", ex.getMessage(), ex); } } /** * Constructor * - * @param xmlFile + * @param xmlString * The string representation of the xml data */ - public GenericXMLHandler(String xmlFile) { - if (StringUtils.isNotEmpty(xmlFile)) { - this.xml = xmlFile; + public GenericXMLHandler(String xmlString) { + if (StringUtils.isNotEmpty(xmlString)) { + this.xml = xmlString; try { this.xmlFile = null; - this.xmlDocument = new org.jdom2.Document(); - SAXBuilder builder = new SAXBuilder(); - builder.setXMLReaderFactory(XMLReaders.NONVALIDATING); - // LOG.debug("XML string to load: "+xmlFile); - xmlFile = xmlFile.substring(xmlFile.indexOf("<")); - this.xmlDocument = builder.build(new StringReader(xmlFile)); + DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + xmlString = xmlString.substring(xmlString.indexOf("<")); + this.xmlDocument = builder.parse(new InputSource(new StringReader(xmlString))); this.namespaces = new HashMap(); - InputSource is = new InputSource(new StringReader(xml)); - this.dDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(is); } catch (Exception ex) { this.xmlDocument = null; - LOG.error("Error parsing xml Response: " + xmlFile + ": " + ex.getMessage()); + LOG.error("Error parsing xml Response: {}: {}", xmlString, ex.getMessage()); } } } @@ -120,85 +112,28 @@ public GenericXMLHandler(String xmlFile) { */ public void SetElementText(String xPathExpression, String value) { - Element node; try { - node = SetElementText(xPathExpression, 0); - node.setText(value); - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); + Element element = (Element) XPathFactory.newInstance().newXPath() + .evaluate(xPathExpression, this.xmlDocument, XPathConstants.NODE); + if (element != null) element.setTextContent(value); + } catch (XPathExpressionException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } } public void SetElementAttribute(String xPathExpression, String attribute, String value) { - Element node; try { - node = SetElementText(xPathExpression, 0); - node.setAttribute(attribute, value); - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); + Element element = (Element) XPathFactory.newInstance().newXPath() + .evaluate(xPathExpression, this.xmlDocument, XPathConstants.NODE); + element.setAttribute(attribute, value); + } catch (XPathExpressionException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } } - /** - * Set the element's text value - * - * @param xPathExpression - * The xpath expression for the element - * @param currentNode - * The value to set the text to - * @throws JDOMException - */ - private Element SetElementText(String xPathExpression, int currentNode) throws JDOMException { - - String currentPath = getCurrentPath(xPathExpression, currentNode); - - if (xPathExists(currentPath)) { - if (currentPath.equals(xPathExpression)) { - return (org.jdom2.Element) XPath.selectSingleNode(this.xmlDocument, xPathExpression); - - } - else { - return SetElementText(xPathExpression, currentNode + 1); - } - } else { - - String childNode = getChildNode(currentPath); - String namespace = getCurrentNamespace(currentPath); - - Element element; - if (namespace != null) { - Namespace sNS = Namespace.getNamespace(namespace, this.namespaces.get(namespace)); - element = new Element(childNode, sNS); - // element.setAttribute("someKey", "someValue", Namespace.getNamespace("someONS", - // "someOtherNamespace")); - } else { - element = new Element(childNode); - } - - if (this.xmlDocument.hasRootElement()) { - Element node = (Element) XPath.selectSingleNode(this.xmlDocument, getParentPath(currentPath)); - node.addContent(element); - } else { - if (this.xmlDocument.hasRootElement()) { - this.xmlDocument.detachRootElement(); - } - - this.xmlDocument.addContent(element); - } - - if (currentPath.equals(xPathExpression)) { - return element; - } - else { - return SetElementText(xPathExpression, currentNode + 1); - } - - } - } - - /** + /** * Get the text for the selected element * * @param xPathExpression @@ -207,15 +142,13 @@ private Element SetElementText(String xPathExpression, int currentNode) throws J */ public String GetElementText(String xPathExpression) { try { - String result = XPathFactory.newInstance().newXPath().evaluate(xPathExpression, dDoc); - if (StringUtils.isNotEmpty(result)) { - return result; - } - return ""; - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); - return ""; + Node node = (Node) XPathFactory.newInstance().newXPath() + .evaluate(xPathExpression, this.xmlDocument, XPathConstants.NODE); + return node.getTextContent(); + } catch (XPathExpressionException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } + return ""; } /** @@ -227,12 +160,17 @@ public String GetElementText(String xPathExpression) { */ public String GetElementAttr(String xPathExpression) { try { - org.jdom2.Attribute node = (Attribute) XPath.selectSingleNode(this.xmlDocument, xPathExpression); - return node.getValue(); - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); - return ""; + Node node = (Node) XPathFactory.newInstance().newXPath() + .evaluate(xPathExpression, this.xmlDocument, XPathConstants.NODE); + NamedNodeMap attributes = node.getAttributes(); + return IntStream.range(0, attributes.getLength()) + .mapToObj(attributes::item) + .map(Node::getTextContent) + .collect(Collectors.joining(",")); + } catch (XPathExpressionException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } + return ""; } /** @@ -243,26 +181,30 @@ public String GetElementAttr(String xPathExpression) { */ public ArrayList GetElementList(String xPathExpression) { try { - List nodeList = XPath.selectNodes(this.xmlDocument, xPathExpression); - return nodeList.stream().map(aNodeList -> (Element) aNodeList).map(Element::getText).collect(Collectors.toCollection(ArrayList::new)); - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); - return null; + NodeList nodeList = (NodeList) XPathFactory.newInstance().newXPath() + .evaluate(xPathExpression, this.xmlDocument, XPathConstants.NODESET); + return IntStream.range(0, nodeList.getLength()) + .mapToObj(nodeList::item) + .map(Node::getTextContent) + .collect(Collectors.toCollection(ArrayList::new)); + } catch (XPathExpressionException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } + return null; } /** * Does an xPath expression exist * - * @param xpathExpr + * @param xPathExpression * The xPath expression * @return TRUE if the xPath expression exists; false otherwise */ - public boolean xPathExists(String xpathExpr) + public boolean xPathExists(String xPathExpression) { try { - return !(XPath.selectSingleNode(this.xmlDocument, xpathExpr) == null); - } catch (Exception ex) { + return !(XPathFactory.newInstance().newXPath().evaluate(xPathExpression, this.xmlDocument).isEmpty()); + } catch (XPathExpressionException ex) { return false; } } @@ -272,12 +214,18 @@ public boolean xPathExists(String xpathExpr) */ public String toString() { if (this.xmlDocument != null) { - XMLOutputter outputter = new XMLOutputter(); - String output = outputter.outputString(this.xmlDocument); - output = output.replaceAll("\r", ""); - output = output.replaceAll("\n", ""); - output = output.replaceAll("\t", ""); - return output; + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + StringWriter writer = new StringWriter(); + transformer.transform(new DOMSource(this.xmlDocument), new StreamResult(writer)); + String output = writer.getBuffer().toString(); + output = output.replaceAll("\r", ""); + output = output.replaceAll("\n", ""); + output = output.replaceAll("\t", ""); + return output; + } catch (TransformerException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); + } } return ""; } @@ -286,14 +234,12 @@ public String toString() { * Save the xml to a file */ public void Save() { - try { - XMLOutputter out = new XMLOutputter(); - java.io.FileWriter writer = new java.io.FileWriter(this.xmlFile); - out.output(this.xmlDocument, writer); + try (FileWriter writer = new FileWriter(this.xmlFile)) { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(this.xmlDocument), new StreamResult(writer)); writer.flush(); - writer.close(); - } catch (Exception ex) { - LOG.error("Error in handler: " + ex.getMessage(), ex); + } catch (TransformerException | IOException ex) { + LOG.error("Error in handler: {}", ex.getMessage(), ex); } } diff --git a/agent/agent_common/src/main/java/com/intuit/tank/http/xml/JsonHandler.java b/agent/agent_common/src/main/java/com/intuit/tank/http/xml/JsonHandler.java deleted file mode 100644 index d228c3f4e..000000000 --- a/agent/agent_common/src/main/java/com/intuit/tank/http/xml/JsonHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright 2011 Intuit Inc. All Rights Reserved - */ -package com.intuit.tank.http.xml; - -/* - * #%L - * Intuit Tank Agent (apiharness) - * %% - * Copyright (C) 2011 - 2015 Intuit Inc. - * %% - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * #L% - */ - -/** - * JsonHandler - * - * @author dangleton - * - */ -public class JsonHandler { - -} diff --git a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/GenericXMLHandlerTest.java b/agent/agent_common/src/test/java/com/intuit/tank/http/xml/GenericXMLHandlerTest.java index 4b7350acb..bb7005841 100644 --- a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/GenericXMLHandlerTest.java +++ b/agent/agent_common/src/test/java/com/intuit/tank/http/xml/GenericXMLHandlerTest.java @@ -14,294 +14,56 @@ */ import java.io.File; +import java.time.Instant; +import java.util.Arrays; import java.util.HashMap; -import org.jdom2.Document; import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; -/** - * The class GenericXMLHandlerTest contains tests for the class {@link GenericXMLHandler}. - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ public class GenericXMLHandlerTest { - /** - * Run the GenericXMLHandler() constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_1() - throws Exception { - - GenericXMLHandler result = new GenericXMLHandler(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.ExceptionInInitializerError - // at org.apache.log4j.LogManager.getLogger(Logger.java:117) - // at com.intuit.tank.http.xml.GenericXMLHandler.(GenericXMLHandler.java:31) - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(File) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_2() - throws Exception { - File xmlFile = new File(""); - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(File) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_3() - throws Exception { - File xmlFile = new File(""); - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(File) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_4() - throws Exception { - File xmlFile = new File(""); - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_5() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_6() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_7() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_8() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_9() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_10() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_11() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the GenericXMLHandler(String) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGenericXMLHandler_12() - throws Exception { - String xmlFile = ""; - - GenericXMLHandler result = new GenericXMLHandler(xmlFile); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } + private final String xml = """ + + + + Text content for child element 1. + + + + More text content. + + + + """; /** * Run the String GetElementAttr(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - @Disabled - public void testGetElementAttr_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; + public void testGetElementAttr_1() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); + String xPathExpression = "rootElement/childElement1"; String result = fixture.GetElementAttr(xPathExpression); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("value1", result); } /** * Run the String GetElementAttr(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - @Disabled - public void testGetElementAttr_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; + public void testGetElementAttr_2() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); + String xPathExpression = "testPlan/testSuite"; String result = fixture.GetElementAttr(xPathExpression); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("Suite for XXX5,XXX5", result); } /** @@ -314,549 +76,253 @@ public void testGetElementAttr_2() @Test public void testGetElementText_1() throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; + GenericXMLHandler fixture = new GenericXMLHandler(xml); + String xPathExpression = "rootElement/childElement1"; String result = fixture.GetElementText(xPathExpression); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("Text content for child element 1.", result.trim()); } /** * Run the String GetElementText(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test public void testGetElementText_2() throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; - - String result = fixture.GetElementText(xPathExpression); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the String GetElementText(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGetElementText_3() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); + String xPathExpression = "testPlan/testSuite"; String result = fixture.GetElementText(xPathExpression); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("https\n\t\t\t\ttest.com\n\t\t\t\t/index.html", result.trim()); } /** * Run the void Save() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSave_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); + public void testSave() { + File xmlfile = new File("src/test/resources/tt.xml"); + GenericXMLHandler fixture = new GenericXMLHandler(xmlfile); fixture.Save(); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - } - - /** - * Run the void Save() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testSave_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - - fixture.Save(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - } - - /** - * Run the void Save() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testSave_3() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - - fixture.Save(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - } - - /** - * Run the void Save() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testSave_4() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - - fixture.Save(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - } - - /** - * Run the void Save() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testSave_5() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - - fixture.Save(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertTrue(xmlfile.exists()); + assertTrue(Instant.now().isAfter(Instant.ofEpochMilli(xmlfile.lastModified()))); } /** * Run the void SetElementAttribute(String,String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test public void testSetElementAttribute_1() throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; - String attribute = ""; - String value = ""; + GenericXMLHandler fixture = new GenericXMLHandler(xml); + String xPathExpression = "rootElement/childElement2"; + String attribute = "TEST"; + String value = "TEST"; fixture.SetElementAttribute(xPathExpression, attribute, value); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertEquals("TEST", fixture.GetElementAttr(xPathExpression)); } /** * Run the void SetElementAttribute(String,String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSetElementAttribute_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; - String attribute = ""; - String value = ""; + public void testSetElementAttribute_2() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); + String xPathExpression = "testPlan/testSuite"; + String attribute = "TEST"; + String value = "TEST"; fixture.SetElementAttribute(xPathExpression, attribute, value); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertTrue(Arrays.asList(fixture.GetElementAttr(xPathExpression).split(",")).contains(value)); } /** * Run the void SetElementText(String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSetElementText_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; - String value = ""; + public void testSetElementText_1() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); + String xPathExpression = "rootElement/childElement2"; + String value = "TEST"; fixture.SetElementText(xPathExpression, value); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertEquals(value, fixture.GetElementText(xPathExpression)); } /** * Run the void SetElementText(String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSetElementText_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xPathExpression = ""; - String value = ""; + public void testSetElementText_2() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); + String xPathExpression = "testPlan/testSuite"; + String value = "TEST"; fixture.SetElementText(xPathExpression, value); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertEquals(value, fixture.GetElementText(xPathExpression)); } /** * Run the Object clone() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testClone_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); + public void testClone_1() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); Object result = fixture.clone(); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertTrue(result instanceof GenericXMLHandler); } /** * Run the Object clone() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testClone_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); + public void testClone_2() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); Object result = fixture.clone(); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertTrue(result instanceof GenericXMLHandler); } /** * Run the String getChildNode(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testGetChildNode_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpath = ""; - - String result = fixture.getChildNode(xpath); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the String getChildNode(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGetChildNode_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpath = ""; + public void testGetChildNode() { + GenericXMLHandler fixture = new GenericXMLHandler(""); + String xpath = "/TEST/TEST"; String result = fixture.getChildNode(xpath); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("TEST", result); } /** * Run the String getCurrentPath(String,int) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testGetCurrentPath_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpath = ""; - int node = -1; + public void testGetCurrentPath() { + GenericXMLHandler fixture = new GenericXMLHandler(""); + String xpath = "//TEST/TEST"; + int node = 1; String result = fixture.getCurrentPath(xpath, node); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("//TEST", result); } /** * Run the String getParentPath(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testGetParentPath_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpath = ""; + public void testGetParentPath_1() { + GenericXMLHandler fixture = new GenericXMLHandler(""); + String xpath = "/rootElement/childElement1"; String result = fixture.getParentPath(xpath); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertNotNull(result); - } - - /** - * Run the String getParentPath(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ - @Test - public void testGetParentPath_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpath = ""; - - String result = fixture.getParentPath(xpath); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); + assertEquals("/rootElement", result); } /** * Run the boolean isXMLValid() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testIsXMLValid_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); + public void testIsXMLValid_1() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); boolean result = fixture.isXMLValid(); assertTrue(result); + + GenericXMLHandler fixture2 = new GenericXMLHandler(xml.substring(10, 30)); + boolean result2 = fixture2.isXMLValid(); + assertFalse(result2); } /** * Run the boolean isXMLValid() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testIsXMLValid_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - + public void testIsXMLValid_2() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); boolean result = fixture.isXMLValid(); - - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertTrue(result); } /** * Run the void setNamespace(String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSetNamespace_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String name = ""; - String value = ""; + public void testSetNamespace() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); + String name = "TEST"; + String value = "TEST"; fixture.setNamespace(name, value); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler + assertEquals(value, fixture.namespaces.get(name)); } /** * Run the String toString() method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testToString_2() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = null; + public void testToString() { + GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); String result = fixture.toString(); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertNotNull(result); } /** * Run the boolean xPathExists(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - @Disabled - public void testXPathExists_1() - throws Exception { - GenericXMLHandler fixture = new GenericXMLHandler(new File("")); - fixture.namespaces = new HashMap(); - fixture.xml = ""; - fixture.xmlDocument = new Document(); - String xpathExpr = ""; + public void testXPathExists() { + GenericXMLHandler fixture = new GenericXMLHandler(xml); - boolean result = fixture.xPathExists(xpathExpr); + boolean result = fixture.xPathExists("rootElement/childElement1"); + assertTrue(result); + + boolean result2 = fixture.xPathExists("rootElement"); + assertTrue(result2); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler - assertTrue(!result); + boolean result3 = fixture.xPathExists("BADELEMENT"); + assertFalse(result3); + + boolean result4 = fixture.xPathExists(""); + assertFalse(result4); } /** * Run the boolean xPathExists(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - @Disabled - public void testXPathExists_2() - throws Exception { + public void testXPathExists_2() { GenericXMLHandler fixture = new GenericXMLHandler(new File("src/test/resources/tt.xml")); fixture.namespaces = new HashMap(); String xpathExpr = "testPlan/testSuite"; boolean result = fixture.xPathExists(xpathExpr); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.xml.GenericXMLHandler assertTrue(result); } diff --git a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/JsonHandlerTest.java b/agent/agent_common/src/test/java/com/intuit/tank/http/xml/JsonHandlerTest.java deleted file mode 100644 index a10922b6f..000000000 --- a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/JsonHandlerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.intuit.tank.http.xml; - -/* - * #%L - * Intuit Tank Agent (apiharness) - * %% - * Copyright (C) 2011 - 2015 Intuit Inc. - * %% - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * #L% - */ - -import org.junit.jupiter.api.*; - -import com.intuit.tank.http.xml.JsonHandler; - -import static org.junit.jupiter.api.Assertions.*; - -/** - * The class JsonHandlerTest contains tests for the class {@link JsonHandler}. - * - * @generatedBy CodePro at 12/16/14 3:57 PM - */ -public class JsonHandlerTest { -} \ No newline at end of file diff --git a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/XMLRequestTest.java b/agent/agent_common/src/test/java/com/intuit/tank/http/xml/XMLRequestTest.java index 01f6abd09..5f2a7aa19 100644 --- a/agent/agent_common/src/test/java/com/intuit/tank/http/xml/XMLRequestTest.java +++ b/agent/agent_common/src/test/java/com/intuit/tank/http/xml/XMLRequestTest.java @@ -5,42 +5,22 @@ import org.junit.jupiter.api.Test; -/** - * The class XMLRequestTest contains tests for the class {@link XMLRequest}. - * - * @generatedBy CodePro at 12/16/14 4:29 PM - */ public class XMLRequestTest { /** * Run the XMLRequest(Httpnull) constructor test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testXMLRequest_1() - throws Exception { - - + public void testXMLRequest_1() { XMLRequest result = new XMLRequest(null, null); - // An unexpected exception was thrown in user code while executing this test: - // java.lang.ExceptionInInitializerError assertNotNull(result); } - /** * Run the String getKey(String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testGetKey_1() - throws Exception { + public void testGetKey_1() { XMLRequest fixture = new XMLRequest(null, null); fixture.handler = new GenericXMLHandler(); String key = ""; @@ -52,22 +32,20 @@ public void testGetKey_1() @Test public void testGetKey_2() { XMLRequest fixture = new XMLRequest(null, null); - fixture.handler = new GenericXMLHandler(); + fixture.handler = new GenericXMLHandler(""); fixture.setKey("testKey", "testValue"); - String result = fixture.getKey("testValue"); - assertEquals("", result); + + String result = fixture.getKey("testKey"); + + assertNotNull(result); + assertEquals("testValue", result); } /** * Run the void setNamespace(String,String) method test. - * - * @throws Exception - * - * @generatedBy CodePro at 12/16/14 4:29 PM */ @Test - public void testSetNamespace_1() - throws Exception { + public void testSetNamespace_1() { XMLRequest fixture = new XMLRequest(null, null); fixture.handler = new GenericXMLHandler(); String name = ""; diff --git a/pom.xml b/pom.xml index b7813c08d..32bee35f1 100644 --- a/pom.xml +++ b/pom.xml @@ -638,11 +638,6 @@ 1.2.0 test - - org.jdom - jdom2 - 2.0.6.1 - jakarta.xml jsr173 diff --git a/script_processor/pom.xml b/script_processor/pom.xml index 30be2d35e..120adde27 100644 --- a/script_processor/pom.xml +++ b/script_processor/pom.xml @@ -55,12 +55,6 @@ test - - org.jdom - jdom2 - test - - commons-jxpath commons-jxpath diff --git a/web/web_ui/pom.xml b/web/web_ui/pom.xml index a01f84a7d..3180794a7 100644 --- a/web/web_ui/pom.xml +++ b/web/web_ui/pom.xml @@ -231,11 +231,6 @@ redmond - - org.jdom - jdom2 - - commons-io commons-io