Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Soap Webservice Support #38

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public enum ConfigSection {
*/
SELENIUM_MAQS("SeleniumMaqs"),

/**
* The default soap namespace section.
*/
SOAP_NAMESPACE_MAQS("SoapMaqsNameSpaces"),

/**
* The default soap maqs section.
*/
SOAP_MAQS("SoapMaqs"),

/**
* The default web service section.
*/
Expand Down
6 changes: 6 additions & 0 deletions maqs-webservices/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@
<ProxyAddress>127.0.0.1:8001</ProxyAddress>
<ProxyPort>8080</ProxyPort>
</WebServiceMaqs>
<SoapMaqs>
<SoapPrefix>soapenv</SoapPrefix>
</SoapMaqs>
<SoapMaqsNameSpaces>
<gs>http://spring.io/guides/gs-producing-web-service</gs>
</SoapMaqsNameSpaces>
</configuration>
33 changes: 33 additions & 0 deletions maqs-webservices/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

<properties>
<spring.web.version>5.3.15</spring.web.version>
<jackson.version>2.13.2</jackson.version>
<spring.web.version>5.3.16</spring.web.version>

<javax.activation.version>1.1.1</javax.activation.version>
<glassfish.jaxb.version>3.0.2</glassfish.jaxb.version>
<jaxb.api.version>2.4.0-b180830.0359</jaxb.api.version>
<soap.saaj-api.version>1.3.5</soap.saaj-api.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -57,5 +64,31 @@
<artifactId>spring-web</artifactId>
<version>${spring.web.version}</version>
</dependency>
<!-- SOAP Web Services Dependencies -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${javax.activation.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${glassfish.jaxb.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>${glassfish.jaxb.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.api.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>${soap.saaj-api.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.cognizantsoftvision.maqs.base.BaseExtendableTest;
import com.cognizantsoftvision.maqs.utilities.helper.StringProcessor;
import com.cognizantsoftvision.maqs.utilities.logging.Logger;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpRequest;
import org.testng.ITestResult;
Expand Down Expand Up @@ -47,7 +46,7 @@ protected void beforeLoggingTeardown(ITestResult resultType) {
* @throws URISyntaxException when URI is incorrect
*/
protected WebServiceDriver getWebServiceClient() throws URISyntaxException {
return new WebServiceDriver(HttpRequest.newBuilder(URI.create(WebServiceConfig.getWebServiceUri())));
return new WebServiceDriver(HttpRequest.newBuilder(WebServiceConfig.getWebServiceUri()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.cognizantsoftvision.maqs.utilities.helper.Config;
import com.cognizantsoftvision.maqs.utilities.helper.ConfigSection;
import java.net.URI;

/**
* The Web Service Configuration class.
Expand All @@ -25,18 +26,27 @@ private WebServiceConfig() {
*
* @return A String containing the URI for the WebService to test
*/
public static String getWebServiceUri() {
public static String getWebServiceURIString() {
return Config.getValueForSection(WEBSERVICE_SECTION, "WebServiceUri");
}

/**
* Grabs the URI for the Web Service.
*
* @return A String containing the URI for the WebService to test
*/
public static URI getWebServiceUri() {
return URI.create(getWebServiceURIString());
}

/**
* Gets the expected time out in seconds.
*
* @return the Timeout value for the web service test, or -1 if none are configured
*/
public static int getWebServiceTimeOut() {
return Integer
.parseInt(Config.getValueForSection(WEBSERVICE_SECTION, "WebServiceTimeout", "-1"));
return Integer.parseInt(
Config.getValueForSection(WEBSERVICE_SECTION, "WebServiceTimeout", "-1"));
}

/**
Expand All @@ -63,7 +73,7 @@ public static String getProxyAddress() {
* @return The Proxy Port
*/
public static int getProxyPort() {
return Integer
.parseInt(Config.getValueForSection(WEBSERVICE_SECTION, "ProxyPort", "-1"));
return Integer.parseInt(
Config.getValueForSection(WEBSERVICE_SECTION, "ProxyPort", "-1"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2022 (C) Cognizant SoftVision, All rights Reserved
*/

package com.cognizantsoftvision.maqs.webservices.soap;

import com.cognizantsoftvision.maqs.base.BaseExtendableTest;
import com.cognizantsoftvision.maqs.utilities.helper.StringProcessor;
import com.cognizantsoftvision.maqs.utilities.logging.Logger;
import com.cognizantsoftvision.maqs.webservices.WebServiceConfig;
import com.cognizantsoftvision.maqs.webservices.WebServiceTestObject;
import java.net.URISyntaxException;
import javax.xml.soap.SOAPException;
import org.testng.ITestResult;

/**
* The Base Soap Web Service Test class.
*/
public class BaseSoapWebServiceTest extends BaseExtendableTest<WebServiceTestObject> {

/**
* Get the Web Service Driver.
*
* @return WebServiceDriver
*/
public SoapWebServiceDriver getWebServiceDriver() {
return (SoapWebServiceDriver) this.getTestObject().getWebServiceDriver();
}

/**
* Set the webServiceDriver.
*
* @param webServiceDriver the webservice driver object
*/
public void setWebServiceDriver(SoapWebServiceDriver webServiceDriver) {
this.getTestObject().setWebServiceDriver(webServiceDriver);
}

/*
* (non-Javadoc)
*
* @see com.cognizantsoftvision.maqs.utilities.BaseTest.BaseTest# beforeLoggingTeardown
* (org.testng.ITestResult)
*/
@Override
protected void beforeLoggingTeardown(ITestResult resultType) {
// There is no logging tear-down required before
}

/**
* Gets new WebServiceDriver.
*
* @return WebServiceDriver
* @throws URISyntaxException when URI is incorrect
*/
protected SoapWebServiceDriver getWebServiceClient() throws URISyntaxException, SOAPException {
return new SoapWebServiceDriver(WebServiceConfig.getWebServiceUri());
}

/**
* Creates a new test object.
*/
@Override
protected void createNewTestObject() {
Logger logger = this.createLogger();
try {
WebServiceTestObject webServiceTestObject = new WebServiceTestObject(
this.getWebServiceClient(), logger, this.getFullyQualifiedTestClassName());
this.setTestObject(webServiceTestObject);
} catch (URISyntaxException | SOAPException e) {
getLogger().logMessage(StringProcessor.safeFormatter(
"Test Object could not be created: %s", e.getMessage()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 (C) Cognizant SoftVision, All rights Reserved
*/

package com.cognizantsoftvision.maqs.webservices.soap;

import com.cognizantsoftvision.maqs.utilities.helper.Config;
import com.cognizantsoftvision.maqs.utilities.helper.ConfigSection;
import java.util.Map;

/**
* The Soap Config class.
*/
public final class SoapConfig {

private SoapConfig() {
}

/**
* Gets the Soap Prefix from the config file.
*
* @return the string of the soap prefix
*/
public static String getSoapPrefix() {
return Config.getValueForSection(ConfigSection.SOAP_MAQS, "SoapPrefix");
}

/**
* Gets the Soap namespaces from the config.
*
* @return the Soap namespaces in a map format
*/
public static Map<String, String> getSoapNamespaces() {
return Config.getSection(ConfigSection.SOAP_NAMESPACE_MAQS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 (C) Cognizant SoftVision, All rights Reserved
*/

package com.cognizantsoftvision.maqs.webservices.soap;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

/**
* The Soap Utilities class.
*/
public class SoapUtilities {

private SoapUtilities() {

}

/**
* Gets the response Body as an Object.
*
* @param httpResponse the http response
* @param unMarshaller the unmarshaller for the soap process
* @return the response object
* @throws SOAPException if a SOAP exception is thrown
* @throws IOException if an IO exception is thrown
* @throws JAXBException if a JAXB exception is thrown
*/
public static Object getResponseBodyAsObjects(HttpResponse<String> httpResponse, Unmarshaller unMarshaller)
throws SOAPException, IOException, JAXBException {
SOAPMessage soapResp = MessageFactory.newInstance()
.createMessage(null, new ByteArrayInputStream(
httpResponse.body().getBytes(StandardCharsets.UTF_8)));
return unMarshaller.unmarshal(soapResp.getSOAPBody().extractContentAsDocument());
}
}
Loading