Search in sources :

Example 6 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SmtpConnection method data.

@PublicAtsApi
public void data(String text) {
    try {
        //obtain an output stream
        OutputStream dataStream = data();
        dataStream.write(text.getBytes());
        dataStream.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (!finishData()) {
        throw new RuntimeException("Error executing data command");
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 7 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SystemOperations method logClassPath.

/**
     * Log all JARs in current application's ClassPath
     */
@PublicAtsApi
public void logClassPath() {
    ISystemOperations operations = getOperationsImplementationFor(atsAgent);
    operations.logClassPath();
}
Also used : ISystemOperations(com.axway.ats.core.system.model.ISystemOperations) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 8 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SystemOperations method getJvmMbeans.

/**
     * @param host the address of the host machine
     * @param jmxPort the jmx port
     * 
     * @return all MBeans with their attributes and type
     * @throws SystemOperationException
     */
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
    JMXConnector jmxCon = null;
    try {
        // Connect to JMXConnector
        JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
        jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
        jmxCon.connect();
        // Access the MBean
        MBeanServerConnection con = jmxCon.getMBeanServerConnection();
        Set<ObjectName> queryResults = con.queryNames(null, null);
        StringBuilder results = new StringBuilder();
        for (ObjectName theName : queryResults) {
            results.append("\n---");
            results.append("\nMBean name: " + theName.getCanonicalName());
            MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
            for (MBeanAttributeInfo attribute : attributes) {
                if (attribute.getType() != null) {
                    if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
                        if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
                            results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                    } else {
                        results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                        CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
                        if (comdata != null) {
                            for (String key : comdata.getCompositeType().keySet()) {
                                Object value = comdata.get(key);
                                if (value instanceof Integer || value instanceof Double || value instanceof Long)
                                    results.append("\r      " + key + " | " + value.getClass());
                            }
                        }
                    }
                }
            }
        }
        return results.toString();
    } catch (Exception e) {
        throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
    } finally {
        if (jmxCon != null)
            try {
                jmxCon.close();
            } catch (IOException e) {
                log.error("JMX connection was not closed!");
            }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SystemOperationException(com.axway.ats.common.system.SystemOperationException) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) SystemOperationException(com.axway.ats.common.system.SystemOperationException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 9 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class SystemOperations method isListening.

/**
    * Check if some process is listening on some port on some host. 
    * Note that we cannot give the name of the listening process.
    * 
    * @param host host address
    * @param port port number
    * @param timeout timeout value in milliseconds
    * @return <code>true</code> if the address is listening on this port
    * @throws SystemOperationException when the target host is unknown
    */
@PublicAtsApi
public boolean isListening(@Validate(name = "host", type = ValidationType.STRING_NOT_EMPTY) String host, @Validate(name = "port", type = ValidationType.NUMBER_PORT_NUMBER) int port, @Validate(name = "timeout", type = ValidationType.NUMBER_POSITIVE) int timeout) {
    // validate input parameters
    new Validator().validateMethodParameters(new Object[] { host, port, timeout });
    // execute action
    ISystemOperations operations = getOperationsImplementationFor(atsAgent);
    return operations.isListening(host, port, timeout);
}
Also used : ISystemOperations(com.axway.ats.core.system.model.ISystemOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 10 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class XmlText method replace.

/**
     * Replace a XML element.
     *
     * @param xpath XPath , pointing to a XML element
     * @param object the new XML element
     * @return this instance
     * @throws XMLException
     */
@PublicAtsApi
public XmlText replace(String xpath, Object object) throws XMLException {
    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }
    if (object == null) {
        throw new XMLException("Null object is not allowed for replacement." + "If you want to remove existing XML element, use XMLText.remove().");
    }
    Element newElement = null;
    if (object instanceof XmlText) {
        newElement = ((XmlText) object).root;
    }
    if (object instanceof String) {
        if (StringUtils.isNullOrEmpty((String) object)) {
            throw new XMLException("Null/empty String object is not allowed for replacement." + "If you want to remove existing XML element, use XMLText.remove().");
        }
        newElement = new XmlText((String) object).root;
    }
    if (newElement == null) {
        throw new XMLException("Given object for replacing an existing one is from invallid class instance. " + "Use String or XMLText instances only.");
    }
    Element oldElement = findElement(xpath);
    if (oldElement != null) {
        if (oldElement.isRootElement()) {
            throw new XMLException("You cannot replace the root element of the XML document.");
        }
        Element parent = oldElement.getParent();
        if (parent != null) {
            parent.elements().set(parent.elements().indexOf(oldElement), newElement);
        } else {
            throw new XMLException("Parent for element with xpath '" + xpath + "' could not be found.");
        }
    } else {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }
    return this;
}
Also used : XMLException(com.axway.ats.common.xml.XMLException) Element(org.dom4j.Element) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)409 Validator (com.axway.ats.core.validation.Validator)66 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)60 WebElement (org.openqa.selenium.WebElement)57 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)44 HiddenHtmlElementState (com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PackageException (com.axway.ats.action.objects.model.PackageException)31 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)31 MessagingException (javax.mail.MessagingException)31 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)24 ArrayList (java.util.ArrayList)18 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)16 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)16 IOException (java.io.IOException)16 JTableFixture (org.fest.swing.fixture.JTableFixture)16 Actions (org.openqa.selenium.interactions.Actions)16 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)15 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)15 XMLException (com.axway.ats.common.xml.XMLException)14