Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 206 additions & 60 deletions doc/style/style.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.41.1</version>
<version>8.42</version>
</dependency>
</dependencies>
<executions>
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/frameworkium/core/api/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
*/
public interface Endpoint {

/**
* Calls {@link String#format(String, Object...)} on the url.
*
* @param params Arguments referenced by the format specifiers in the url.
* @return A formatted String representing the URL of the given constant.
*/
String getUrl(Object... params);
/**
* Calls {@link String#format(String, Object...)} on the url.
*
* @param params Arguments referenced by the format specifiers in the url.
* @return A formatted String representing the URL of the given constant.
*/
String getUrl(Object... params);
}
50 changes: 26 additions & 24 deletions src/main/java/com/frameworkium/core/api/dto/AbstractDTO.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
package com.frameworkium.core.api.dto;

import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.builder.*;

import java.io.Serializable;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public abstract class AbstractDTO<T> implements Serializable, Cloneable {

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
@SuppressWarnings("unchecked")
protected T clone() throws CloneNotSupportedException {
try {
return (T) SerializationUtils.clone(this);
} catch (Exception e) {
throw new CloneNotSupportedException(e.getMessage());
}
@Override
@SuppressWarnings("unchecked")
protected T clone() throws CloneNotSupportedException {
try {
return (T) SerializationUtils.clone(this);
} catch (Exception e) {
throw new CloneNotSupportedException(e.getMessage());
}
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(
this, ToStringStyle.SHORT_PREFIX_STYLE);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(
this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
205 changes: 102 additions & 103 deletions src/main/java/com/frameworkium/core/api/services/BaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,124 +7,123 @@
import io.restassured.response.ExtractableResponse;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public abstract class BaseService {

protected static final Logger logger = LogManager.getLogger();
protected static final Logger logger = LogManager.getLogger();

static {
if (Property.PROXY.isSpecified()) {
try {
RestAssured.proxy(new URI(Property.PROXY.getValue()));
} catch (URISyntaxException e) {
logger.error("Proxy URI given is in an invalid format."
+ " Ensure it's in the format of: http://{hostname}:{port}", e);
}
}
static {
if (Property.PROXY.isSpecified()) {
try {
RestAssured.proxy(new URI(Property.PROXY.getValue()));
} catch (URISyntaxException e) {
logger.error("Proxy URI given is in an invalid format."
+ " Ensure it's in the format of: http://{hostname}:{port}", e);
}
}
}

/**
* Used to define the RequestSpecification common to all operations
* defined in the given service. For example:
* <pre><code>RestAssured.given().proxy(...)</code></pre>
*
* @return the RestAssured RequestSpecification with appropriate defaults
*/
protected abstract RequestSpecification getRequestSpec();
/**
* Used to define the RequestSpecification common to all operations
* defined in the given service. For example:
* <pre><code>RestAssured.given().proxy(...)</code></pre>
*
* @return the RestAssured RequestSpecification with appropriate defaults
*/
protected abstract RequestSpecification getRequestSpec();

/**
* Used to define the RequestSpecification common to all operations
* defined in the given service. For example:
* <pre>
* <code>getDefaultRequestSpecification().then().response().statusCode(200);</code>
* </pre>
*
* @return the RestAssured ResponseSpecification with appropriate defaults
*/
protected abstract ResponseSpecification getResponseSpec();
/**
* Used to define the RequestSpecification common to all operations
* defined in the given service. For example:
* <pre>
* <code>getDefaultRequestSpecification().then().response().statusCode(200);</code>
* </pre>
*
* @return the RestAssured ResponseSpecification with appropriate defaults
*/
protected abstract ResponseSpecification getResponseSpec();

/**
* Performs GET request of the URL.
*
* @return The response from the request
*/
protected ExtractableResponse get(String url) {
return get(ImmutableMap.of(), url);
}
/**
* Performs GET request of the URL.
*
* @return The response from the request
*/
protected ExtractableResponse get(String url) {
return get(ImmutableMap.of(), url);
}

/**
* Performs GET request of the URL with parameters.
*
* @param params the GET parameters
* @param url the URL to GET
* @return The response from the request
*/
protected ExtractableResponse get(Map<String, ?> params, String url) {
return request(Method.GET, params, url);
}
/**
* Performs GET request of the URL with parameters.
*
* @param params the GET parameters
* @param url the URL to GET
* @return The response from the request
*/
protected ExtractableResponse get(Map<String, ?> params, String url) {
return request(Method.GET, params, url);
}

/**
* Performs GET request of the URL.
*
* @return The response from the request
* @deprecated use {@link #get(String)}
*/
@Deprecated
protected ExtractableResponse request(String url) {
return request(ImmutableMap.of(), url);
}
/**
* Performs GET request of the URL.
*
* @return The response from the request
* @deprecated use {@link #get(String)}
*/
@Deprecated
protected ExtractableResponse request(String url) {
return request(ImmutableMap.of(), url);
}

/**
* Performs GET request of the URL with parameters.
*
* @return The response from the request
* @deprecated use {@link #get(Map, String)}
*/
@Deprecated
protected ExtractableResponse request(Map<String, ?> params, String url) {
return request(Method.GET, params, url);
}
/**
* Performs GET request of the URL with parameters.
*
* @return The response from the request
* @deprecated use {@link #get(Map, String)}
*/
@Deprecated
protected ExtractableResponse request(Map<String, ?> params, String url) {
return request(Method.GET, params, url);
}

/**
* Performs specified HTTP verb request of the URL with parameters.
*
* @param method the HTTP method to request
* @param params the request parameters
* @param url the URL to request
* @return The response from the request
*/
protected ExtractableResponse request(Method method, Map<String, ?> params, String url) {
return getRequestSpec()
.params(params)
.when()
.request(method, url)
.then()
.spec(getResponseSpec())
.extract();
}
/**
* Performs specified HTTP verb request of the URL with parameters.
*
* @param method the HTTP method to request
* @param params the request parameters
* @param url the URL to request
* @return The response from the request
*/
protected ExtractableResponse request(Method method, Map<String, ?> params, String url) {
return getRequestSpec()
.params(params)
.when()
.request(method, url)
.then()
.spec(getResponseSpec())
.extract();
}

/**
* Performs specified HTTP verb request of the URL with the given body.
*
* @param method the HTTP method to request
* @param body the body of the request
* @param url the URL to request
* @return The response from the request
*/
protected ExtractableResponse request(Method method, Object body, String url) {
return getRequestSpec()
.when()
.body(body)
.request(method, url)
.then()
.spec(getResponseSpec())
.extract();
}
/**
* Performs specified HTTP verb request of the URL with the given body.
*
* @param method the HTTP method to request
* @param body the body of the request
* @param url the URL to request
* @return The response from the request
*/
protected ExtractableResponse request(Method method, Object body, String url) {
return getRequestSpec()
.when()
.body(body)
.request(method, url)
.then()
.spec(getResponseSpec())
.extract();
}

}
26 changes: 16 additions & 10 deletions src/main/java/com/frameworkium/core/api/tests/BaseAPITest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package com.frameworkium.core.api.tests;

import com.frameworkium.core.common.listeners.*;
import com.frameworkium.core.common.listeners.MethodInterceptor;
import com.frameworkium.core.common.listeners.ResultLoggerListener;
import com.frameworkium.core.common.listeners.TestListener;
import com.frameworkium.core.common.reporting.allure.AllureProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.*;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({MethodInterceptor.class,
TestListener.class,
ResultLoggerListener.class})
TestListener.class,
ResultLoggerListener.class})
@Test(groups = "base-api")
public abstract class BaseAPITest {

protected final Logger logger = LogManager.getLogger(this);
protected final Logger logger = LogManager.getLogger(this);

/** Creates the allure properties for the report, after the test run. */
@AfterSuite(alwaysRun = true)
public static void createAllureProperties() {
AllureProperties.createAPI();
}
/**
* Creates the allure properties for the report, after the test run.
*/
@AfterSuite(alwaysRun = true)
public static void createAllureProperties() {
AllureProperties.createAPI();
}

}
Loading