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
35 changes: 35 additions & 0 deletions src/main/java/com/frameworkium/core/api/dto/AbstractDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.frameworkium.core.api.dto;

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

import java.io.Serializable;

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

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

@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.toString());
}
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(
this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.frameworkium.core.api.dto

import spock.lang.Specification

class AbstractDTOSpec extends Specification {

def sut = new TopLevelDTO()

def "two different DTOs with the same data are equal but not =="() {
given:
def sut2 = new TopLevelDTO()
expect:
sut.equals(sut2)
!sut.is(sut2) // == in Java
sut.hashCode() == sut2.hashCode()
}

def "two different DTOs with different data are not equal"() {
given:
def sut2 = new TopLevelDTO()
sut2.lowLevelDTO.data = "foo"
expect:
sut != sut2
!sut.is(sut2) // == in Java
sut.hashCode() != sut2.hashCode()
}

def "Cloning a DTOs makes a deep not shallow clone"() {
given:
def clone = sut.clone()
when:
clone.lowLevelDTO.data = "something"
then:
sut.lowLevelDTO.data != "something"
}

def "toString() creates readable output"() {
expect:
sut.toString() == 'TopLevelDTO[lowLevelDTO=LowLevelDTO[data=initial]]'
}

}
5 changes: 5 additions & 0 deletions src/test/java/com/frameworkium/core/api/dto/LowLevelDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.frameworkium.core.api.dto;

public class LowLevelDTO extends AbstractDTO<LowLevelDTO> {
String data = "initial";
}
5 changes: 5 additions & 0 deletions src/test/java/com/frameworkium/core/api/dto/TopLevelDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.frameworkium.core.api.dto;

public class TopLevelDTO extends AbstractDTO<TopLevelDTO> {
LowLevelDTO lowLevelDTO = new LowLevelDTO();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.frameworkium.integration.ai.capture.api.dto.executions;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.frameworkium.core.api.dto.AbstractDTO;

public class Browser extends AbstractDTO<Browser> {

/** Browser message. */
public class Browser {
public String name;
public String version;

Expand All @@ -14,34 +13,4 @@ public static Browser newInstance() {
browser.version = "49.0";
return browser;
}

@Override
public String toString() {
return "Browser{" +
"name='" + name + '\'' +
", version='" + version + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

Browser browser = (Browser) o;

return new EqualsBuilder()
.append(name, browser.name)
.append(version, browser.version)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(name)
.append(version)
.toHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.frameworkium.integration.ai.capture.api.dto.executions;

import com.frameworkium.core.api.dto.AbstractDTO;

import java.net.InetAddress;
import java.net.UnknownHostException;

/** Execution message. */
public class Execution {
public class Execution extends AbstractDTO<Execution> {

// used in the create
public String testID;
Expand All @@ -19,7 +20,7 @@ public class Execution {
public String executionID;

/**
* Using the static factory method pattern instead of using the constructor
* Using the static factory method pattern instead of using a constructor
* to ensure this class can be used for both input and output. Also allows
* for multiple different creation methods in one place.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.frameworkium.integration.ai.capture.api.dto.executions;

import com.frameworkium.core.api.dto.AbstractDTO;

/** Created execution message. */
public class ExecutionID {
public class ExecutionID extends AbstractDTO<ExecutionID> {

public String executionID;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.frameworkium.integration.ai.capture.api.dto.executions;

import com.frameworkium.core.api.dto.AbstractDTO;

import java.util.List;

/** Executions message */
public class ExecutionResults {
public class ExecutionResults extends AbstractDTO<ExecutionResults> {

public List<Execution> results;
public int total;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.frameworkium.integration.ai.capture.api.dto.executions;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.frameworkium.core.api.dto.AbstractDTO;

public class SoftwareUnderTest extends AbstractDTO<SoftwareUnderTest> {

/** Represents the Software under test message. */
public class SoftwareUnderTest {
public String name;
public String version;

Expand All @@ -15,33 +14,4 @@ public static SoftwareUnderTest newInstance() {
return sut;
}

@Override
public String toString() {
return "SoftwareUnderTest{" +
"name='" + name + '\'' +
", version='" + version + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

SoftwareUnderTest that = (SoftwareUnderTest) o;

return new EqualsBuilder()
.append(name, that.name)
.append(version, that.version)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(name)
.append(version)
.toHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.frameworkium.integration.heroku.restfulbooker.api.constant;

import com.frameworkium.core.api.Endpoint;

/** The various Endpoints of Restful Booker. */
public enum BookerEndpoint implements Endpoint {

BASE_URI("https://restful-booker.herokuapp.com"),
PING("/ping"),
BOOKING("/booking"),
BOOKING_ID("/booking/%d"),
AUTH("/auth");

private String url;

BookerEndpoint(String url) {
this.url = url;
}

/**
* @param params Arguments referenced by the format specifiers in the url.
* @return A formatted String representing the URL of the given constant.
*/
@Override
public String getUrl(Object... params) {
return String.format(url, params);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.frameworkium.integration.heroku.restfulbooker.api.dto.booking;

import com.frameworkium.core.api.dto.AbstractDTO;

import java.util.concurrent.ThreadLocalRandom;

public class Booking extends AbstractDTO {
public String firstname;
public String lastname;
public long totalprice;
public boolean depositpaid;
public BookingDates bookingdates;
public String additionalneeds;

public static Booking newInstance() {
ThreadLocalRandom random = ThreadLocalRandom.current();
int randInt = random.nextInt();
Booking booking = new Booking();
booking.firstname = "firstname" + randInt;
booking.lastname = "lastname" + randInt;
booking.totalprice = randInt;
booking.depositpaid = random.nextBoolean();
booking.bookingdates = BookingDates.newInstance();
booking.additionalneeds = null;
return booking;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.frameworkium.integration.heroku.restfulbooker.api.dto.booking;

import com.frameworkium.core.api.dto.AbstractDTO;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class BookingDates extends AbstractDTO {

public static final DateTimeFormatter FORMAT =
DateTimeFormatter.ofPattern("YYYY-MM-DD");

public String checkin;
public String checkout;

public static BookingDates newInstance() {
BookingDates dates = new BookingDates();
dates.checkin = LocalDate.now().plusDays(1).format(FORMAT);
dates.checkout = LocalDate.now().plusDays(10).format(FORMAT);
return dates;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.frameworkium.integration.heroku.restfulbooker.api.dto.booking;

import com.frameworkium.core.api.dto.AbstractDTO;

public class BookingID extends AbstractDTO {

public int bookingid;

public static BookingID of(int bookingID) {
BookingID id = new BookingID();
id.bookingid = bookingID;
return id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.frameworkium.integration.heroku.restfulbooker.api.dto.booking;

import com.frameworkium.core.api.dto.AbstractDTO;

public class BookingResponse extends AbstractDTO {
public Booking booking;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.frameworkium.integration.heroku.restfulbooker.api.dto.booking;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class SearchParamsMapper {

private SearchParamsMapper() {
// hide constructor of mapper
}

public static Map<String, String> namesOfBooking(Booking booking) {
return ImmutableMap.of(
"firstname", booking.firstname,
"lastname", booking.lastname);
}

public static Map<String, String> datesOfBooking(Booking booking) {
return ImmutableMap.of(
"checkin", booking.bookingdates.checkin,
"checkout", booking.bookingdates.checkout);
}
}
Loading