-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revamp mock listener and mock model (#10)
- Loading branch information
Sérgio Martins
committed
Apr 18, 2020
1 parent
1530e82
commit bd08e60
Showing
12 changed files
with
406 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,40 @@ | ||
package utils.mocks; | ||
|
||
import com.google.gson.Gson; | ||
import utils.mocks.model.MockRequest; | ||
import utils.mocks.model.MockResponse; | ||
|
||
/*** | ||
* Concrete definition of a mock. | ||
* To be used by a mapper; from json to {@link MockDefinition} object. | ||
* <p> | ||
* A mock is represented by a {@link MockRequest} and by a {@link MockResponse} | ||
* </p> | ||
*/ | ||
@SuppressWarnings("unused") | ||
public final class MockDefinition { | ||
|
||
/** | ||
* Holds the mocked request params. | ||
* Represents the mocked request. | ||
*/ | ||
private Request request; | ||
private MockRequest request; | ||
|
||
/** | ||
* Holds the mocked response params. | ||
* Represents the mocked response. | ||
*/ | ||
private Response response; | ||
private MockResponse response; | ||
|
||
public Request getRequest() { | ||
public MockRequest getRequest() { | ||
return request; | ||
} | ||
|
||
public Response getResponse() { | ||
public MockResponse getResponse() { | ||
return response; | ||
} | ||
|
||
public void setResponse(Response response) { | ||
public void setResponse(MockResponse response) { | ||
this.response = response; | ||
} | ||
|
||
public void setRequest(Request request) { | ||
public void setRequest(MockRequest request) { | ||
this.request = request; | ||
} | ||
|
||
public static class Request { | ||
|
||
/** | ||
* Contains the mapping request path. | ||
*/ | ||
private String path; | ||
|
||
/** | ||
* Contains the type of request (e.g. GET, POST). | ||
*/ | ||
private String method; | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public String getMethod() { | ||
return method; | ||
} | ||
|
||
public void setMethod(String method) { | ||
this.method = method; | ||
} | ||
} | ||
|
||
public static class Response { | ||
|
||
/** | ||
* Holds the whole response body. | ||
*/ | ||
private Object body; | ||
|
||
/** | ||
* Status code response. | ||
*/ | ||
private Integer statusCode; | ||
|
||
public String getBody() { | ||
return new Gson().toJson(this.body); | ||
} | ||
|
||
public void setBody(Object body) { | ||
this.body = body; | ||
} | ||
|
||
public Integer getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public void setStatusCode(Integer statusCode) { | ||
this.statusCode = statusCode; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
package utils.mocks; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.gson.Gson; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
/** | ||
* Single responsibility of parsing json files into objects. | ||
* Single responsibility of parsing json files into {@link MockDefinition} objects. | ||
*/ | ||
public final class MockParser { | ||
|
||
public static MockDefinition toObject(String path) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
InputStream inputStream = MockParser.class.getResourceAsStream(path); | ||
try { | ||
return mapper.readValue(inputStream, MockDefinition.class); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
public static MockDefinition toObject(String jsonPath) { | ||
return new Gson().fromJson(new InputStreamReader(MockParser.class.getResourceAsStream(jsonPath)), MockDefinition.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package utils.mocks.model; | ||
|
||
/** | ||
* Concrete definition of a mocked cookie. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class MockCookie { | ||
|
||
/** | ||
* Cookie name. | ||
*/ | ||
private String name; | ||
|
||
/** | ||
* Cookie value. | ||
*/ | ||
private String value; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package utils.mocks.model; | ||
|
||
/** | ||
* Concrete definition of a mocked header. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public final class MockHeader { | ||
|
||
/** | ||
* Header name. | ||
*/ | ||
private String name; | ||
|
||
/** | ||
* Header values. | ||
*/ | ||
private String values; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getValues() { | ||
return values; | ||
} | ||
|
||
public void setValues(String values) { | ||
this.values = values; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/utils/mocks/model/MockQueryStringParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utils.mocks.model; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Concrete definition of a mocked query parameter. | ||
*/ | ||
@SuppressWarnings("unused") | ||
public final class MockQueryStringParameter { | ||
|
||
/** | ||
* Query parameter name. | ||
*/ | ||
private String name; | ||
|
||
/** | ||
* Query parameter values. | ||
*/ | ||
private List<String> values; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public List<String> getValues() { | ||
return values; | ||
} | ||
|
||
public void setValues(List<String> values) { | ||
this.values = values; | ||
} | ||
} |
Oops, something went wrong.