repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/StubServiceExchangeTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.service.model;
public class StubServiceExchangeTest {
private StubServiceExchange instance1;
private StubServiceExchange instance2;
@Before
public void before() { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/StubServiceExchangeTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.service.model;
public class StubServiceExchangeTest {
private StubServiceExchange instance1;
private StubServiceExchange instance2;
@Before
public void before() { | StubExchange exchange1 = new StubExchange(); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/StubServiceExchangeTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.service.model;
public class StubServiceExchangeTest {
private StubServiceExchange instance1;
private StubServiceExchange instance2;
@Before
public void before() {
StubExchange exchange1 = new StubExchange();
StubExchange exchange2 = new StubExchange();
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/StubServiceExchangeTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.service.model;
public class StubServiceExchangeTest {
private StubServiceExchange instance1;
private StubServiceExchange instance2;
@Before
public void before() {
StubExchange exchange1 = new StubExchange();
StubExchange exchange2 = new StubExchange();
| exchange1.setRequest(new StubRequest()); |
Sensis/http-stub-server | play/app/controllers/GenericStubController.java | // Path: play/app/au/com/sensis/stubby/play/Transformer.java
// public class Transformer {
//
// public static List<HttpHeader> fromPlayHeaders(Map<String, Http.Header> headers) {
// List<HttpHeader> result = new ArrayList<HttpHeader>();
// for (Http.Header playHeader : headers.values()) {
// HttpHeader header = new HttpHeader();
// header.name = playHeader.name.toLowerCase(); // Play already does this, but just to be sure.
// header.values = playHeader.values;
// result.add(header);
// }
// return result;
// }
//
// public static List<HttpParam> fromPlayParams(Scope.Params params) {
// List<HttpParam> result = new ArrayList<HttpParam>();
// for (Map.Entry<String,String[]> entry : params.all().entrySet()) {
// if (entry.getKey().equals("body") // Play! puts the request body in this
// || entry.getKey().equals("_ignore")) { // created by 'catch all' route
// continue;
// }
// HttpParam param = new HttpParam();
// param.name = entry.getKey();
// param.values = Arrays.asList(entry.getValue());
// result.add(param);
// }
// return result;
// }
//
// public static HttpRequest fromPlayRequest(Http.Request request) {
// HttpRequest result = new HttpRequest();
// try {
// result.path = new URI(request.url).getPath();
// } catch (URISyntaxException e) {
// throw new RuntimeException(e);
// }
// result.method = request.method.toUpperCase();
// if (!result.method.equals("GET")) { // GET requests don't (shouldn't) have a body or content type
// result.contentType = request.contentType;
// try {
// result.body = IOUtils.toString(request.body);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
// for (HttpParam param : fromPlayParams(request.params)) {
// result.params.put(param.name, param);
// }
// for (HttpHeader header : fromPlayHeaders(request.headers)) {
// result.headers.put(header.name, header);
// }
// return result;
// }
//
// public static void populatePlayResponse(HttpMessage message, Http.Response response) throws IOException {
// response.contentType = message.contentType;
// response.status = message.statusCode;
// if (message.body instanceof String) {
// response.print(message.body);
// } else {
// response.print(new ObjectMapper().writeValueAsString(message.body)); // assume deserialised JSON (ie, a Map)
// }
// for (HttpHeader header : message.headers.values()) {
// for (String value : header.values) {
// Http.Header playHeader = response.headers.get(header.name);
// if (playHeader != null) {
// playHeader.values.add(value);
// } else {
// response.setHeader(header.name, value);
// }
// }
// }
// }
//
// }
| import java.util.LinkedList;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import play.mvc.Controller;
import au.com.sensis.stubby.HttpMessage;
import au.com.sensis.stubby.StubbedResponse;
import au.com.sensis.stubby.play.Transformer;
import au.com.sensis.stubby.utils.UriUtils; | package controllers;
/*
* Generic stubbed controller that can be used to stub any URL
* Stubbed URLs can contain wildcards, eg: /path/*?param=*
*/
public class GenericStubController extends Controller {
private static final Logger LOGGER = Logger.getLogger(GenericStubController.class);
public static LinkedList<StubbedResponse> RESPONSES = new LinkedList<StubbedResponse>();
public static LinkedList<HttpMessage> REQUESTS = new LinkedList<HttpMessage>();
private static ObjectMapper JSON = new ObjectMapper();
public static synchronized void match() throws Exception { | // Path: play/app/au/com/sensis/stubby/play/Transformer.java
// public class Transformer {
//
// public static List<HttpHeader> fromPlayHeaders(Map<String, Http.Header> headers) {
// List<HttpHeader> result = new ArrayList<HttpHeader>();
// for (Http.Header playHeader : headers.values()) {
// HttpHeader header = new HttpHeader();
// header.name = playHeader.name.toLowerCase(); // Play already does this, but just to be sure.
// header.values = playHeader.values;
// result.add(header);
// }
// return result;
// }
//
// public static List<HttpParam> fromPlayParams(Scope.Params params) {
// List<HttpParam> result = new ArrayList<HttpParam>();
// for (Map.Entry<String,String[]> entry : params.all().entrySet()) {
// if (entry.getKey().equals("body") // Play! puts the request body in this
// || entry.getKey().equals("_ignore")) { // created by 'catch all' route
// continue;
// }
// HttpParam param = new HttpParam();
// param.name = entry.getKey();
// param.values = Arrays.asList(entry.getValue());
// result.add(param);
// }
// return result;
// }
//
// public static HttpRequest fromPlayRequest(Http.Request request) {
// HttpRequest result = new HttpRequest();
// try {
// result.path = new URI(request.url).getPath();
// } catch (URISyntaxException e) {
// throw new RuntimeException(e);
// }
// result.method = request.method.toUpperCase();
// if (!result.method.equals("GET")) { // GET requests don't (shouldn't) have a body or content type
// result.contentType = request.contentType;
// try {
// result.body = IOUtils.toString(request.body);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
// for (HttpParam param : fromPlayParams(request.params)) {
// result.params.put(param.name, param);
// }
// for (HttpHeader header : fromPlayHeaders(request.headers)) {
// result.headers.put(header.name, header);
// }
// return result;
// }
//
// public static void populatePlayResponse(HttpMessage message, Http.Response response) throws IOException {
// response.contentType = message.contentType;
// response.status = message.statusCode;
// if (message.body instanceof String) {
// response.print(message.body);
// } else {
// response.print(new ObjectMapper().writeValueAsString(message.body)); // assume deserialised JSON (ie, a Map)
// }
// for (HttpHeader header : message.headers.values()) {
// for (String value : header.values) {
// Http.Header playHeader = response.headers.get(header.name);
// if (playHeader != null) {
// playHeader.values.add(value);
// } else {
// response.setHeader(header.name, value);
// }
// }
// }
// }
//
// }
// Path: play/app/controllers/GenericStubController.java
import java.util.LinkedList;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import play.mvc.Controller;
import au.com.sensis.stubby.HttpMessage;
import au.com.sensis.stubby.StubbedResponse;
import au.com.sensis.stubby.play.Transformer;
import au.com.sensis.stubby.utils.UriUtils;
package controllers;
/*
* Generic stubbed controller that can be used to stub any URL
* Stubbed URLs can contain wildcards, eg: /path/*?param=*
*/
public class GenericStubController extends Controller {
private static final Logger LOGGER = Logger.getLogger(GenericStubController.class);
public static LinkedList<StubbedResponse> RESPONSES = new LinkedList<StubbedResponse>();
public static LinkedList<HttpMessage> REQUESTS = new LinkedList<HttpMessage>();
private static ObjectMapper JSON = new ObjectMapper();
public static synchronized void match() throws Exception { | HttpMessage lastRequest = Transformer.fromPlayRequest(request); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.utils;
public class RequestFilterBuilder {
private static final String METHOD_PARAM = "method";
private static final String PATH_PARAM = "path";
private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.utils;
public class RequestFilterBuilder {
private static final String METHOD_PARAM = "method";
private static final String PATH_PARAM = "path";
private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
| private StubRequest filter; |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.utils;
public class RequestFilterBuilder {
private static final String METHOD_PARAM = "method";
private static final String PATH_PARAM = "path";
private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
private StubRequest filter;
public RequestFilterBuilder() {
this.filter = new StubRequest(); | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.utils;
public class RequestFilterBuilder {
private static final String METHOD_PARAM = "method";
private static final String PATH_PARAM = "path";
private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
private StubRequest filter;
public RequestFilterBuilder() {
this.filter = new StubRequest(); | this.filter.setParams(new ArrayList<StubParam>()); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java | // Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
import au.com.sensis.stubby.utils.JsonUtils; | }
public List<String> getHeaders(String name) {
List<String> result = new ArrayList<String>();
for (Header header : response.getHeaders(name)) {
result.add(header.getValue());
}
return result;
}
public GenericClientResponse assertOk() {
if (!isOk()) {
throw new RuntimeException("Server returned " + getStatus());
}
return this;
}
public GenericClientResponse assertBody() {
if (!hasBody()) {
throw new RuntimeException("Response body expected");
}
return this;
}
public boolean isOk() {
return getStatus() == HttpStatus.SC_OK;
}
public <T> T getJson(Class<T> type) {
assertBody(); | // Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.util.EntityUtils;
import au.com.sensis.stubby.utils.JsonUtils;
}
public List<String> getHeaders(String name) {
List<String> result = new ArrayList<String>();
for (Header header : response.getHeaders(name)) {
result.add(header.getValue());
}
return result;
}
public GenericClientResponse assertOk() {
if (!isOk()) {
throw new RuntimeException("Server returned " + getStatus());
}
return this;
}
public GenericClientResponse assertBody() {
if (!hasBody()) {
throw new RuntimeException("Response body expected");
}
return this;
}
public boolean isOk() {
return getStatus() == HttpStatus.SC_OK;
}
public <T> T getJson(Class<T> type) {
assertBody(); | return JsonUtils.deserialize(body, type); |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/Transformer.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.servlet;
/*
* Transform between stubby & Servlet HTTP structures
*/
public class Transformer {
@SuppressWarnings("unchecked") | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/Transformer.java
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.servlet;
/*
* Transform between stubby & Servlet HTTP structures
*/
public class Transformer {
@SuppressWarnings("unchecked") | public static List<StubParam> fromServletHeaders(HttpServletRequest request) { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/ScriptTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
public class ScriptTest extends TestBase {
private static final String TEST_SCRIPT =
"if (request.getParam('run') == 'true') { exchange.response.status = 202; exchange.response.body = exchange.request.getParam('run'); }";
private void givenTestScript() {
builder().setRequestPath("/script/bar").setResponseStatus(201).setResponseBody("original").setScript(TEST_SCRIPT).stub();
}
@Test
public void testRunFalse() {
givenTestScript();
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/ScriptTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
public class ScriptTest extends TestBase {
private static final String TEST_SCRIPT =
"if (request.getParam('run') == 'true') { exchange.response.status = 202; exchange.response.body = exchange.request.getParam('run'); }";
private void givenTestScript() {
builder().setRequestPath("/script/bar").setResponseStatus(201).setResponseBody("original").setScript(TEST_SCRIPT).stub();
}
@Test
public void testRunFalse() {
givenTestScript();
| GenericClientResponse result = client.executeGet("/script/bar?run=false"); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/model/StubServiceExchange.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.service.model;
public class StubServiceExchange { // wrap exchange model with some extra runtime info
private static final Logger LOGGER = Logger.getLogger(StubServiceExchange.class);
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/model/StubServiceExchange.java
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.service.model;
public class StubServiceExchange { // wrap exchange model with some extra runtime info
private static final Logger LOGGER = Logger.getLogger(StubServiceExchange.class);
| private StubExchange exchange; |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/model/StubServiceExchange.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.service.model;
public class StubServiceExchange { // wrap exchange model with some extra runtime info
private static final Logger LOGGER = Logger.getLogger(StubServiceExchange.class);
private StubExchange exchange;
private RequestPattern requestPattern;
private List<MatchResult> attempts;
public StubServiceExchange(StubExchange exchange) {
this.exchange = exchange;
this.requestPattern = new RequestPattern(exchange.getRequest());
this.attempts = new ArrayList<MatchResult>();
}
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/model/StubServiceExchange.java
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.service.model;
public class StubServiceExchange { // wrap exchange model with some extra runtime info
private static final Logger LOGGER = Logger.getLogger(StubServiceExchange.class);
private StubExchange exchange;
private RequestPattern requestPattern;
private List<MatchResult> attempts;
public StubServiceExchange(StubExchange exchange) {
this.exchange = exchange;
this.requestPattern = new RequestPattern(exchange.getRequest());
this.attempts = new ArrayList<MatchResult>();
}
| public MatchResult matches(StubRequest message) throws URISyntaxException { |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/RequestPatternTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.service.model;
public class RequestPatternTest {
private static final List<StubParam> EMPTY_PARAMS = Collections.emptyList();
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/RequestPatternTest.java
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.service.model;
public class RequestPatternTest {
private static final List<StubParam> EMPTY_PARAMS = Collections.emptyList();
| private StubRequest stubbedRequest; |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/js/ScriptWorld.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptWorld { // the world as JavaScript sees it
private StubRequest request; | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/js/ScriptWorld.java
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptWorld { // the world as JavaScript sees it
private StubRequest request; | private StubResponse response; |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/js/ScriptWorld.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptWorld { // the world as JavaScript sees it
private StubRequest request;
private StubResponse response;
private Long delay;
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/js/ScriptWorld.java
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptWorld { // the world as JavaScript sees it
private StubRequest request;
private StubResponse response;
private Long delay;
| public ScriptWorld(StubRequest request, StubExchange response) { // copy everything so the script can't change the server state |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/MatchResultTest.java | // Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import au.com.sensis.stubby.service.model.MatchField.MatchType; | package au.com.sensis.stubby.service.model;
@RunWith(MockitoJUnitRunner.class)
public class MatchResultTest {
@Mock
private MatchField field1;
@Mock
private MatchField field2;
@Mock
private MatchField field3;
private MatchResult result1;
private MatchResult result2;
@Before
public void before() {
when(field1.score()).thenReturn(1);
when(field2.score()).thenReturn(2);
when(field3.score()).thenReturn(3);
| // Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/MatchResultTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import au.com.sensis.stubby.service.model.MatchField.MatchType;
package au.com.sensis.stubby.service.model;
@RunWith(MockitoJUnitRunner.class)
public class MatchResultTest {
@Mock
private MatchField field1;
@Mock
private MatchField field2;
@Mock
private MatchField field3;
private MatchResult result1;
private MatchResult result2;
@Before
public void before() {
when(field1.score()).thenReturn(1);
when(field2.score()).thenReturn(2);
when(field3.score()).thenReturn(3);
| when(field1.getMatchType()).thenReturn(MatchType.MATCH_FAILURE); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType; | package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType;
package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() { | request = new StubRequest(); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType; | package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() {
request = new StubRequest();
request.setHeader("Content-Type", "text/plain");
request.setBody("foo");
}
private void assertRequestMatches(String patternStr) {
TextBodyPattern pattern = new TextBodyPattern(patternStr);
MatchField result = pattern.matches(request);
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType;
package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() {
request = new StubRequest();
request.setHeader("Content-Type", "text/plain");
request.setBody("foo");
}
private void assertRequestMatches(String patternStr) {
TextBodyPattern pattern = new TextBodyPattern(patternStr);
MatchField result = pattern.matches(request);
| assertEquals(FieldType.BODY, result.getFieldType()); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType; | package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() {
request = new StubRequest();
request.setHeader("Content-Type", "text/plain");
request.setBody("foo");
}
private void assertRequestMatches(String patternStr) {
TextBodyPattern pattern = new TextBodyPattern(patternStr);
MatchField result = pattern.matches(request);
assertEquals(FieldType.BODY, result.getFieldType()); | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum MatchType {
// NOT_FOUND,
// MATCH_FAILURE,
// MATCH;
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/TextBodyPatternTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import au.com.sensis.stubby.service.model.MatchField.MatchType;
package au.com.sensis.stubby.service.model;
public class TextBodyPatternTest {
private StubMessage request;
@Before
public void before() {
request = new StubRequest();
request.setHeader("Content-Type", "text/plain");
request.setBody("foo");
}
private void assertRequestMatches(String patternStr) {
TextBodyPattern pattern = new TextBodyPattern(patternStr);
MatchField result = pattern.matches(request);
assertEquals(FieldType.BODY, result.getFieldType()); | assertEquals(MatchType.MATCH, result.getMatchType()); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/utils/RequestFilterBuilderTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest; | package au.com.sensis.stubby.utils;
public class RequestFilterBuilderTest {
private List<StubParam> params;
private RequestFilterBuilder builder;
@Before
public void before() {
params = new ArrayList<StubParam>();
builder = new RequestFilterBuilder();
}
@Test
public void testMethod() {
params.add(new StubParam("method", "G.T"));
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/utils/RequestFilterBuilderTest.java
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
package au.com.sensis.stubby.utils;
public class RequestFilterBuilderTest {
private List<StubParam> params;
private RequestFilterBuilder builder;
@Before
public void before() {
params = new ArrayList<StubParam>();
builder = new RequestFilterBuilder();
}
@Test
public void testMethod() {
params.add(new StubParam("method", "G.T"));
| StubRequest filter = builder.fromParams(params).getFilter(); |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/StubContextListener.java | // Path: core/src/main/java/au/com/sensis/stubby/service/StubService.java
// public class StubService {
//
// private static final Logger LOGGER = Logger.getLogger(StubService.class);
//
// private LinkedList<StubServiceExchange> responses = new LinkedList<StubServiceExchange>();
// private LinkedList<StubRequest> requests = new LinkedList<StubRequest>();
//
// public synchronized void addResponse(StubExchange exchange) {
// LOGGER.debug("Adding response: " + JsonUtils.prettyPrint(exchange));
// StubServiceExchange internal = new StubServiceExchange(exchange);
// responses.remove(internal); // remove existing stubed request (ie, will never match anymore)
// responses.addFirst(internal); // ensure most recent match first
// }
//
// public synchronized StubServiceResult findMatch(StubRequest request) {
// try {
// LOGGER.trace("Got request: " + JsonUtils.prettyPrint(request));
// requests.addFirst(request);
// List<MatchResult> attempts = new ArrayList<MatchResult>();
// for (StubServiceExchange response : responses) {
// MatchResult matchResult = response.matches(request);
// attempts.add(matchResult);
// if (matchResult.matches()) {
// LOGGER.info("Matched: " + request.getPath() + "");
// StubExchange exchange = response.getExchange();
// if (exchange.getScript() != null) {
// ScriptWorld world = new ScriptWorld(request, exchange); // creates deep copies of objects
// new Script(exchange.getScript()).execute(world);
// return new StubServiceResult(
// attempts, world.getResponse(), world.getDelay());
// } else {
// return new StubServiceResult(
// attempts, exchange.getResponse(), exchange.getDelay());
// }
// }
// }
// LOGGER.info("Didn't match: " + request.getPath());
// this.notifyAll(); // inform any waiting threads that a new request has come in
// return new StubServiceResult(attempts); // no match (empty list)
// } catch (Exception e) {
// throw new RuntimeException("Error matching request", e);
// }
// }
//
// public synchronized StubServiceExchange getResponse(int index) throws NotFoundException {
// try {
// return responses.get(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Response does not exist: " + index);
// }
// }
//
// public synchronized List<StubServiceExchange> getResponses() {
// return responses;
// }
//
// public synchronized void deleteResponse(int index) throws NotFoundException {
// LOGGER.trace("Deleting response: " + index);
// try {
// responses.remove(index);
// } catch (IndexOutOfBoundsException e) {
// throw new RuntimeException("Response does not exist: " + index);
// }
// }
//
// public synchronized void deleteResponses() {
// LOGGER.trace("Deleting all responses");
// responses.clear();
// }
//
// public synchronized StubRequest getRequest(int index) throws NotFoundException {
// try {
// return requests.get(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Response does not exist: " + index);
// }
// }
//
// public synchronized List<StubRequest> findRequests(StubRequest filter, long timeout) { // blocking call
// long remaining = timeout;
// while (remaining > 0) {
// List<StubRequest> result = findRequests(filter);
// if (result.isEmpty()) {
// try {
// long start = System.currentTimeMillis();
// this.wait(remaining); // wait for a request to come in, or time to expire
// remaining -= System.currentTimeMillis() - start;
// } catch (InterruptedException e) {
// throw new RuntimeException("Interrupted while waiting for request");
// }
// } else {
// return result;
// }
// }
// return Collections.emptyList();
// }
//
// public synchronized List<StubRequest> findRequests(StubRequest filter) {
// RequestPattern pattern = new RequestPattern(filter);
// List<StubRequest> result = new ArrayList<StubRequest>();
// for (StubRequest request : requests) {
// if (pattern.match(request).matches()) {
// result.add(request);
// }
// }
// return result;
// }
//
// public synchronized List<StubRequest> getRequests() {
// return requests;
// }
//
// public synchronized void deleteRequest(int index) throws NotFoundException {
// LOGGER.trace("Deleting request: " + index);
// try {
// requests.remove(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Request does not exist: " + index);
// }
// }
//
// public synchronized void deleteRequests() {
// LOGGER.trace("Deleting all requests");
// requests.clear();
// }
//
// }
| import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import au.com.sensis.stubby.service.StubService; | package au.com.sensis.stubby.servlet;
public class StubContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) { | // Path: core/src/main/java/au/com/sensis/stubby/service/StubService.java
// public class StubService {
//
// private static final Logger LOGGER = Logger.getLogger(StubService.class);
//
// private LinkedList<StubServiceExchange> responses = new LinkedList<StubServiceExchange>();
// private LinkedList<StubRequest> requests = new LinkedList<StubRequest>();
//
// public synchronized void addResponse(StubExchange exchange) {
// LOGGER.debug("Adding response: " + JsonUtils.prettyPrint(exchange));
// StubServiceExchange internal = new StubServiceExchange(exchange);
// responses.remove(internal); // remove existing stubed request (ie, will never match anymore)
// responses.addFirst(internal); // ensure most recent match first
// }
//
// public synchronized StubServiceResult findMatch(StubRequest request) {
// try {
// LOGGER.trace("Got request: " + JsonUtils.prettyPrint(request));
// requests.addFirst(request);
// List<MatchResult> attempts = new ArrayList<MatchResult>();
// for (StubServiceExchange response : responses) {
// MatchResult matchResult = response.matches(request);
// attempts.add(matchResult);
// if (matchResult.matches()) {
// LOGGER.info("Matched: " + request.getPath() + "");
// StubExchange exchange = response.getExchange();
// if (exchange.getScript() != null) {
// ScriptWorld world = new ScriptWorld(request, exchange); // creates deep copies of objects
// new Script(exchange.getScript()).execute(world);
// return new StubServiceResult(
// attempts, world.getResponse(), world.getDelay());
// } else {
// return new StubServiceResult(
// attempts, exchange.getResponse(), exchange.getDelay());
// }
// }
// }
// LOGGER.info("Didn't match: " + request.getPath());
// this.notifyAll(); // inform any waiting threads that a new request has come in
// return new StubServiceResult(attempts); // no match (empty list)
// } catch (Exception e) {
// throw new RuntimeException("Error matching request", e);
// }
// }
//
// public synchronized StubServiceExchange getResponse(int index) throws NotFoundException {
// try {
// return responses.get(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Response does not exist: " + index);
// }
// }
//
// public synchronized List<StubServiceExchange> getResponses() {
// return responses;
// }
//
// public synchronized void deleteResponse(int index) throws NotFoundException {
// LOGGER.trace("Deleting response: " + index);
// try {
// responses.remove(index);
// } catch (IndexOutOfBoundsException e) {
// throw new RuntimeException("Response does not exist: " + index);
// }
// }
//
// public synchronized void deleteResponses() {
// LOGGER.trace("Deleting all responses");
// responses.clear();
// }
//
// public synchronized StubRequest getRequest(int index) throws NotFoundException {
// try {
// return requests.get(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Response does not exist: " + index);
// }
// }
//
// public synchronized List<StubRequest> findRequests(StubRequest filter, long timeout) { // blocking call
// long remaining = timeout;
// while (remaining > 0) {
// List<StubRequest> result = findRequests(filter);
// if (result.isEmpty()) {
// try {
// long start = System.currentTimeMillis();
// this.wait(remaining); // wait for a request to come in, or time to expire
// remaining -= System.currentTimeMillis() - start;
// } catch (InterruptedException e) {
// throw new RuntimeException("Interrupted while waiting for request");
// }
// } else {
// return result;
// }
// }
// return Collections.emptyList();
// }
//
// public synchronized List<StubRequest> findRequests(StubRequest filter) {
// RequestPattern pattern = new RequestPattern(filter);
// List<StubRequest> result = new ArrayList<StubRequest>();
// for (StubRequest request : requests) {
// if (pattern.match(request).matches()) {
// result.add(request);
// }
// }
// return result;
// }
//
// public synchronized List<StubRequest> getRequests() {
// return requests;
// }
//
// public synchronized void deleteRequest(int index) throws NotFoundException {
// LOGGER.trace("Deleting request: " + index);
// try {
// requests.remove(index);
// } catch (IndexOutOfBoundsException e) {
// throw new NotFoundException("Request does not exist: " + index);
// }
// }
//
// public synchronized void deleteRequests() {
// LOGGER.trace("Deleting all requests");
// requests.clear();
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/StubContextListener.java
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import au.com.sensis.stubby.service.StubService;
package au.com.sensis.stubby.servlet;
public class StubContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) { | event.getServletContext().setAttribute(AbstractStubServlet.SERVICE_CONTEXT_KEY, new StubService()); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/utils/HttpMessageUtilsTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage; | package au.com.sensis.stubby.utils;
public class HttpMessageUtilsTest {
@Test
public void testUpperCaseHeader() {
Assert.assertEquals("Header", HttpMessageUtils.upperCaseHeader("header"));
Assert.assertEquals("Header-Name", HttpMessageUtils.upperCaseHeader("header-name"));
Assert.assertEquals("X-Header-Name", HttpMessageUtils.upperCaseHeader("x-header-name"));
Assert.assertEquals("-X-Header-Name", HttpMessageUtils.upperCaseHeader("-x-header-name"));
}
@Test
public void testIsText() { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/utils/HttpMessageUtilsTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import au.com.sensis.stubby.model.StubMessage;
package au.com.sensis.stubby.utils;
public class HttpMessageUtilsTest {
@Test
public void testUpperCaseHeader() {
Assert.assertEquals("Header", HttpMessageUtils.upperCaseHeader("header"));
Assert.assertEquals("Header-Name", HttpMessageUtils.upperCaseHeader("header-name"));
Assert.assertEquals("X-Header-Name", HttpMessageUtils.upperCaseHeader("x-header-name"));
Assert.assertEquals("-X-Header-Name", HttpMessageUtils.upperCaseHeader("-x-header-name"));
}
@Test
public void testIsText() { | StubMessage message = new StubMessage() { }; |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
| import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder; | package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder;
package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
| private StubRequest createFilter(HttpServletRequest request) { |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
| import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder; | package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
private StubRequest createFilter(HttpServletRequest request) { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder;
package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
private StubRequest createFilter(HttpServletRequest request) { | List<StubParam> params = Transformer.fromServletParams(request); |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
| import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder; | package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
private StubRequest createFilter(HttpServletRequest request) {
List<StubParam> params = Transformer.fromServletParams(request); | // Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/RequestFilterBuilder.java
// public class RequestFilterBuilder {
//
// private static final String METHOD_PARAM = "method";
// private static final String PATH_PARAM = "path";
// private static final Pattern PARAM_PATTERN = Pattern.compile("^param\\[(.+)\\]$");
// private static final Pattern HEADER_PATTERN = Pattern.compile("^header\\[(.+)\\]$");
//
// private StubRequest filter;
//
// public RequestFilterBuilder() {
// this.filter = new StubRequest();
// this.filter.setParams(new ArrayList<StubParam>());
// this.filter.setHeaders(new ArrayList<StubParam>());
// }
//
// public RequestFilterBuilder fromParams(List<StubParam> params) {
// for (StubParam param : params) {
// addParam(param.getName(), param.getValue());
// }
// return this;
// }
//
// private void addParam(String name, String value) {
// if (METHOD_PARAM.equals(name)) {
// filter.setMethod(value);
// return;
// }
// if (PATH_PARAM.equals(name)) {
// filter.setPath(value);
// return;
// }
// Matcher matcher = PARAM_PATTERN.matcher(name);
// if (matcher.matches()) {
// String param = matcher.group(1);
// filter.getParams().add(new StubParam(param, value));
// return;
// }
// matcher = HEADER_PATTERN.matcher(name);
// if (matcher.matches()) {
// String header = matcher.group(1);
// filter.getHeaders().add(new StubParam(header, value));
// return;
// }
// }
//
// public StubRequest getFilter() {
// return filter;
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/RequestsServlet.java
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.RequestFilterBuilder;
package au.com.sensis.stubby.servlet;
/*
* Handles operations on requets collection (eg, 'DELETE /_control/requests')
*/
@SuppressWarnings("serial")
public class RequestsServlet extends AbstractStubServlet {
private StubRequest createFilter(HttpServletRequest request) {
List<StubParam> params = Transformer.fromServletParams(request); | return new RequestFilterBuilder().fromParams(params).getFilter(); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
public class ControlRequestTest extends TestBase {
@Test
public void testGetRequestOrder() {
client.executeGet("/test/1");
client.executeGet("/test/2");
assertEquals("/test/2", client.getRequest(0).path);
assertEquals("/test/1", client.getRequest(1).path);
}
@Test
public void testGetRequestsOrder() {
client.executeGet("/test/1");
client.executeGet("/test/2");
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
public class ControlRequestTest extends TestBase {
@Test
public void testGetRequestOrder() {
client.executeGet("/test/1");
client.executeGet("/test/2");
assertEquals("/test/2", client.getRequest(0).path);
assertEquals("/test/1", client.getRequest(1).path);
}
@Test
public void testGetRequestsOrder() {
client.executeGet("/test/1");
client.executeGet("/test/2");
| JsonRequestList requests = client.getRequests(); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase; | assertEquals(2, requests.size());
assertEquals("/test/2", requests.get(0).path);
assertEquals("/test/1", requests.get(1).path);
}
@Test
public void testGetRequestNotFound() {
client.executeGet("/test/1");
assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
}
@Test
public void testDeleteRequests() {
client.executeGet("/test/1");
assertEquals(1, client.getRequests().size());
client.deleteRequests();
assertEquals(0, client.getRequests().size());
}
@Test
public void testRequestDetails() {
HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
post.addHeader("X-Foo", "bar1");
post.addHeader("X-Foo", "bar2");
post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
client.execute(post);
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
assertEquals(2, requests.size());
assertEquals("/test/2", requests.get(0).path);
assertEquals("/test/1", requests.get(1).path);
}
@Test
public void testGetRequestNotFound() {
client.executeGet("/test/1");
assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
}
@Test
public void testDeleteRequests() {
client.executeGet("/test/1");
assertEquals(1, client.getRequests().size());
client.deleteRequests();
assertEquals(0, client.getRequests().size());
}
@Test
public void testRequestDetails() {
HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
post.addHeader("X-Foo", "bar1");
post.addHeader("X-Foo", "bar2");
post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
client.execute(post);
| JsonRequest request = client.getRequest(0); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase; | public void testGetRequestNotFound() {
client.executeGet("/test/1");
assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
}
@Test
public void testDeleteRequests() {
client.executeGet("/test/1");
assertEquals(1, client.getRequests().size());
client.deleteRequests();
assertEquals(0, client.getRequests().size());
}
@Test
public void testRequestDetails() {
HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
post.addHeader("X-Foo", "bar1");
post.addHeader("X-Foo", "bar2");
post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
client.execute(post);
JsonRequest request = client.getRequest(0);
assertEquals("POST", request.method);
assertEquals("/test/path", request.path);
assertEquals(2, request.params.size()); | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
//
// public String name;
// public String value;
//
// public JsonPair() { } // for Jackson
//
// public JsonPair(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// @Override
// public int hashCode() {
// return HashCodeBuilder.reflectionHashCode(this);
// }
//
// @Override
// public boolean equals(Object obj) {
// return EqualsBuilder.reflectionEquals(this, obj);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
public void testGetRequestNotFound() {
client.executeGet("/test/1");
assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
}
@Test
public void testDeleteRequests() {
client.executeGet("/test/1");
assertEquals(1, client.getRequests().size());
client.deleteRequests();
assertEquals(0, client.getRequests().size());
}
@Test
public void testRequestDetails() {
HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
post.addHeader("X-Foo", "bar1");
post.addHeader("X-Foo", "bar2");
post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
client.execute(post);
JsonRequest request = client.getRequest(0);
assertEquals("POST", request.method);
assertEquals("/test/path", request.path);
assertEquals(2, request.params.size()); | assertTrue(request.params.contains(new JsonPair("foo", "bar1"))); |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/ResponseServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/service/NotFoundException.java
// @SuppressWarnings("serial")
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String message) {
// super(message);
// }
//
// }
| import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.service.NotFoundException; | package au.com.sensis.stubby.servlet;
/*
* Handles operations on responses (eg, 'GET /_control/responses/<index>')
*/
@SuppressWarnings("serial")
public class ResponseServlet extends AbstractStubServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
returnJson(response, service().getResponse(getId(request))); | // Path: core/src/main/java/au/com/sensis/stubby/service/NotFoundException.java
// @SuppressWarnings("serial")
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String message) {
// super(message);
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/ResponseServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.service.NotFoundException;
package au.com.sensis.stubby.servlet;
/*
* Handles operations on responses (eg, 'GET /_control/responses/<index>')
*/
@SuppressWarnings("serial")
public class ResponseServlet extends AbstractStubServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
returnJson(response, service().getResponse(getId(request))); | } catch (NotFoundException e) { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
| import au.com.sensis.stubby.test.model.JsonExchange; | package au.com.sensis.stubby.test.client;
public class MessageBuilder {
private Client client; | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java
import au.com.sensis.stubby.test.model.JsonExchange;
package au.com.sensis.stubby.test.client;
public class MessageBuilder {
private Client client; | private JsonExchange exchange; |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/DuplicateRequestPatternTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java
// public class MessageBuilder {
//
// private Client client;
// private JsonExchange exchange;
//
// public MessageBuilder(Client client) {
// this.client = client;
// this.exchange = new JsonExchange();
// }
//
// public MessageBuilder setDelay(Long delay) {
// exchange.delay = delay;
// return this;
// }
//
// public MessageBuilder setScript(String script) {
// exchange.script = script;
// return this;
// }
//
// public MessageBuilder setRequestMethod(String method) {
// exchange.request().method = method;
// return this;
// }
//
// public MessageBuilder setRequestPath(String path) {
// exchange.request().path = path;
// return this;
// }
//
// public MessageBuilder setResponseStatus(Integer status) {
// exchange.response().status = status;
// return this;
// }
//
// public MessageBuilder setResponseBody(Object body) {
// exchange.response().body = body;
// return this;
// }
//
// public MessageBuilder setRequestBody(Object body) {
// exchange.request().body = body;
// return this;
// }
//
// public MessageBuilder addRequestParam(String name, String value) {
// exchange.request().addParam(name, value);
// return this;
// }
//
// public MessageBuilder setRequestParam(String name, String value) {
// exchange.request().setParam(name, value);
// return this;
// }
//
// public MessageBuilder setRequestHeader(String name, String value) {
// exchange.request().setHeader(name, value);
// return this;
// }
//
// public MessageBuilder addRequestHeader(String name, String value) {
// exchange.request().addHeader(name, value);
// return this;
// }
//
// public MessageBuilder setResponseHeader(String name, String value) {
// exchange.response().setHeader(name, value);
// return this;
// }
//
// public MessageBuilder addResponseHeader(String name, String value) {
// exchange.response().addHeader(name, value);
// return this;
// }
//
// public MessageBuilder stub() {
// client.postMessage(exchange);
// return this;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import org.junit.Test;
import au.com.sensis.stubby.test.client.MessageBuilder;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
/*
* When two identical request patterns are stubbed, the previous one should be deleted
* and the new one inserted at the start of the list.
*/
public class DuplicateRequestPatternTest extends TestBase {
private void assertSame(MessageBuilder... messages) {
int status = 1; // use status code to identify requests
for (MessageBuilder message : messages) {
message.setResponseStatus(status).stub();
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java
// public class MessageBuilder {
//
// private Client client;
// private JsonExchange exchange;
//
// public MessageBuilder(Client client) {
// this.client = client;
// this.exchange = new JsonExchange();
// }
//
// public MessageBuilder setDelay(Long delay) {
// exchange.delay = delay;
// return this;
// }
//
// public MessageBuilder setScript(String script) {
// exchange.script = script;
// return this;
// }
//
// public MessageBuilder setRequestMethod(String method) {
// exchange.request().method = method;
// return this;
// }
//
// public MessageBuilder setRequestPath(String path) {
// exchange.request().path = path;
// return this;
// }
//
// public MessageBuilder setResponseStatus(Integer status) {
// exchange.response().status = status;
// return this;
// }
//
// public MessageBuilder setResponseBody(Object body) {
// exchange.response().body = body;
// return this;
// }
//
// public MessageBuilder setRequestBody(Object body) {
// exchange.request().body = body;
// return this;
// }
//
// public MessageBuilder addRequestParam(String name, String value) {
// exchange.request().addParam(name, value);
// return this;
// }
//
// public MessageBuilder setRequestParam(String name, String value) {
// exchange.request().setParam(name, value);
// return this;
// }
//
// public MessageBuilder setRequestHeader(String name, String value) {
// exchange.request().setHeader(name, value);
// return this;
// }
//
// public MessageBuilder addRequestHeader(String name, String value) {
// exchange.request().addHeader(name, value);
// return this;
// }
//
// public MessageBuilder setResponseHeader(String name, String value) {
// exchange.response().setHeader(name, value);
// return this;
// }
//
// public MessageBuilder addResponseHeader(String name, String value) {
// exchange.response().addHeader(name, value);
// return this;
// }
//
// public MessageBuilder stub() {
// client.postMessage(exchange);
// return this;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/DuplicateRequestPatternTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import au.com.sensis.stubby.test.client.MessageBuilder;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
/*
* When two identical request patterns are stubbed, the previous one should be deleted
* and the new one inserted at the start of the list.
*/
public class DuplicateRequestPatternTest extends TestBase {
private void assertSame(MessageBuilder... messages) {
int status = 1; // use status code to identify requests
for (MessageBuilder message : messages) {
message.setResponseStatus(status).stub();
| JsonStubbedExchangeList responses = responses(); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java | // Path: core/src/main/java/au/com/sensis/stubby/utils/EqualsUtils.java
// public class EqualsUtils {
//
// public static boolean safeEquals(Object a, Object b) {
// return (a == null && b == null) || (a != null && a.equals(b));
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.util.regex.Pattern;
import org.apache.commons.lang.builder.EqualsBuilder;
import au.com.sensis.stubby.utils.EqualsUtils;
import au.com.sensis.stubby.utils.JsonUtils; | public int score() { // attempt to give some weight to matches so we can guess 'near misses'
switch (matchType) {
case NOT_FOUND:
return 0;
case MATCH_FAILURE:
switch (fieldType) {
case PATH:
case METHOD:
return 0; // these guys always exist, so the fact that they're found is unimportant
case HEADER:
case QUERY_PARAM:
case BODY:
return 1; // if found but didn't match
default:
throw new RuntimeException(); // impossible
}
case MATCH:
switch (fieldType) {
case PATH:
return 5; // path is most important in the match
default:
return 2;
}
default:
throw new RuntimeException(); // impossible
}
}
@Override
public String toString() { | // Path: core/src/main/java/au/com/sensis/stubby/utils/EqualsUtils.java
// public class EqualsUtils {
//
// public static boolean safeEquals(Object a, Object b) {
// return (a == null && b == null) || (a != null && a.equals(b));
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
import java.util.regex.Pattern;
import org.apache.commons.lang.builder.EqualsBuilder;
import au.com.sensis.stubby.utils.EqualsUtils;
import au.com.sensis.stubby.utils.JsonUtils;
public int score() { // attempt to give some weight to matches so we can guess 'near misses'
switch (matchType) {
case NOT_FOUND:
return 0;
case MATCH_FAILURE:
switch (fieldType) {
case PATH:
case METHOD:
return 0; // these guys always exist, so the fact that they're found is unimportant
case HEADER:
case QUERY_PARAM:
case BODY:
return 1; // if found but didn't match
default:
throw new RuntimeException(); // impossible
}
case MATCH:
switch (fieldType) {
case PATH:
return 5; // path is most important in the match
default:
return 2;
}
default:
throw new RuntimeException(); // impossible
}
}
@Override
public String toString() { | return JsonUtils.serialize(this); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java | // Path: core/src/main/java/au/com/sensis/stubby/utils/EqualsUtils.java
// public class EqualsUtils {
//
// public static boolean safeEquals(Object a, Object b) {
// return (a == null && b == null) || (a != null && a.equals(b));
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.util.regex.Pattern;
import org.apache.commons.lang.builder.EqualsBuilder;
import au.com.sensis.stubby.utils.EqualsUtils;
import au.com.sensis.stubby.utils.JsonUtils; | return 1; // if found but didn't match
default:
throw new RuntimeException(); // impossible
}
case MATCH:
switch (fieldType) {
case PATH:
return 5; // path is most important in the match
default:
return 2;
}
default:
throw new RuntimeException(); // impossible
}
}
@Override
public String toString() {
return JsonUtils.serialize(this);
}
@Override
public boolean equals(Object object) { // only used in tests
if (object instanceof MatchField) {
MatchField other = (MatchField) object;
if (!fieldName.equals(other.fieldName)
|| !fieldType.equals(other.fieldType)
|| !matchType.equals(other.matchType)) {
return false;
} | // Path: core/src/main/java/au/com/sensis/stubby/utils/EqualsUtils.java
// public class EqualsUtils {
//
// public static boolean safeEquals(Object a, Object b) {
// return (a == null && b == null) || (a != null && a.equals(b));
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
import java.util.regex.Pattern;
import org.apache.commons.lang.builder.EqualsBuilder;
import au.com.sensis.stubby.utils.EqualsUtils;
import au.com.sensis.stubby.utils.JsonUtils;
return 1; // if found but didn't match
default:
throw new RuntimeException(); // impossible
}
case MATCH:
switch (fieldType) {
case PATH:
return 5; // path is most important in the match
default:
return 2;
}
default:
throw new RuntimeException(); // impossible
}
}
@Override
public String toString() {
return JsonUtils.serialize(this);
}
@Override
public boolean equals(Object object) { // only used in tests
if (object instanceof MatchField) {
MatchField other = (MatchField) object;
if (!fieldName.equals(other.fieldName)
|| !fieldType.equals(other.fieldType)
|| !matchType.equals(other.matchType)) {
return false;
} | if (!EqualsUtils.safeEquals(message, other.message)) { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/VersionTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertTrue;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
public class VersionTest extends TestBase {
public static final class VersionResponse {
public String version;
}
@Test
public void testGetVersion() { | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/VersionTest.java
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
public class VersionTest extends TestBase {
public static final class VersionResponse {
public String version;
}
@Test
public void testGetVersion() { | GenericClientResponse response = client.executeGet("/_control/version").assertOk(); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptWorldTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptWorldTest {
private StubRequest request; | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptWorldTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptWorldTest {
private StubRequest request; | private StubExchange response; |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptWorldTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptWorldTest {
private StubRequest request;
private StubExchange response;
@Before
public void before() {
request = new StubRequest();
request.setPath("/request/path");
response = new StubExchange(); | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptWorldTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptWorldTest {
private StubRequest request;
private StubExchange response;
@Before
public void before() {
request = new StubRequest();
request.setPath("/request/path");
response = new StubExchange(); | response.setResponse(new StubResponse()); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/service/model/MatchFieldTest.java | // Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
| import au.com.sensis.stubby.service.model.MatchField.FieldType;
import static org.junit.Assert.assertEquals;
import java.util.regex.Pattern;
import org.junit.Test; | package au.com.sensis.stubby.service.model;
public class MatchFieldTest {
@Test
public void ensurePatternsMatch() { | // Path: core/src/main/java/au/com/sensis/stubby/service/model/MatchField.java
// public enum FieldType {
// PATH,
// METHOD,
// QUERY_PARAM,
// HEADER,
// BODY;
// }
// Path: core/src/test/java/au/com/sensis/stubby/service/model/MatchFieldTest.java
import au.com.sensis.stubby.service.model.MatchField.FieldType;
import static org.junit.Assert.assertEquals;
import java.util.regex.Pattern;
import org.junit.Test;
package au.com.sensis.stubby.service.model;
public class MatchFieldTest {
@Test
public void ensurePatternsMatch() { | MatchField field1 = new MatchField(FieldType.BODY, "foo", Pattern.compile(".*")).asMatchFailure("bar"); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/MatchResponseTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
public class MatchResponseTest extends TestBase {
@Test
public void testAllFields() {
builder()
.setRequestPath("/.*")
.setResponseStatus(201)
.addResponseHeader("X-Foo", "bar1")
.addResponseHeader("X-Foo", "bar2") // two values for single name
.addResponseHeader("x-foo", "bar3; bar4") // check case-insensitivity
.setResponseBody("response body")
.stub();
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/GenericClientResponse.java
// public class GenericClientResponse {
//
// private HttpResponse response;
// private String body;
//
// public GenericClientResponse(HttpResponse response) {
// this.response = response;
// this.body = consumeBody(response); // always read body in to memory
// }
//
// private static String consumeBody(HttpResponse response) {
// try {
// if (response.getEntity() != null && response.getEntity().getContent() != null) {
// return EntityUtils.toString(response.getEntity(), "UTF-8"); // releases connection
// } else {
// return null; // no body
// }
// } catch (IOException e) {
// throw new RuntimeException("Error reading response body", e);
// }
// }
//
// public boolean hasBody() {
// return body != null;
// }
//
// public int getStatus() {
// return response.getStatusLine().getStatusCode();
// }
//
// public String getHeader(String name) {
// if (response.getFirstHeader(name) != null) {
// return response.getFirstHeader(name).getValue();
// } else {
// return null;
// }
// }
//
// public List<String> getHeaders(String name) {
// List<String> result = new ArrayList<String>();
// for (Header header : response.getHeaders(name)) {
// result.add(header.getValue());
// }
// return result;
// }
//
// public GenericClientResponse assertOk() {
// if (!isOk()) {
// throw new RuntimeException("Server returned " + getStatus());
// }
// return this;
// }
//
// public GenericClientResponse assertBody() {
// if (!hasBody()) {
// throw new RuntimeException("Response body expected");
// }
// return this;
// }
//
// public boolean isOk() {
// return getStatus() == HttpStatus.SC_OK;
// }
//
// public <T> T getJson(Class<T> type) {
// assertBody();
// return JsonUtils.deserialize(body, type);
// }
//
// public String getText() {
// assertBody();
// return body;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/MatchResponseTest.java
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import au.com.sensis.stubby.test.client.GenericClientResponse;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
public class MatchResponseTest extends TestBase {
@Test
public void testAllFields() {
builder()
.setRequestPath("/.*")
.setResponseStatus(201)
.addResponseHeader("X-Foo", "bar1")
.addResponseHeader("X-Foo", "bar2") // two values for single name
.addResponseHeader("x-foo", "bar3; bar4") // check case-insensitivity
.setResponseBody("response body")
.stub();
| GenericClientResponse response = client.executeGet("/test"); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/FindRequestTest.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
| import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.client.methods.HttpPost;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase; | package au.com.sensis.stubby.test;
public class FindRequestTest extends TestBase {
@Before
public void makeRequests() {
client.executeGet("/test1");
client.executeGet("/test2?foo=bar");
client.executeGet("/test3?foo=bar1&foo=bar2");
client.executeDelete("/test4");
HttpPost test5 = new HttpPost(client.makeUri("/test5"));
test5.addHeader("X-Foo", "bar");
client.execute(test5);
HttpPost test6 = new HttpPost(client.makeUri("/test6"));
test6.addHeader("X-Foo", "bar1");
test6.addHeader("X-Foo", "bar2");
client.execute(test6);
}
@Test
public void testFindAll() { | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
//
// private static final String P_TEST_SERVER = "test.server"; // server to test against
//
// protected Client client;
//
// @Before
// public void before() {
// String testServer = System.getProperty(P_TEST_SERVER);
//
// client = new Client(testServer);
// client.reset();
// }
//
// @After
// public void after() {
// client.close();
// }
//
// protected void postFile(String filename) {
// String path = "/tests/" + filename;
// InputStream resource = getClass().getResourceAsStream(path);
// if (resource != null) {
// try {
// client.postMessage(IOUtils.toString(resource));
// } catch (IOException e) {
// throw new RuntimeException("Error posting file", e);
// }
// } else {
// throw new RuntimeException("Resource not found: " + path);
// }
// }
//
// protected String makeUri(String path) {
// return client.makeUri(path);
// }
//
// protected void close(HttpResponse response) {
// HttpClientUtils.closeQuietly(response);
// }
//
// protected GenericClientResponse execute(HttpUriRequest request) {
// return client.execute(request);
// }
//
// protected Client client() {
// return client;
// }
//
// protected JsonStubbedExchangeList responses() {
// return client.getResponses();
// }
//
// protected void assertOk(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_OK, response);
// }
//
// protected void assertNotFound(GenericClientResponse response) {
// assertStatus(HttpStatus.SC_NOT_FOUND, response);
// }
//
// protected void assertStatus(int status, GenericClientResponse response) {
// Assert.assertEquals(status, response.getStatus());
// }
//
// protected MessageBuilder builder() {
// return new MessageBuilder(client);
// }
//
// protected void assertHasHeader(JsonMessage request, String name, String value) {
// for (JsonPair header : request.headers) {
// if (header.name.equalsIgnoreCase(name)
// && header.value.equals(value)) {
// return;
// }
// }
// fail();
// }
//
// protected void assumeNotTravisCi() {
// assumeFalse("Running as Travis CI", isTravisCi());
// }
//
// protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
// return "true".equals(System.getenv("TRAVIS"));
// }
//
// protected void assertTimeTaken(long started, long ended, long expected) {
// double tolerance = 500; // 1/2 second tolerance
//
// if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
// assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
// }
// }
//
// protected long now() {
// return System.currentTimeMillis();
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/FindRequestTest.java
import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.client.methods.HttpPost;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;
public class FindRequestTest extends TestBase {
@Before
public void makeRequests() {
client.executeGet("/test1");
client.executeGet("/test2?foo=bar");
client.executeGet("/test3?foo=bar1&foo=bar2");
client.executeDelete("/test4");
HttpPost test5 = new HttpPost(client.makeUri("/test5"));
test5.addHeader("X-Foo", "bar");
client.execute(test5);
HttpPost test6 = new HttpPost(client.makeUri("/test6"));
test6.addHeader("X-Foo", "bar1");
test6.addHeader("X-Foo", "bar2");
client.execute(test6);
}
@Test
public void testFindAll() { | JsonRequestList requests = client.findRequests(""); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/model/StubMessage.java | // Path: core/src/main/java/au/com/sensis/stubby/utils/DeepCopyUtils.java
// public class DeepCopyUtils {
//
// @SuppressWarnings("unchecked")
// public static <T> T deepCopy(T src) {
// try {
// ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// new ObjectOutputStream(outStream).writeObject(src);
// ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
// return (T)new ObjectInputStream(inStream).readObject();
// } catch (Exception e) {
// throw new RuntimeException("Error performing deep copy", e);
// }
// }
//
// }
| import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.codehaus.jackson.annotate.JsonIgnore;
import au.com.sensis.stubby.utils.DeepCopyUtils; | package au.com.sensis.stubby.model;
public abstract class StubMessage {
private List<StubParam> headers;
private Object body;
protected StubMessage() { }
protected StubMessage(StubMessage other) { // copy constructor | // Path: core/src/main/java/au/com/sensis/stubby/utils/DeepCopyUtils.java
// public class DeepCopyUtils {
//
// @SuppressWarnings("unchecked")
// public static <T> T deepCopy(T src) {
// try {
// ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// new ObjectOutputStream(outStream).writeObject(src);
// ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
// return (T)new ObjectInputStream(inStream).readObject();
// } catch (Exception e) {
// throw new RuntimeException("Error performing deep copy", e);
// }
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.codehaus.jackson.annotate.JsonIgnore;
import au.com.sensis.stubby.utils.DeepCopyUtils;
package au.com.sensis.stubby.model;
public abstract class StubMessage {
private List<StubParam> headers;
private Object body;
protected StubMessage() { }
protected StubMessage(StubMessage other) { // copy constructor | this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null; |
Sensis/http-stub-server | standalone/src/test/java/au/com/sensis/stubby/test/StandaloneSuiteTest.java | // Path: standalone/src/test/java/au/com/sensis/stubby/test/support/TestServer.java
// public class TestServer {
//
// public static final int FREE_PORT = 0; // let operating system choose a free port
// public static final int NUM_SERVER_WORKERS = 2;
//
// private static ServerInstance server;
//
// public static void start() {
// try {
// server = new HttpServerInstance(FREE_PORT, new ServerHandler(), Executors.newFixedThreadPool(NUM_SERVER_WORKERS));
// } catch (Exception e) {
// throw new RuntimeException("Error starting server", e);
// }
// }
//
// public static int getPort() {
// return server.getAddress().getPort();
// }
//
// public static boolean isRunning() {
// return (server != null);
// }
//
// }
| import org.junit.BeforeClass;
import au.com.sensis.stubby.test.support.TestServer; | package au.com.sensis.stubby.test;
public class StandaloneSuiteTest extends AllTests {
@BeforeClass
public static void setUp() { | // Path: standalone/src/test/java/au/com/sensis/stubby/test/support/TestServer.java
// public class TestServer {
//
// public static final int FREE_PORT = 0; // let operating system choose a free port
// public static final int NUM_SERVER_WORKERS = 2;
//
// private static ServerInstance server;
//
// public static void start() {
// try {
// server = new HttpServerInstance(FREE_PORT, new ServerHandler(), Executors.newFixedThreadPool(NUM_SERVER_WORKERS));
// } catch (Exception e) {
// throw new RuntimeException("Error starting server", e);
// }
// }
//
// public static int getPort() {
// return server.getAddress().getPort();
// }
//
// public static boolean isRunning() {
// return (server != null);
// }
//
// }
// Path: standalone/src/test/java/au/com/sensis/stubby/test/StandaloneSuiteTest.java
import org.junit.BeforeClass;
import au.com.sensis.stubby.test.support.TestServer;
package au.com.sensis.stubby.test;
public class StandaloneSuiteTest extends AllTests {
@BeforeClass
public static void setUp() { | if (!TestServer.isRunning()) { // keep running for all tests |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/RequestServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/service/NotFoundException.java
// @SuppressWarnings("serial")
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String message) {
// super(message);
// }
//
// }
| import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.service.NotFoundException; | package au.com.sensis.stubby.servlet;
/*
* Handles operations on requests (eg, 'GET /_control/requests/<index>')
*/
@SuppressWarnings("serial")
public class RequestServlet extends AbstractStubServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
returnJson(response, service().getRequest(getId(request))); | // Path: core/src/main/java/au/com/sensis/stubby/service/NotFoundException.java
// @SuppressWarnings("serial")
// public class NotFoundException extends RuntimeException {
//
// public NotFoundException(String message) {
// super(message);
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/RequestServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import au.com.sensis.stubby.service.NotFoundException;
package au.com.sensis.stubby.servlet;
/*
* Handles operations on requests (eg, 'GET /_control/requests/<index>')
*/
@SuppressWarnings("serial")
public class RequestServlet extends AbstractStubServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
returnJson(response, service().getRequest(getId(request))); | } catch (NotFoundException e) { |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/JsonServiceInterface.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.service;
public class JsonServiceInterface { // interface using serialized JSON strings/streams
private StubService service;
public JsonServiceInterface(StubService service) {
this.service = service;
}
public void addResponse(String exchange) { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/JsonServiceInterface.java
import java.io.InputStream;
import java.io.OutputStream;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.service;
public class JsonServiceInterface { // interface using serialized JSON strings/streams
private StubService service;
public JsonServiceInterface(StubService service) {
this.service = service;
}
public void addResponse(String exchange) { | service.addResponse(JsonUtils.deserialize(exchange, StubExchange.class)); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/JsonServiceInterface.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import java.io.InputStream;
import java.io.OutputStream;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.service;
public class JsonServiceInterface { // interface using serialized JSON strings/streams
private StubService service;
public JsonServiceInterface(StubService service) {
this.service = service;
}
public void addResponse(String exchange) { | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/JsonServiceInterface.java
import java.io.InputStream;
import java.io.OutputStream;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.service;
public class JsonServiceInterface { // interface using serialized JSON strings/streams
private StubService service;
public JsonServiceInterface(StubService service) {
this.service = service;
}
public void addResponse(String exchange) { | service.addResponse(JsonUtils.deserialize(exchange, StubExchange.class)); |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
| private StubExchange exchange; |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange; | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange; | private StubRequest request; |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange;
private StubRequest request; | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange;
private StubRequest request; | private StubResponse response; |
Sensis/http-stub-server | core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange;
private StubRequest request;
private StubResponse response;
private TestBean testBean;
private ScriptWorld world;
@Before
public void before() {
givenTestBean();
givenDefaultRequest();
givenDefaultResponse();
givenDefaultExchange();
}
private void givenTestBean() {
testBean = new TestBean();
testBean.getItems().add("one");
testBean.getItems().add("two");
}
private void givenDefaultRequest() {
request = new StubRequest();
request.setMethod("POST");
request.setPath("/request/path"); | // Path: core/src/main/java/au/com/sensis/stubby/model/StubExchange.java
// public class StubExchange {
//
// private StubRequest request;
// private StubResponse response;
// private Long delay;
// private String script;
//
// public StubExchange() { }
//
// public StubExchange(StubExchange other) { // copy constructor
// this.request = (other.request != null) ? new StubRequest(other.request) : null;
// this.response = (other.response != null) ? new StubResponse(other.response) : null;
// this.delay = other.delay;
// this.script = other.script;
// }
//
// public StubRequest getRequest() {
// return request;
// }
//
// public void setRequest(StubRequest request) {
// this.request = request;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public void setResponse(StubResponse response) {
// this.response = response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public void setDelay(Long delay) {
// this.delay = delay;
// }
//
// public String getScript() {
// return script;
// }
//
// public void setScript(String script) {
// this.script = script;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubParam.java
// public class StubParam {
//
// private String name;
// private String value;
//
// public StubParam() { }
//
// public StubParam(String name, String value) {
// this.name = name;
// this.value = value;
// }
//
// public StubParam(StubParam other) { // copy constructor
// this.name = other.name;
// this.value = other.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;
// }
//
// @Override
// public String toString() {
// return name + "=" + value;
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubRequest.java
// public class StubRequest extends StubMessage {
//
// private String method;
// private String path;
// private List<StubParam> params;
//
// public StubRequest() { }
//
// public StubRequest(StubRequest other) { // copy constructor
// super(other);
// this.method = other.method;
// this.path = other.path;
// if (other.params != null) {
// this.params = new ArrayList<StubParam>();
// for (StubParam param : other.params) {
// this.params.add(new StubParam(param));
// }
// }
// }
//
// public String getMethod() {
// return method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getPath() {
// return path;
// }
//
// public void setPath(String path) {
// this.path = path;
// }
//
// public List<StubParam> getParams() {
// return params;
// }
//
// public void setParams(List<StubParam> params) {
// this.params = params;
// }
//
// @JsonIgnore
// public String getParam(String name) { // get first, case sensitive lookup
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// return param.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public List<String> getParams(String name) { // get all, case sensitive lookup
// List<String> result = new ArrayList<String>();
// if (params != null) {
// for (StubParam param : params) {
// if (param.getName().equals(name)) {
// result.add(param.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/test/java/au/com/sensis/stubby/js/ScriptTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.model.StubExchange;
import au.com.sensis.stubby.model.StubParam;
import au.com.sensis.stubby.model.StubRequest;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.js;
public class ScriptTest {
@SuppressWarnings("serial")
public static class TestBean implements Serializable {
private List<String> items = new ArrayList<String>();
public List<String> getItems() {
return items;
}
}
private StubExchange exchange;
private StubRequest request;
private StubResponse response;
private TestBean testBean;
private ScriptWorld world;
@Before
public void before() {
givenTestBean();
givenDefaultRequest();
givenDefaultResponse();
givenDefaultExchange();
}
private void givenTestBean() {
testBean = new TestBean();
testBean.getItems().add("one");
testBean.getItems().add("two");
}
private void givenDefaultRequest() {
request = new StubRequest();
request.setMethod("POST");
request.setPath("/request/path"); | request.setParams(new ArrayList<StubParam>()); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/utils/HttpMessageUtils.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
| import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubMessage; | case 403:
return "Forbidden";
case 404:
return "Not Found";
case 406:
return "Not Acceptable";
case 415:
return "Unsupported Media Type";
case 422:
return "Unprocessable Entity";
case 500:
return "Internal Server Error";
case 503:
return "Service Unavailable";
default:
return null;
}
}
public static String upperCaseHeader(String name) {
Pattern pattern = Pattern.compile("\\-.|^.");
Matcher matcher = pattern.matcher(name);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(result, matcher.group().toUpperCase());
}
matcher.appendTail(result);
return result.toString();
}
| // Path: core/src/main/java/au/com/sensis/stubby/model/StubMessage.java
// public abstract class StubMessage {
//
// private List<StubParam> headers;
// private Object body;
//
// protected StubMessage() { }
//
// protected StubMessage(StubMessage other) { // copy constructor
// this.body = (other.body != null) ? DeepCopyUtils.deepCopy(other.body) : null;
// if (other.headers != null) {
// this.headers = new ArrayList<StubParam>();
// for (StubParam param : other.headers) {
// headers.add(new StubParam(param));
// }
// }
// }
//
// public List<StubParam> getHeaders() {
// return headers;
// }
//
// public void setHeaders(List<StubParam> headers) {
// this.headers = headers;
// }
//
// public Object getBody() {
// return body;
// }
//
// public void setBody(Object body) {
// this.body = body;
// }
//
// @JsonIgnore
// public String getHeader(String name) { // get first, case insensitive lookup
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// return header.getValue();
// }
// }
// }
// return null; // not found
// }
//
// @JsonIgnore
// public void removeHeader(String name) { // case insensitive lookup
// if (headers != null) {
// Iterator<StubParam> iter = headers.iterator();
// while (iter.hasNext()) {
// if (iter.next().getName().equalsIgnoreCase(name)) {
// iter.remove();
// }
// }
// }
// }
//
// @JsonIgnore
// public void setHeader(String name, String value) { // replace value, case insensitive lookup
// removeHeader(name);
// if (headers == null) {
// headers = new ArrayList<StubParam>();
// }
// headers.add(new StubParam(name, value));
// }
//
// @JsonIgnore
// public List<String> getHeaders(String name) { // get all, case insensitive lookup
// List<String> result = new ArrayList<String>();
// if (headers != null) {
// for (StubParam header : headers) {
// if (header.getName().equalsIgnoreCase(name)) {
// result.add(header.getValue());
// }
// }
// }
// return result; // empty list if not found
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/utils/HttpMessageUtils.java
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import au.com.sensis.stubby.model.StubMessage;
case 403:
return "Forbidden";
case 404:
return "Not Found";
case 406:
return "Not Acceptable";
case 415:
return "Unsupported Media Type";
case 422:
return "Unprocessable Entity";
case 500:
return "Internal Server Error";
case 503:
return "Service Unavailable";
default:
return null;
}
}
public static String upperCaseHeader(String name) {
Pattern pattern = Pattern.compile("\\-.|^.");
Matcher matcher = pattern.matcher(name);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(result, matcher.group().toUpperCase());
}
matcher.appendTail(result);
return result.toString();
}
| public static boolean isText(StubMessage message) { |
Sensis/http-stub-server | servlet/src/main/java/au/com/sensis/stubby/servlet/MatcherServlet.java | // Path: core/src/main/java/au/com/sensis/stubby/service/model/StubServiceResult.java
// public class StubServiceResult { // returned by the 'findMatch' method
//
// private List<MatchResult> attempts;
// private StubResponse response;
// private Long delay;
//
// public StubServiceResult(List<MatchResult> attempts) {
// this.attempts = attempts;
// }
//
// public StubServiceResult(List<MatchResult> attempts, StubResponse response, Long delay) {
// this.attempts = attempts;
// this.response = response;
// this.delay = delay;
// }
//
// public boolean matchFound() {
// for (MatchResult attempt : attempts) {
// if (attempt.matches()) {
// return true;
// }
// }
// return false;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public List<MatchResult> getAttempts() {
// return attempts;
// }
//
// }
| import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.service.model.StubServiceResult; | package au.com.sensis.stubby.servlet;
/*
* Generic stubbed controller that can be used to stub any URL
* Stubbed URLs can contain wildcards, eg: /path/*?param=*
*/
@SuppressWarnings("serial")
public class MatcherServlet extends AbstractStubServlet {
private static final Logger LOGGER = Logger.getLogger(MatcherServlet.class);
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
try { | // Path: core/src/main/java/au/com/sensis/stubby/service/model/StubServiceResult.java
// public class StubServiceResult { // returned by the 'findMatch' method
//
// private List<MatchResult> attempts;
// private StubResponse response;
// private Long delay;
//
// public StubServiceResult(List<MatchResult> attempts) {
// this.attempts = attempts;
// }
//
// public StubServiceResult(List<MatchResult> attempts, StubResponse response, Long delay) {
// this.attempts = attempts;
// this.response = response;
// this.delay = delay;
// }
//
// public boolean matchFound() {
// for (MatchResult attempt : attempts) {
// if (attempt.matches()) {
// return true;
// }
// }
// return false;
// }
//
// public StubResponse getResponse() {
// return response;
// }
//
// public Long getDelay() {
// return delay;
// }
//
// public List<MatchResult> getAttempts() {
// return attempts;
// }
//
// }
// Path: servlet/src/main/java/au/com/sensis/stubby/servlet/MatcherServlet.java
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import au.com.sensis.stubby.service.model.StubServiceResult;
package au.com.sensis.stubby.servlet;
/*
* Generic stubbed controller that can be used to stub any URL
* Stubbed URLs can contain wildcards, eg: /path/*?param=*
*/
@SuppressWarnings("serial")
public class MatcherServlet extends AbstractStubServlet {
private static final Logger LOGGER = Logger.getLogger(MatcherServlet.class);
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
try { | StubServiceResult result = service().findMatch(Transformer.fromServletRequest(request)); |
Sensis/http-stub-server | core/src/main/java/au/com/sensis/stubby/service/model/StubServiceResult.java | // Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
| import java.util.List;
import au.com.sensis.stubby.model.StubResponse; | package au.com.sensis.stubby.service.model;
public class StubServiceResult { // returned by the 'findMatch' method
private List<MatchResult> attempts; | // Path: core/src/main/java/au/com/sensis/stubby/model/StubResponse.java
// public class StubResponse extends StubMessage {
//
// private Integer status;
//
// public StubResponse() { }
//
// public StubResponse(StubResponse other) { // copy constructor
// super(other);
// this.status = other.status;
// }
//
// public Integer getStatus() {
// return status;
// }
//
// public void setStatus(Integer status) {
// this.status = status;
// }
//
// }
// Path: core/src/main/java/au/com/sensis/stubby/service/model/StubServiceResult.java
import java.util.List;
import au.com.sensis.stubby.model.StubResponse;
package au.com.sensis.stubby.service.model;
public class StubServiceResult { // returned by the 'findMatch' method
private List<MatchResult> attempts; | private StubResponse response; |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
| public void postMessage(JsonExchange message) { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) { | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) { | executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk(); |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
| public JsonStubbedExchangeList getResponses() { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
| public JsonRequestList getRequests() { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
public JsonRequestList getRequests() {
return executeGet("/_control/requests").assertOk().getJson(JsonRequestList.class);
}
public JsonRequestList findRequests(String query) {
return executeGet("/_control/requests?" + query).assertOk().getJson(JsonRequestList.class);
}
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
public JsonRequestList getRequests() {
return executeGet("/_control/requests").assertOk().getJson(JsonRequestList.class);
}
public JsonRequestList findRequests(String query) {
return executeGet("/_control/requests?" + query).assertOk().getJson(JsonRequestList.class);
}
| public JsonStubbedExchange getResponse(int index) { |
Sensis/http-stub-server | functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java | // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
| import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils; | package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
public JsonRequestList getRequests() {
return executeGet("/_control/requests").assertOk().getJson(JsonRequestList.class);
}
public JsonRequestList findRequests(String query) {
return executeGet("/_control/requests?" + query).assertOk().getJson(JsonRequestList.class);
}
public JsonStubbedExchange getResponse(int index) {
return executeGet("/_control/responses/" + index).assertOk().getJson(JsonStubbedExchange.class);
}
| // Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonExchange.java
// public class JsonExchange {
//
// public JsonRequest request;
// public JsonResponse response;
// public Long delay;
// public String script;
//
// @JsonIgnore
// public JsonRequest request() {
// if (request == null) {
// request = new JsonRequest();
// }
// return request;
// }
//
// @JsonIgnore
// public JsonResponse response() {
// if (response == null) {
// response = new JsonResponse();
// }
// return response;
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
//
// public String method;
// public String path;
// public JsonPairList params;
//
// public void setParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.set(name, value);
// }
//
// public void addParam(String name, String value) {
// if (params == null) {
// params = new JsonPairList();
// }
// params.add(name, value);
// }
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchange.java
// public class JsonStubbedExchange {
//
// public JsonExchange exchange;
// public List<Object> attempts; // TODO: lock-down the format of this...
//
// }
//
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//
// }
//
// Path: core/src/main/java/au/com/sensis/stubby/utils/JsonUtils.java
// public class JsonUtils {
//
// public static ObjectMapper mapper() {
// return new ObjectMapper();
// }
//
// public static ObjectMapper defaultMapper() {
// ObjectMapper result = mapper();
// result.enable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
// result.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS); // for 'exact' floating-point matches
// result.setSerializationInclusion(Inclusion.NON_NULL);
// return result;
// }
//
// public static ObjectWriter prettyWriter() {
// return defaultMapper().writerWithDefaultPrettyPrinter();
// }
//
// public static String prettyPrint(Object value) {
// try {
// return prettyWriter().writeValueAsString(value);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static String serialize(Object object) {
// try {
// return defaultMapper().writeValueAsString(object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static void serialize(OutputStream stream, Object object) {
// try {
// defaultMapper().writeValue(stream, object);
// } catch (IOException e) {
// throw new RuntimeException("Error serializing JSON", e);
// }
// }
//
// public static <T> T deserialize(String json, Class<T> type) {
// try {
// return defaultMapper().readValue(json, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// public static <T> T deserialize(InputStream stream, Class<T> type) {
// try {
// return defaultMapper().readValue(stream, type);
// } catch (IOException e) {
// throw new RuntimeException("Error deserializing JSON", e);
// }
// }
//
// }
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/Client.java
import org.apache.http.entity.ContentType;
import au.com.sensis.stubby.test.model.JsonExchange;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.model.JsonStubbedExchange;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.utils.JsonUtils;
package au.com.sensis.stubby.test.client;
public class Client extends GenericClient {
public Client(String baseUri) {
super(baseUri);
}
public void postMessage(JsonExchange message) {
executePost("/_control/responses", JsonUtils.serialize(message), ContentType.APPLICATION_JSON).assertOk();
}
public void postMessage(String message) {
executePost("/_control/responses", message, ContentType.APPLICATION_JSON).assertOk();
}
public JsonStubbedExchangeList getResponses() {
return executeGet("/_control/responses").assertOk().getJson(JsonStubbedExchangeList.class);
}
public JsonRequestList getRequests() {
return executeGet("/_control/requests").assertOk().getJson(JsonRequestList.class);
}
public JsonRequestList findRequests(String query) {
return executeGet("/_control/requests?" + query).assertOk().getJson(JsonRequestList.class);
}
public JsonStubbedExchange getResponse(int index) {
return executeGet("/_control/responses/" + index).assertOk().getJson(JsonStubbedExchange.class);
}
| public JsonRequest getRequest(int index) { |
mattcasters/pentaho-pdi-dataset | src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTestsMeta.java | // Path: src/main/java/org/pentaho/di/dataset/TestType.java
// public enum TestType {
// NONE, CONCEPTUAL, DEVELOPMENT, UNIT_TEST;
// }
//
// Path: src/main/java/org/pentaho/di/dataset/UnitTestResult.java
// public class UnitTestResult {
// private static final Class<?> PKG = UnitTestResult.class; // For i18n
//
// private String transformationName;
// private String unitTestName;
// private String dataSetName;
// private String stepName;
// private boolean error;
// private String comment;
//
// public UnitTestResult() {
// super();
// }
//
// public UnitTestResult( String transformationName, String unitTestName, String dataSetName, String stepName, boolean error, String comment ) {
// super();
// this.transformationName = transformationName;
// this.unitTestName = unitTestName;
// this.dataSetName = dataSetName;
// this.stepName = stepName;
// this.error = error;
// this.comment = comment;
// }
//
// public String getTransformationName() {
// return transformationName;
// }
//
// public void setTransformationName( String transformationName ) {
// this.transformationName = transformationName;
// }
//
// public String getUnitTestName() {
// return unitTestName;
// }
//
// public void setUnitTestName( String unitTestName ) {
// this.unitTestName = unitTestName;
// }
//
// public String getDataSetName() {
// return dataSetName;
// }
//
// public void setDataSetName( String dataSetName ) {
// this.dataSetName = dataSetName;
// }
//
// public String getStepName() {
// return stepName;
// }
//
// public void setStepName( String stepName ) {
// this.stepName = stepName;
// }
//
// public boolean isError() {
// return error;
// }
//
// public void setError( boolean error ) {
// this.error = error;
// }
//
// public String getComment() {
// return comment;
// }
//
// public void setComment( String comment ) {
// this.comment = comment;
// }
//
// public static final RowMetaInterface getRowMeta() {
// RowMetaInterface rowMeta = new RowMeta();
//
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.TransformationName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.UnitTestName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.DataSetName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.StepName" ) ) );
// rowMeta.addValueMeta( new ValueMetaBoolean( BaseMessages.getString( PKG, "UnitTestResult.FieldName.Error" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.Comment" ) ) );
//
// return rowMeta;
// }
//
// public static final List<Object[]> getRowData( List<UnitTestResult> results ) {
// List<Object[]> rows = new ArrayList<Object[]>();
// RowMetaInterface rowMeta = getRowMeta();
// for ( UnitTestResult result : results ) {
// int index = 0;
// Object[] row = RowDataUtil.allocateRowData( rowMeta.size() );
// row[ index++ ] = result.getTransformationName();
// row[ index++ ] = result.getUnitTestName();
// row[ index++ ] = result.getDataSetName();
// row[ index++ ] = result.getStepName();
// row[ index++ ] = result.isError();
// row[ index++ ] = result.getComment();
// rows.add( row );
// }
// return rows;
// }
//
// }
| import org.pentaho.di.core.annotations.Step;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.dataset.TestType;
import org.pentaho.di.dataset.UnitTestResult;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.metastore.api.IMetaStore;
import org.w3c.dom.Node;
import java.util.List; | image = "ui/images/TRNEx.svg",
categoryDescription = "Flow"
)
public class ExecuteTestsMeta extends BaseStepMeta implements StepMetaInterface {
public static final String TAG_TEST_NAME_INPUT_FIELD = "test_name_input_field";
public static final String TAG_TYPE_TO_EXECUTE = "type_to_execute";
public static final String TAG_TRANSFORMATION_NAME_FIELD = "trans_name_field";
public static final String TAG_UNIT_TEST_NAME_FIELD = "unit_test_name_field";
public static final String TAG_DATASET_NAME_FIELD = "data_set_name_field";
public static final String TAG_STEP_NAME_FIELD = "step_name_field";
public static final String TAG_ERROR_FIELD = "error_field";
public static final String TAG_COMMENT_FIELD = "comment_field";
private String testNameInputField;
private TestType typeToExecute;
private String transformationNameField;
private String unitTestNameField;
private String dataSetNameField;
private String stepNameField;
private String errorField;
private String commentField;
public ExecuteTestsMeta() {
super();
}
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { | // Path: src/main/java/org/pentaho/di/dataset/TestType.java
// public enum TestType {
// NONE, CONCEPTUAL, DEVELOPMENT, UNIT_TEST;
// }
//
// Path: src/main/java/org/pentaho/di/dataset/UnitTestResult.java
// public class UnitTestResult {
// private static final Class<?> PKG = UnitTestResult.class; // For i18n
//
// private String transformationName;
// private String unitTestName;
// private String dataSetName;
// private String stepName;
// private boolean error;
// private String comment;
//
// public UnitTestResult() {
// super();
// }
//
// public UnitTestResult( String transformationName, String unitTestName, String dataSetName, String stepName, boolean error, String comment ) {
// super();
// this.transformationName = transformationName;
// this.unitTestName = unitTestName;
// this.dataSetName = dataSetName;
// this.stepName = stepName;
// this.error = error;
// this.comment = comment;
// }
//
// public String getTransformationName() {
// return transformationName;
// }
//
// public void setTransformationName( String transformationName ) {
// this.transformationName = transformationName;
// }
//
// public String getUnitTestName() {
// return unitTestName;
// }
//
// public void setUnitTestName( String unitTestName ) {
// this.unitTestName = unitTestName;
// }
//
// public String getDataSetName() {
// return dataSetName;
// }
//
// public void setDataSetName( String dataSetName ) {
// this.dataSetName = dataSetName;
// }
//
// public String getStepName() {
// return stepName;
// }
//
// public void setStepName( String stepName ) {
// this.stepName = stepName;
// }
//
// public boolean isError() {
// return error;
// }
//
// public void setError( boolean error ) {
// this.error = error;
// }
//
// public String getComment() {
// return comment;
// }
//
// public void setComment( String comment ) {
// this.comment = comment;
// }
//
// public static final RowMetaInterface getRowMeta() {
// RowMetaInterface rowMeta = new RowMeta();
//
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.TransformationName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.UnitTestName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.DataSetName" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.StepName" ) ) );
// rowMeta.addValueMeta( new ValueMetaBoolean( BaseMessages.getString( PKG, "UnitTestResult.FieldName.Error" ) ) );
// rowMeta.addValueMeta( new ValueMetaString( BaseMessages.getString( PKG, "UnitTestResult.FieldName.Comment" ) ) );
//
// return rowMeta;
// }
//
// public static final List<Object[]> getRowData( List<UnitTestResult> results ) {
// List<Object[]> rows = new ArrayList<Object[]>();
// RowMetaInterface rowMeta = getRowMeta();
// for ( UnitTestResult result : results ) {
// int index = 0;
// Object[] row = RowDataUtil.allocateRowData( rowMeta.size() );
// row[ index++ ] = result.getTransformationName();
// row[ index++ ] = result.getUnitTestName();
// row[ index++ ] = result.getDataSetName();
// row[ index++ ] = result.getStepName();
// row[ index++ ] = result.isError();
// row[ index++ ] = result.getComment();
// rows.add( row );
// }
// return rows;
// }
//
// }
// Path: src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTestsMeta.java
import org.pentaho.di.core.annotations.Step;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.dataset.TestType;
import org.pentaho.di.dataset.UnitTestResult;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.metastore.api.IMetaStore;
import org.w3c.dom.Node;
import java.util.List;
image = "ui/images/TRNEx.svg",
categoryDescription = "Flow"
)
public class ExecuteTestsMeta extends BaseStepMeta implements StepMetaInterface {
public static final String TAG_TEST_NAME_INPUT_FIELD = "test_name_input_field";
public static final String TAG_TYPE_TO_EXECUTE = "type_to_execute";
public static final String TAG_TRANSFORMATION_NAME_FIELD = "trans_name_field";
public static final String TAG_UNIT_TEST_NAME_FIELD = "unit_test_name_field";
public static final String TAG_DATASET_NAME_FIELD = "data_set_name_field";
public static final String TAG_STEP_NAME_FIELD = "step_name_field";
public static final String TAG_ERROR_FIELD = "error_field";
public static final String TAG_COMMENT_FIELD = "comment_field";
private String testNameInputField;
private TestType typeToExecute;
private String transformationNameField;
private String unitTestNameField;
private String dataSetNameField;
private String stepNameField;
private String errorField;
private String commentField;
public ExecuteTestsMeta() {
super();
}
@Override
public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { | RowMetaInterface rowMeta = UnitTestResult.getRowMeta(); |
googleapis/java-mediatranslation | google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/MockSpeechTranslationServiceImpl.java | // Path: grpc-google-cloud-mediatranslation-v1beta1/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceGrpc.java
// public abstract static class SpeechTranslationServiceImplBase implements io.grpc.BindableService {
//
// /**
// *
// *
// * <pre>
// * Performs bidirectional streaming speech translation: receive results while
// * sending audio. This method is only available via the gRPC API (not REST).
// * </pre>
// */
// public io.grpc.stub.StreamObserver<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest>
// streamingTranslateSpeech(
// io.grpc.stub.StreamObserver<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse>
// responseObserver) {
// return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(
// getStreamingTranslateSpeechMethod(), responseObserver);
// }
//
// @java.lang.Override
// public final io.grpc.ServerServiceDefinition bindService() {
// return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
// .addMethod(
// getStreamingTranslateSpeechMethod(),
// io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
// new MethodHandlers<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest,
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse>(
// this, METHODID_STREAMING_TRANSLATE_SPEECH)))
// .build();
// }
// }
| import com.google.api.core.BetaApi;
import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceGrpc.SpeechTranslationServiceImplBase;
import com.google.protobuf.AbstractMessage;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import javax.annotation.Generated; | /*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.mediatranslation.v1beta1;
@BetaApi
@Generated("by gapic-generator-java") | // Path: grpc-google-cloud-mediatranslation-v1beta1/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceGrpc.java
// public abstract static class SpeechTranslationServiceImplBase implements io.grpc.BindableService {
//
// /**
// *
// *
// * <pre>
// * Performs bidirectional streaming speech translation: receive results while
// * sending audio. This method is only available via the gRPC API (not REST).
// * </pre>
// */
// public io.grpc.stub.StreamObserver<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest>
// streamingTranslateSpeech(
// io.grpc.stub.StreamObserver<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse>
// responseObserver) {
// return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(
// getStreamingTranslateSpeechMethod(), responseObserver);
// }
//
// @java.lang.Override
// public final io.grpc.ServerServiceDefinition bindService() {
// return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
// .addMethod(
// getStreamingTranslateSpeechMethod(),
// io.grpc.stub.ServerCalls.asyncBidiStreamingCall(
// new MethodHandlers<
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest,
// com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse>(
// this, METHODID_STREAMING_TRANSLATE_SPEECH)))
// .build();
// }
// }
// Path: google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/MockSpeechTranslationServiceImpl.java
import com.google.api.core.BetaApi;
import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceGrpc.SpeechTranslationServiceImplBase;
import com.google.protobuf.AbstractMessage;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import javax.annotation.Generated;
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.mediatranslation.v1beta1;
@BetaApi
@Generated("by gapic-generator-java") | public class MockSpeechTranslationServiceImpl extends SpeechTranslationServiceImplBase { |
ransford/mspsim | se/sics/mspsim/core/IOUnit.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import se.sics.mspsim.core.EmulationLogger.WarningType; | StateChangeListener listener = stateListener;
if (listener != null) {
listener.stateChanged(this, oldState, ioState);
}
}
}
public void reset(int type) {
}
// write
// write a value to the IO unit
public abstract void write(int address, int value, boolean word, long cycles);
// read
// read a value from the IO unit
public abstract int read(int address, boolean word, long cycles);
public String getID() {
return id;
}
public String getName() {
return name;
}
protected void log(String msg) {
logger.log(this, msg);
}
| // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/IOUnit.java
import se.sics.mspsim.core.EmulationLogger.WarningType;
StateChangeListener listener = stateListener;
if (listener != null) {
listener.stateChanged(this, oldState, ioState);
}
}
}
public void reset(int type) {
}
// write
// write a value to the IO unit
public abstract void write(int address, int value, boolean word, long cycles);
// read
// read a value from the IO unit
public abstract int read(int address, boolean word, long cycles);
public String getID() {
return id;
}
public String getName() {
return name;
}
protected void log(String msg) {
logger.log(this, msg);
}
| protected void logw(WarningType type, String msg) { |
ransford/mspsim | se/sics/mspsim/core/Chip.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.ArrayUtils;
|
public String getName() {
return name;
}
public abstract int getModeMax();
/* By default the cs is set high */
public boolean getChipSelect() {
return true;
}
public String info() {
return "* no info";
}
public int getLogLevel() {
return logLevel;
}
public void setLogLevel(int l) {
logLevel = l;
DEBUG = logLevel == Loggable.DEBUG;
}
protected void log(String msg) {
logger.log(this, msg);
}
/* warn about anything above severe - but what types are severe? */
| // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/Chip.java
import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.ArrayUtils;
public String getName() {
return name;
}
public abstract int getModeMax();
/* By default the cs is set high */
public boolean getChipSelect() {
return true;
}
public String info() {
return "* no info";
}
public int getLogLevel() {
return logLevel;
}
public void setLogLevel(int l) {
logLevel = l;
DEBUG = logLevel == Loggable.DEBUG;
}
protected void log(String msg) {
logger.log(this, msg);
}
/* warn about anything above severe - but what types are severe? */
| protected void logw(WarningType type, String msg) {
|
ransford/mspsim | se/sics/mspsim/core/FlashSegment.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import se.sics.mspsim.core.EmulationLogger.WarningType; | package se.sics.mspsim.core;
public class FlashSegment implements Memory {
private final MSP430Core core;
private final int memory[];
private final Flash flash;
public FlashSegment(MSP430Core core, Flash flash) {
this.core = core;
this.memory = core.memory;
this.flash = flash;
}
@Override
public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
if (core.isFlashBusy) {
flash.notifyRead(address);
}
int val = memory[address] & 0xff;
if (mode != AccessMode.BYTE) {
val |= (memory[address + 1] & 0xff) << 8;
if ((address & 1) != 0) { | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/FlashSegment.java
import se.sics.mspsim.core.EmulationLogger.WarningType;
package se.sics.mspsim.core;
public class FlashSegment implements Memory {
private final MSP430Core core;
private final int memory[];
private final Flash flash;
public FlashSegment(MSP430Core core, Flash flash) {
this.core = core;
this.memory = core.memory;
this.flash = flash;
}
@Override
public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
if (core.isFlashBusy) {
flash.notifyRead(address);
}
int val = memory[address] & 0xff;
if (mode != AccessMode.BYTE) {
val |= (memory[address + 1] & 0xff) << 8;
if ((address & 1) != 0) { | core.printWarning(WarningType.MISALIGNED_READ, address); |
ransford/mspsim | se/sics/mspsim/Main.java | // Path: se/sics/mspsim/util/ArgumentManager.java
// public class ArgumentManager extends ConfigManager {
//
// private String configName = "config";
// private String[] arguments;
// private boolean isConfigLoaded;
//
// public ArgumentManager() {
// }
//
// public ArgumentManager(ConfigManager parent) {
// super(parent);
// }
//
// public boolean isConfigLoaded() {
// return isConfigLoaded;
// }
//
// public String getConfigArgumentName() {
// return configName;
// }
//
// public void setConfigArgumentName(String configName) {
// this.configName = configName;
// }
//
// public String[] getArguments() {
// return arguments;
// }
//
// public void handleArguments(String[] args) {
// ArrayList<String> list = new ArrayList<String>();
// ArrayList<String> config = new ArrayList<String>();
// for (int i = 0, n = args.length; i < n; i++) {
// if ("-".equals(args[i])) {
// // The rest should be considered arguments
// for(++i; i < args.length; i++) {
// list.add(args[i]);
// }
// break;
// }
// if (args[i].startsWith("-")) {
// String param = args[i].substring(1);
// String value = "";
// int index = param.indexOf('=');
// if (index >= 0) {
// if (index < param.length()) {
// value = param.substring(index + 1);
// }
// param = param.substring(0, index);
// }
// if (param.length() == 0) {
// throw new IllegalArgumentException("illegal argument: " + args[i]);
// }
// if (configName != null && configName.equals(param)) {
// if (value.length() == 0) {
// throw new IllegalArgumentException("no config file name specified");
// }
// if (!loadConfiguration(value)) {
// throw new IllegalArgumentException("failed to load configuration " + value);
// }
// isConfigLoaded = true;
// }
// config.add(param);
// config.add(value.length() > 0 ? value : "true");
// } else {
// // Normal argument
// list.add(args[i]);
// }
// }
// this.arguments = list.toArray(new String[list.size()]);
// for (int i = 0, n = config.size(); i < n; i += 2) {
// setProperty(config.get(i), config.get(i + 1));
// }
// }
//
// } // ArgumentManager
| import se.sics.mspsim.platform.GenericNode;
import se.sics.mspsim.util.ArgumentManager;
import java.io.IOException; | } catch (ClassCastException e) {
// Wrong class type
} catch (InstantiationException e) {
// Failed to instantiate
} catch (IllegalAccessException e) {
// Failed to access constructor
}
return null;
}
public static String getNodeTypeByPlatform(String platform) {
if ("jcreate".equals(platform)) {
return "se.sics.mspsim.platform.jcreate.JCreateNode";
}
if ("sentilla-usb".equals(platform)) {
return "se.sics.mspsim.platform.sentillausb.SentillaUSBNode";
}
if ("esb".equals(platform)) {
return "se.sics.mspsim.platform.esb.ESBNode";
}
if ("exp5438".equals(platform)) {
return "se.sics.mspsim.platform.ti.Exp5438Node";
}
// Try to guess the node type.
return "se.sics.mspsim.platform." + platform + '.'
+ Character.toUpperCase(platform.charAt(0))
+ platform.substring(1).toLowerCase() + "Node";
}
public static void main(String[] args) throws IOException { | // Path: se/sics/mspsim/util/ArgumentManager.java
// public class ArgumentManager extends ConfigManager {
//
// private String configName = "config";
// private String[] arguments;
// private boolean isConfigLoaded;
//
// public ArgumentManager() {
// }
//
// public ArgumentManager(ConfigManager parent) {
// super(parent);
// }
//
// public boolean isConfigLoaded() {
// return isConfigLoaded;
// }
//
// public String getConfigArgumentName() {
// return configName;
// }
//
// public void setConfigArgumentName(String configName) {
// this.configName = configName;
// }
//
// public String[] getArguments() {
// return arguments;
// }
//
// public void handleArguments(String[] args) {
// ArrayList<String> list = new ArrayList<String>();
// ArrayList<String> config = new ArrayList<String>();
// for (int i = 0, n = args.length; i < n; i++) {
// if ("-".equals(args[i])) {
// // The rest should be considered arguments
// for(++i; i < args.length; i++) {
// list.add(args[i]);
// }
// break;
// }
// if (args[i].startsWith("-")) {
// String param = args[i].substring(1);
// String value = "";
// int index = param.indexOf('=');
// if (index >= 0) {
// if (index < param.length()) {
// value = param.substring(index + 1);
// }
// param = param.substring(0, index);
// }
// if (param.length() == 0) {
// throw new IllegalArgumentException("illegal argument: " + args[i]);
// }
// if (configName != null && configName.equals(param)) {
// if (value.length() == 0) {
// throw new IllegalArgumentException("no config file name specified");
// }
// if (!loadConfiguration(value)) {
// throw new IllegalArgumentException("failed to load configuration " + value);
// }
// isConfigLoaded = true;
// }
// config.add(param);
// config.add(value.length() > 0 ? value : "true");
// } else {
// // Normal argument
// list.add(args[i]);
// }
// }
// this.arguments = list.toArray(new String[list.size()]);
// for (int i = 0, n = config.size(); i < n; i += 2) {
// setProperty(config.get(i), config.get(i + 1));
// }
// }
//
// } // ArgumentManager
// Path: se/sics/mspsim/Main.java
import se.sics.mspsim.platform.GenericNode;
import se.sics.mspsim.util.ArgumentManager;
import java.io.IOException;
} catch (ClassCastException e) {
// Wrong class type
} catch (InstantiationException e) {
// Failed to instantiate
} catch (IllegalAccessException e) {
// Failed to access constructor
}
return null;
}
public static String getNodeTypeByPlatform(String platform) {
if ("jcreate".equals(platform)) {
return "se.sics.mspsim.platform.jcreate.JCreateNode";
}
if ("sentilla-usb".equals(platform)) {
return "se.sics.mspsim.platform.sentillausb.SentillaUSBNode";
}
if ("esb".equals(platform)) {
return "se.sics.mspsim.platform.esb.ESBNode";
}
if ("exp5438".equals(platform)) {
return "se.sics.mspsim.platform.ti.Exp5438Node";
}
// Try to guess the node type.
return "se.sics.mspsim.platform." + platform + '.'
+ Character.toUpperCase(platform.charAt(0))
+ platform.substring(1).toLowerCase() + "Node";
}
public static void main(String[] args) throws IOException { | ArgumentManager config = new ArgumentManager(); |
ransford/mspsim | se/sics/mspsim/cli/FileCommands.java | // Path: se/sics/mspsim/util/ComponentRegistry.java
// public class ComponentRegistry {
//
// private ArrayList<ComponentEntry> components = new ArrayList<ComponentEntry>();
// private boolean running = false;
//
// private synchronized ComponentEntry[] getAllEntries() {
// return components.toArray(new ComponentEntry[components.size()]);
// }
//
// public void registerComponent(String name, Object component) {
// if (name == null || component == null) {
// throw new NullPointerException();
// }
// synchronized (this) {
// components.add(new ComponentEntry(name, component));
// }
// if (component instanceof ActiveComponent) {
// ((ActiveComponent)component).init(name, this);
// if (running) {
// ((ActiveComponent)component).start();
// }
// } else if (component instanceof ServiceComponent) {
// ((ServiceComponent)component).init(name, this);
// }
// }
//
// public synchronized Object getComponent(String name) {
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// return entry.component;
// }
// }
// return null;
// }
//
// public synchronized boolean removeComponent(String name) {
// ComponentEntry rem = null;
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// rem = entry;
// break;
// }
// }
// if (rem == null) {
// return false;
// }
// components.remove(rem);
// return true;
// }
//
// public synchronized Object[] getAllComponents(String name) {
// ArrayList<Object> list = new ArrayList<Object>();
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// list.add(entry.component);
// }
// }
// return list.toArray();
// }
//
// public synchronized <T> T getComponent(Class<T> type, String name) {
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component) && name.equals(entry.name)) {
// return type.cast(entry.component);
// }
// }
// return null;
// }
//
// @SuppressWarnings("unchecked")
// public synchronized <T> T[] getAllComponents(Class<T> type, String name) {
// ArrayList<T> list = new ArrayList<T>();
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component) && name.equals(entry.name)) {
// list.add(type.cast(entry.component));
// }
// }
// return list.toArray((T[]) java.lang.reflect.Array.newInstance(type, list.size()));
// }
//
// public synchronized <T> T getComponent(Class<T> type) {
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component)) {
// return type.cast(entry.component);
// }
// }
// return null;
// }
//
// @SuppressWarnings("unchecked")
// public synchronized <T> T[] getAllComponents(Class<T> type) {
// ArrayList<T> list = new ArrayList<T>();
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component)) {
// list.add(type.cast(entry.component));
// }
// }
// return list.toArray((T[]) java.lang.reflect.Array.newInstance(type, list.size()));
// }
//
// public void start() {
// ComponentEntry[] plugs;
// synchronized (this) {
// running = true;
// plugs = getAllEntries();
// }
//
// for (ComponentEntry entry : plugs) {
// if (entry.component instanceof ActiveComponent) {
// ((ActiveComponent) entry.component).start();
// }
// }
// }
//
// public void printRegistry(PrintStream out) {
// ComponentEntry[] plugs = getAllEntries();
// out.printf("%-22s %s\n", "Component Name", "Component Class");
// out.println("----------------------------------------------");
// for (ComponentEntry entry : plugs) {
// out.printf("%-22s %s\n", entry.name, entry.component.getClass().getName());
// }
// }
//
// private static class ComponentEntry {
// public final String name;
// public final Object component;
//
// private ComponentEntry(String name, Object component) {
// this.name = name;
// this.component = component;
// }
// }
//
// }
| import java.util.Hashtable;
import se.sics.mspsim.util.ComponentRegistry; | package se.sics.mspsim.cli;
public class FileCommands implements CommandBundle {
private final Hashtable <String,Target> fileTargets = new Hashtable<String,Target>();
| // Path: se/sics/mspsim/util/ComponentRegistry.java
// public class ComponentRegistry {
//
// private ArrayList<ComponentEntry> components = new ArrayList<ComponentEntry>();
// private boolean running = false;
//
// private synchronized ComponentEntry[] getAllEntries() {
// return components.toArray(new ComponentEntry[components.size()]);
// }
//
// public void registerComponent(String name, Object component) {
// if (name == null || component == null) {
// throw new NullPointerException();
// }
// synchronized (this) {
// components.add(new ComponentEntry(name, component));
// }
// if (component instanceof ActiveComponent) {
// ((ActiveComponent)component).init(name, this);
// if (running) {
// ((ActiveComponent)component).start();
// }
// } else if (component instanceof ServiceComponent) {
// ((ServiceComponent)component).init(name, this);
// }
// }
//
// public synchronized Object getComponent(String name) {
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// return entry.component;
// }
// }
// return null;
// }
//
// public synchronized boolean removeComponent(String name) {
// ComponentEntry rem = null;
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// rem = entry;
// break;
// }
// }
// if (rem == null) {
// return false;
// }
// components.remove(rem);
// return true;
// }
//
// public synchronized Object[] getAllComponents(String name) {
// ArrayList<Object> list = new ArrayList<Object>();
// for (ComponentEntry entry : components) {
// if (name.equals(entry.name)) {
// list.add(entry.component);
// }
// }
// return list.toArray();
// }
//
// public synchronized <T> T getComponent(Class<T> type, String name) {
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component) && name.equals(entry.name)) {
// return type.cast(entry.component);
// }
// }
// return null;
// }
//
// @SuppressWarnings("unchecked")
// public synchronized <T> T[] getAllComponents(Class<T> type, String name) {
// ArrayList<T> list = new ArrayList<T>();
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component) && name.equals(entry.name)) {
// list.add(type.cast(entry.component));
// }
// }
// return list.toArray((T[]) java.lang.reflect.Array.newInstance(type, list.size()));
// }
//
// public synchronized <T> T getComponent(Class<T> type) {
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component)) {
// return type.cast(entry.component);
// }
// }
// return null;
// }
//
// @SuppressWarnings("unchecked")
// public synchronized <T> T[] getAllComponents(Class<T> type) {
// ArrayList<T> list = new ArrayList<T>();
// for (ComponentEntry entry : components) {
// if (type.isInstance(entry.component)) {
// list.add(type.cast(entry.component));
// }
// }
// return list.toArray((T[]) java.lang.reflect.Array.newInstance(type, list.size()));
// }
//
// public void start() {
// ComponentEntry[] plugs;
// synchronized (this) {
// running = true;
// plugs = getAllEntries();
// }
//
// for (ComponentEntry entry : plugs) {
// if (entry.component instanceof ActiveComponent) {
// ((ActiveComponent) entry.component).start();
// }
// }
// }
//
// public void printRegistry(PrintStream out) {
// ComponentEntry[] plugs = getAllEntries();
// out.printf("%-22s %s\n", "Component Name", "Component Class");
// out.println("----------------------------------------------");
// for (ComponentEntry entry : plugs) {
// out.printf("%-22s %s\n", entry.name, entry.component.getClass().getName());
// }
// }
//
// private static class ComponentEntry {
// public final String name;
// public final Object component;
//
// private ComponentEntry(String name, Object component) {
// this.name = name;
// this.component = component;
// }
// }
//
// }
// Path: se/sics/mspsim/cli/FileCommands.java
import java.util.Hashtable;
import se.sics.mspsim.util.ComponentRegistry;
package se.sics.mspsim.cli;
public class FileCommands implements CommandBundle {
private final Hashtable <String,Target> fileTargets = new Hashtable<String,Target>();
| public void setupCommands(final ComponentRegistry registry, CommandHandler handler) { |
ransford/mspsim | se/sics/mspsim/core/USCI.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import se.sics.mspsim.core.EmulationLogger.WarningType; | div = 1;
}
if (clockSource == MSP430Constants.CLK_ACLK) {
if (DEBUG) {
log(" Baud rate is (bps): " + cpu.aclkFrq / div + " div = " + div);
}
baudRate = cpu.aclkFrq / div;
} else {
if (DEBUG) {
log(" Baud rate is (bps): " + cpu.smclkFrq / div + " div = " + div);
}
baudRate = cpu.smclkFrq / div;
}
if (baudRate == 0) baudRate = 1;
// Is this correct??? Is it the DCO or smclkFRQ we should have here???
tickPerByte = (8 * cpu.smclkFrq) / baudRate;
if (DEBUG) {
log(" Ticks per byte: " + tickPerByte);
}
}
// We should add "Interrupt serviced..." to indicate that its latest
// Interrupt was serviced...
public void interruptServiced(int vector) {
/* NOTE: this is handled by SFR : clear IFG bit if interrupt is serviced */
// System.out.println(getName() + " SFR irq " + vector + " " + txShiftReg + " " + getIFG());
}
private void handleTransmit(long cycles) {
if (cpu.getMode() >= MSP430Core.MODE_LPM3) { | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/USCI.java
import se.sics.mspsim.core.EmulationLogger.WarningType;
div = 1;
}
if (clockSource == MSP430Constants.CLK_ACLK) {
if (DEBUG) {
log(" Baud rate is (bps): " + cpu.aclkFrq / div + " div = " + div);
}
baudRate = cpu.aclkFrq / div;
} else {
if (DEBUG) {
log(" Baud rate is (bps): " + cpu.smclkFrq / div + " div = " + div);
}
baudRate = cpu.smclkFrq / div;
}
if (baudRate == 0) baudRate = 1;
// Is this correct??? Is it the DCO or smclkFRQ we should have here???
tickPerByte = (8 * cpu.smclkFrq) / baudRate;
if (DEBUG) {
log(" Ticks per byte: " + tickPerByte);
}
}
// We should add "Interrupt serviced..." to indicate that its latest
// Interrupt was serviced...
public void interruptServiced(int vector) {
/* NOTE: this is handled by SFR : clear IFG bit if interrupt is serviced */
// System.out.println(getName() + " SFR irq " + vector + " " + txShiftReg + " " + getIFG());
}
private void handleTransmit(long cycles) {
if (cpu.getMode() >= MSP430Core.MODE_LPM3) { | logw(WarningType.EXECUTION, "Warning: USART transmission during LPM!!! " + nextTXByte); |
ransford/mspsim | se/sics/mspsim/core/RTC.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import java.util.Calendar;
import java.util.GregorianCalendar;
import se.sics.mspsim.core.EmulationLogger.WarningType; | }
cal.set(calField, res);
cal.get(calField); // Until get is not done the fields are not set
}
/**
* Clear the highest priority interrupt flag
*/
private void clearHighestInterrupt() {
if (readyInterruptFlag) {
readyInterruptFlag = false;
} else if (eventInterruptFlag) {
eventInterruptFlag = false;
} else if (alarmInterruptFlag) {
alarmInterruptFlag = false;
}
if (getIV() > 0) {
cpu.flagInterrupt(rtcIntVector, this, true);
}
}
/**
* The registers are written
*/
public void write(int address, int value, boolean word, long cycles) {
/*
* XXX: this assumes always word access
*/
if (!word) { | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/RTC.java
import java.util.Calendar;
import java.util.GregorianCalendar;
import se.sics.mspsim.core.EmulationLogger.WarningType;
}
cal.set(calField, res);
cal.get(calField); // Until get is not done the fields are not set
}
/**
* Clear the highest priority interrupt flag
*/
private void clearHighestInterrupt() {
if (readyInterruptFlag) {
readyInterruptFlag = false;
} else if (eventInterruptFlag) {
eventInterruptFlag = false;
} else if (alarmInterruptFlag) {
alarmInterruptFlag = false;
}
if (getIV() > 0) {
cpu.flagInterrupt(rtcIntVector, this, true);
}
}
/**
* The registers are written
*/
public void write(int address, int value, boolean word, long cycles) {
/*
* XXX: this assumes always word access
*/
if (!word) { | logw(WarningType.MISALIGNED_WRITE, "byte access not implemented"); |
ransford/mspsim | se/sics/mspsim/core/ADC12Plus.java | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
| import se.sics.mspsim.core.EmulationLogger.WarningType;
import java.util.Arrays; | } else {
adc12ctl1 = value & 0xfffe;
startMem = (value >> 12) & 0xf;
shSource = (value >> 10) & 0x3;
adcDiv = ((value >> 5) & 0x7) + 1;
adcSSel = (value >> 3) & 0x03;
}
conSeq = (value >> 1) & 0x03;
if (DEBUG)
log("Set startMem: " + startMem + " SHSource: " + shSource
+ " ConSeq-mode:" + conSeq + " Div: " + adcDiv + " ADCSSEL: "
+ adcSSel);
break;
case ADC12CTL2: /* Low Power Specs */
if (enableConversion) {
/*
* Clock pre divider can't be modified when conversion is already
* enabled
*/
value &= 0xfeff;
value |= (adc12ctl2 & 0x100);
}
clockPredivider = ((value & 0x100) > 0) ? 4 : 1;
/* bit resolution 8, 10, 12 */
int tmp = (value & 0x30) >> 4;
tmp = (tmp <= 2) ? tmp * 2 : 4;
bitsResolution = tmp + 8;
formatSigned = ((value & 0x08) > 0);
if (formatSigned) { | // Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
// EMULATION_ERROR, EXECUTION,
// MISALIGNED_READ, MISALIGNED_WRITE,
// ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
// ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };
// Path: se/sics/mspsim/core/ADC12Plus.java
import se.sics.mspsim.core.EmulationLogger.WarningType;
import java.util.Arrays;
} else {
adc12ctl1 = value & 0xfffe;
startMem = (value >> 12) & 0xf;
shSource = (value >> 10) & 0x3;
adcDiv = ((value >> 5) & 0x7) + 1;
adcSSel = (value >> 3) & 0x03;
}
conSeq = (value >> 1) & 0x03;
if (DEBUG)
log("Set startMem: " + startMem + " SHSource: " + shSource
+ " ConSeq-mode:" + conSeq + " Div: " + adcDiv + " ADCSSEL: "
+ adcSSel);
break;
case ADC12CTL2: /* Low Power Specs */
if (enableConversion) {
/*
* Clock pre divider can't be modified when conversion is already
* enabled
*/
value &= 0xfeff;
value |= (adc12ctl2 & 0x100);
}
clockPredivider = ((value & 0x100) > 0) ? 4 : 1;
/* bit resolution 8, 10, 12 */
int tmp = (value & 0x30) >> 4;
tmp = (tmp <= 2) ? tmp * 2 : 4;
bitsResolution = tmp + 8;
formatSigned = ((value & 0x08) > 0);
if (formatSigned) { | logw(WarningType.EMULATION_ERROR, "signed format not implemented"); |
ransford/mspsim | se/sics/mspsim/core/Profiler.java | // Path: se/sics/mspsim/profiler/CallListener.java
// public interface CallListener {
//
// public void functionCall(Profiler source, CallEntry entry);
//
// public void functionReturn(Profiler source, CallEntry entry);
//
// }
//
// Path: se/sics/mspsim/util/MapEntry.java
// public class MapEntry {
//
// public static enum TYPE {function, variable, module}
//
// private final TYPE type;
// private final int address;
// private final String name;
// private final String file;
// private final boolean isLocal;
// private int size;
// private int dataAddr;
// private int dataSize;
// private int bssAddr;
// private int bssSize;
//
// public MapEntry(TYPE type, int address, int size, String name, String file, boolean isLocal) {
// this.type = type;
// this.address = address;
// this.name = name;
// this.file = file;
// this.isLocal = isLocal;
// this.size = size;
// }
//
// void setData(int dataAddr, int dataSize) {
// this.dataAddr = dataAddr;
// this.dataSize = dataSize;
// }
//
// void setBSS(int bssAddr, int bssSize) {
// this.bssAddr = bssAddr;
// this.bssSize = bssSize;
// }
//
// void setSize(int size) {
// this.size = size;
// }
//
// public int getSize() {
// return size;
// }
//
// public int getDataAddress() {
// return dataAddr;
// }
//
// public int getDataSize() {
// return dataSize;
// }
//
// public int getBSSAddress() {
// return bssAddr;
// }
//
// public int getBSSSize() {
// return bssSize;
// }
//
// public TYPE getType() {
// return type;
// }
//
// public int getAddress() {
// return address;
// }
//
// public String getName() {
// return name;
// }
//
// public String getFile() {
// return file;
// }
//
// public boolean isLocal() {
// return isLocal;
// }
//
// public String getInfo() {
// StringBuilder sb = new StringBuilder();
// sb.append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append('$').append(Utils.hex(address, 4)).append(' ').append(type).append(' ').append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
// }
| import java.io.PrintStream;
import java.util.Properties;
import se.sics.mspsim.profiler.CallListener;
import se.sics.mspsim.util.MapEntry; | /**
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of MSPSim.
*
* $Id$
*
* -----------------------------------------------------------------
*
* MSP430
*
* Author : Joakim Eriksson
* Created : Sun Oct 21 22:00:00 2007
* Updated : $Date$
* $Revision$
*/
package se.sics.mspsim.core;
public interface Profiler {
public static final String PARAM_FUNCTION_NAME_REGEXP = "function.regexp";
public static final String PARAM_PROFILE_CALLERS = "showcallers";
public static final String PARAM_SORT_MODE = "sortmode";
public void setCPU(MSP430Core cpu);
| // Path: se/sics/mspsim/profiler/CallListener.java
// public interface CallListener {
//
// public void functionCall(Profiler source, CallEntry entry);
//
// public void functionReturn(Profiler source, CallEntry entry);
//
// }
//
// Path: se/sics/mspsim/util/MapEntry.java
// public class MapEntry {
//
// public static enum TYPE {function, variable, module}
//
// private final TYPE type;
// private final int address;
// private final String name;
// private final String file;
// private final boolean isLocal;
// private int size;
// private int dataAddr;
// private int dataSize;
// private int bssAddr;
// private int bssSize;
//
// public MapEntry(TYPE type, int address, int size, String name, String file, boolean isLocal) {
// this.type = type;
// this.address = address;
// this.name = name;
// this.file = file;
// this.isLocal = isLocal;
// this.size = size;
// }
//
// void setData(int dataAddr, int dataSize) {
// this.dataAddr = dataAddr;
// this.dataSize = dataSize;
// }
//
// void setBSS(int bssAddr, int bssSize) {
// this.bssAddr = bssAddr;
// this.bssSize = bssSize;
// }
//
// void setSize(int size) {
// this.size = size;
// }
//
// public int getSize() {
// return size;
// }
//
// public int getDataAddress() {
// return dataAddr;
// }
//
// public int getDataSize() {
// return dataSize;
// }
//
// public int getBSSAddress() {
// return bssAddr;
// }
//
// public int getBSSSize() {
// return bssSize;
// }
//
// public TYPE getType() {
// return type;
// }
//
// public int getAddress() {
// return address;
// }
//
// public String getName() {
// return name;
// }
//
// public String getFile() {
// return file;
// }
//
// public boolean isLocal() {
// return isLocal;
// }
//
// public String getInfo() {
// StringBuilder sb = new StringBuilder();
// sb.append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append('$').append(Utils.hex(address, 4)).append(' ').append(type).append(' ').append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
// }
// Path: se/sics/mspsim/core/Profiler.java
import java.io.PrintStream;
import java.util.Properties;
import se.sics.mspsim.profiler.CallListener;
import se.sics.mspsim.util.MapEntry;
/**
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of MSPSim.
*
* $Id$
*
* -----------------------------------------------------------------
*
* MSP430
*
* Author : Joakim Eriksson
* Created : Sun Oct 21 22:00:00 2007
* Updated : $Date$
* $Revision$
*/
package se.sics.mspsim.core;
public interface Profiler {
public static final String PARAM_FUNCTION_NAME_REGEXP = "function.regexp";
public static final String PARAM_PROFILE_CALLERS = "showcallers";
public static final String PARAM_SORT_MODE = "sortmode";
public void setCPU(MSP430Core cpu);
| public void profileCall(MapEntry entry, long cycles, int from); |
ransford/mspsim | se/sics/mspsim/core/Profiler.java | // Path: se/sics/mspsim/profiler/CallListener.java
// public interface CallListener {
//
// public void functionCall(Profiler source, CallEntry entry);
//
// public void functionReturn(Profiler source, CallEntry entry);
//
// }
//
// Path: se/sics/mspsim/util/MapEntry.java
// public class MapEntry {
//
// public static enum TYPE {function, variable, module}
//
// private final TYPE type;
// private final int address;
// private final String name;
// private final String file;
// private final boolean isLocal;
// private int size;
// private int dataAddr;
// private int dataSize;
// private int bssAddr;
// private int bssSize;
//
// public MapEntry(TYPE type, int address, int size, String name, String file, boolean isLocal) {
// this.type = type;
// this.address = address;
// this.name = name;
// this.file = file;
// this.isLocal = isLocal;
// this.size = size;
// }
//
// void setData(int dataAddr, int dataSize) {
// this.dataAddr = dataAddr;
// this.dataSize = dataSize;
// }
//
// void setBSS(int bssAddr, int bssSize) {
// this.bssAddr = bssAddr;
// this.bssSize = bssSize;
// }
//
// void setSize(int size) {
// this.size = size;
// }
//
// public int getSize() {
// return size;
// }
//
// public int getDataAddress() {
// return dataAddr;
// }
//
// public int getDataSize() {
// return dataSize;
// }
//
// public int getBSSAddress() {
// return bssAddr;
// }
//
// public int getBSSSize() {
// return bssSize;
// }
//
// public TYPE getType() {
// return type;
// }
//
// public int getAddress() {
// return address;
// }
//
// public String getName() {
// return name;
// }
//
// public String getFile() {
// return file;
// }
//
// public boolean isLocal() {
// return isLocal;
// }
//
// public String getInfo() {
// StringBuilder sb = new StringBuilder();
// sb.append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append('$').append(Utils.hex(address, 4)).append(' ').append(type).append(' ').append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
// }
| import java.io.PrintStream;
import java.util.Properties;
import se.sics.mspsim.profiler.CallListener;
import se.sics.mspsim.util.MapEntry; | /**
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of MSPSim.
*
* $Id$
*
* -----------------------------------------------------------------
*
* MSP430
*
* Author : Joakim Eriksson
* Created : Sun Oct 21 22:00:00 2007
* Updated : $Date$
* $Revision$
*/
package se.sics.mspsim.core;
public interface Profiler {
public static final String PARAM_FUNCTION_NAME_REGEXP = "function.regexp";
public static final String PARAM_PROFILE_CALLERS = "showcallers";
public static final String PARAM_SORT_MODE = "sortmode";
public void setCPU(MSP430Core cpu);
public void profileCall(MapEntry entry, long cycles, int from);
public void profileReturn(long cycles);
public void profileInterrupt(int vector, long cycles);
public void profileRETI(long cycles);
public void resetProfile();
public void clearProfile();
| // Path: se/sics/mspsim/profiler/CallListener.java
// public interface CallListener {
//
// public void functionCall(Profiler source, CallEntry entry);
//
// public void functionReturn(Profiler source, CallEntry entry);
//
// }
//
// Path: se/sics/mspsim/util/MapEntry.java
// public class MapEntry {
//
// public static enum TYPE {function, variable, module}
//
// private final TYPE type;
// private final int address;
// private final String name;
// private final String file;
// private final boolean isLocal;
// private int size;
// private int dataAddr;
// private int dataSize;
// private int bssAddr;
// private int bssSize;
//
// public MapEntry(TYPE type, int address, int size, String name, String file, boolean isLocal) {
// this.type = type;
// this.address = address;
// this.name = name;
// this.file = file;
// this.isLocal = isLocal;
// this.size = size;
// }
//
// void setData(int dataAddr, int dataSize) {
// this.dataAddr = dataAddr;
// this.dataSize = dataSize;
// }
//
// void setBSS(int bssAddr, int bssSize) {
// this.bssAddr = bssAddr;
// this.bssSize = bssSize;
// }
//
// void setSize(int size) {
// this.size = size;
// }
//
// public int getSize() {
// return size;
// }
//
// public int getDataAddress() {
// return dataAddr;
// }
//
// public int getDataSize() {
// return dataSize;
// }
//
// public int getBSSAddress() {
// return bssAddr;
// }
//
// public int getBSSSize() {
// return bssSize;
// }
//
// public TYPE getType() {
// return type;
// }
//
// public int getAddress() {
// return address;
// }
//
// public String getName() {
// return name;
// }
//
// public String getFile() {
// return file;
// }
//
// public boolean isLocal() {
// return isLocal;
// }
//
// public String getInfo() {
// StringBuilder sb = new StringBuilder();
// sb.append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append('$').append(Utils.hex(address, 4)).append(' ').append(type).append(' ').append(name);
// if (file != null) {
// sb.append(" (");
// if (isLocal) sb.append("local in ");
// sb.append(file).append(')');
// } else if (isLocal) {
// sb.append(" (local)");
// }
// return sb.toString();
// }
// }
// Path: se/sics/mspsim/core/Profiler.java
import java.io.PrintStream;
import java.util.Properties;
import se.sics.mspsim.profiler.CallListener;
import se.sics.mspsim.util.MapEntry;
/**
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of MSPSim.
*
* $Id$
*
* -----------------------------------------------------------------
*
* MSP430
*
* Author : Joakim Eriksson
* Created : Sun Oct 21 22:00:00 2007
* Updated : $Date$
* $Revision$
*/
package se.sics.mspsim.core;
public interface Profiler {
public static final String PARAM_FUNCTION_NAME_REGEXP = "function.regexp";
public static final String PARAM_PROFILE_CALLERS = "showcallers";
public static final String PARAM_SORT_MODE = "sortmode";
public void setCPU(MSP430Core cpu);
public void profileCall(MapEntry entry, long cycles, int from);
public void profileReturn(long cycles);
public void profileInterrupt(int vector, long cycles);
public void profileRETI(long cycles);
public void resetProfile();
public void clearProfile();
| public void addCallListener(CallListener listener); |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/ManufacturerController.java | // Path: src/main/java/org/cejug/hurraa/model/Manufacturer.java
// @Entity
// public class Manufacturer implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ManufacturerBean.java
// @Stateless
// public class ManufacturerBean extends AbstractBean<Manufacturer> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public ManufacturerBean() {
// super(Manufacturer.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Manufacturer;
import org.cejug.hurraa.model.bean.ManufacturerBean;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("manufacturer")
@Controller
public class ManufacturerController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/Manufacturer.java
// @Entity
// public class Manufacturer implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ManufacturerBean.java
// @Stateless
// public class ManufacturerBean extends AbstractBean<Manufacturer> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public ManufacturerBean() {
// super(Manufacturer.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/ManufacturerController.java
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Manufacturer;
import org.cejug.hurraa.model.bean.ManufacturerBean;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("manufacturer")
@Controller
public class ManufacturerController {
@Inject
private Result result;
@Inject | private ManufacturerBean manufacturerBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/ManufacturerController.java | // Path: src/main/java/org/cejug/hurraa/model/Manufacturer.java
// @Entity
// public class Manufacturer implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ManufacturerBean.java
// @Stateless
// public class ManufacturerBean extends AbstractBean<Manufacturer> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public ManufacturerBean() {
// super(Manufacturer.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Manufacturer;
import org.cejug.hurraa.model.bean.ManufacturerBean;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("manufacturer")
@Controller
public class ManufacturerController {
@Inject
private Result result;
@Inject
private ManufacturerBean manufacturerBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(ManufacturerController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | // Path: src/main/java/org/cejug/hurraa/model/Manufacturer.java
// @Entity
// public class Manufacturer implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ManufacturerBean.java
// @Stateless
// public class ManufacturerBean extends AbstractBean<Manufacturer> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public ManufacturerBean() {
// super(Manufacturer.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/ManufacturerController.java
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Manufacturer;
import org.cejug.hurraa.model.bean.ManufacturerBean;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("manufacturer")
@Controller
public class ManufacturerController {
@Inject
private Result result;
@Inject
private ManufacturerBean manufacturerBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(ManufacturerController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | Manufacturer manufacturer = manufacturerBean.findById(id); |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/OccurrenceStateController.java | // Path: src/main/java/org/cejug/hurraa/model/OccurrenceState.java
// @Entity
// public class OccurrenceState implements Serializable {
//
// private static final long serialVersionUID = -4673686582019613496L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
//
// @NotEmpty
// private String name;
//
// private boolean active = true;
//
// public OccurrenceState() {}
//
// public OccurrenceState(Integer id) {
// super();
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// OccurrenceState other = (OccurrenceState) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/OccurrenceStateBean.java
// @Stateless
// public class OccurrenceStateBean extends AbstractBean<OccurrenceState>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public OccurrenceStateBean() {
// super(OccurrenceState.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
| import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.OccurrenceState;
import org.cejug.hurraa.model.bean.OccurrenceStateBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Controller
@Path("occurrence-state")
public class OccurrenceStateController {
private Result result; | // Path: src/main/java/org/cejug/hurraa/model/OccurrenceState.java
// @Entity
// public class OccurrenceState implements Serializable {
//
// private static final long serialVersionUID = -4673686582019613496L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
//
// @NotEmpty
// private String name;
//
// private boolean active = true;
//
// public OccurrenceState() {}
//
// public OccurrenceState(Integer id) {
// super();
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// OccurrenceState other = (OccurrenceState) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/OccurrenceStateBean.java
// @Stateless
// public class OccurrenceStateBean extends AbstractBean<OccurrenceState>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public OccurrenceStateBean() {
// super(OccurrenceState.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/OccurrenceStateController.java
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.OccurrenceState;
import org.cejug.hurraa.model.bean.OccurrenceStateBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Controller
@Path("occurrence-state")
public class OccurrenceStateController {
private Result result; | private OccurrenceStateBean occurrenceStateBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/OccurrenceStateController.java | // Path: src/main/java/org/cejug/hurraa/model/OccurrenceState.java
// @Entity
// public class OccurrenceState implements Serializable {
//
// private static final long serialVersionUID = -4673686582019613496L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
//
// @NotEmpty
// private String name;
//
// private boolean active = true;
//
// public OccurrenceState() {}
//
// public OccurrenceState(Integer id) {
// super();
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// OccurrenceState other = (OccurrenceState) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/OccurrenceStateBean.java
// @Stateless
// public class OccurrenceStateBean extends AbstractBean<OccurrenceState>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public OccurrenceStateBean() {
// super(OccurrenceState.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
| import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.OccurrenceState;
import org.cejug.hurraa.model.bean.OccurrenceStateBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Controller
@Path("occurrence-state")
public class OccurrenceStateController {
private Result result;
private OccurrenceStateBean occurrenceStateBean;
private ResourceBundle messagesBundle;
@Deprecated
public OccurrenceStateController() {
}
@Inject
public OccurrenceStateController(Result result , OccurrenceStateBean occurrenceStateBean , ResourceBundle messagesBundle ){
this.result = result;
this.occurrenceStateBean = occurrenceStateBean;
this.messagesBundle = messagesBundle;
}
@Path(value = { "", "/" })
public void index() {
result.forwardTo( this.getClass() ).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Integer id) { | // Path: src/main/java/org/cejug/hurraa/model/OccurrenceState.java
// @Entity
// public class OccurrenceState implements Serializable {
//
// private static final long serialVersionUID = -4673686582019613496L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
//
// @NotEmpty
// private String name;
//
// private boolean active = true;
//
// public OccurrenceState() {}
//
// public OccurrenceState(Integer id) {
// super();
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// OccurrenceState other = (OccurrenceState) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/OccurrenceStateBean.java
// @Stateless
// public class OccurrenceStateBean extends AbstractBean<OccurrenceState>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public OccurrenceStateBean() {
// super(OccurrenceState.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/OccurrenceStateController.java
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.OccurrenceState;
import org.cejug.hurraa.model.bean.OccurrenceStateBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Controller
@Path("occurrence-state")
public class OccurrenceStateController {
private Result result;
private OccurrenceStateBean occurrenceStateBean;
private ResourceBundle messagesBundle;
@Deprecated
public OccurrenceStateController() {
}
@Inject
public OccurrenceStateController(Result result , OccurrenceStateBean occurrenceStateBean , ResourceBundle messagesBundle ){
this.result = result;
this.occurrenceStateBean = occurrenceStateBean;
this.messagesBundle = messagesBundle;
}
@Path(value = { "", "/" })
public void index() {
result.forwardTo( this.getClass() ).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Integer id) { | OccurrenceState occurrenceState = occurrenceStateBean.findById(id); |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/ProblemTypeController.java | // Path: src/main/java/org/cejug/hurraa/model/ProblemType.java
// @Entity
// public class ProblemType {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// ProblemType other = (ProblemType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ProblemTypeBean.java
// @Stateless
// public class ProblemTypeBean extends AbstractBean<ProblemType> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public ProblemTypeBean() {
// super(ProblemType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.ProblemType;
import org.cejug.hurraa.model.bean.ProblemTypeBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
| /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("problem-type")
@Controller
public class ProblemTypeController {
@Inject
private Result result;
@Inject
| // Path: src/main/java/org/cejug/hurraa/model/ProblemType.java
// @Entity
// public class ProblemType {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// ProblemType other = (ProblemType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ProblemTypeBean.java
// @Stateless
// public class ProblemTypeBean extends AbstractBean<ProblemType> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public ProblemTypeBean() {
// super(ProblemType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/ProblemTypeController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.ProblemType;
import org.cejug.hurraa.model.bean.ProblemTypeBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("problem-type")
@Controller
public class ProblemTypeController {
@Inject
private Result result;
@Inject
| private ProblemTypeBean problemTypeBean;
|
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/ProblemTypeController.java | // Path: src/main/java/org/cejug/hurraa/model/ProblemType.java
// @Entity
// public class ProblemType {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// ProblemType other = (ProblemType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ProblemTypeBean.java
// @Stateless
// public class ProblemTypeBean extends AbstractBean<ProblemType> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public ProblemTypeBean() {
// super(ProblemType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.ProblemType;
import org.cejug.hurraa.model.bean.ProblemTypeBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
| /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("problem-type")
@Controller
public class ProblemTypeController {
@Inject
private Result result;
@Inject
private ProblemTypeBean problemTypeBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(this).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) {
| // Path: src/main/java/org/cejug/hurraa/model/ProblemType.java
// @Entity
// public class ProblemType {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// ProblemType other = (ProblemType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/ProblemTypeBean.java
// @Stateless
// public class ProblemTypeBean extends AbstractBean<ProblemType> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public ProblemTypeBean() {
// super(ProblemType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/ProblemTypeController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.ProblemType;
import org.cejug.hurraa.model.bean.ProblemTypeBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("problem-type")
@Controller
public class ProblemTypeController {
@Inject
private Result result;
@Inject
private ProblemTypeBean problemTypeBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(this).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) {
| ProblemType problemType = problemTypeBean.findById(id);
|
cejug/hurraa | src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
| import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.EquipmentType; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.bean;
@Stateless
public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
@PersistenceContext
private EntityManager entityManager;
public EquipmentModelBean() {
super(EquipmentModel.class);
}
@Override
protected EntityManager getEntityManager() {
return entityManager;
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public boolean isNameAvailable(String name){
TypedQuery<EquipmentModel> query = getEntityManager()
.createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
query.setParameter("name", name);
return query.getResultList().isEmpty();
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.EquipmentType;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.bean;
@Stateless
public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
@PersistenceContext
private EntityManager entityManager;
public EquipmentModelBean() {
super(EquipmentModel.class);
}
@Override
protected EntityManager getEntityManager() {
return entityManager;
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public boolean isNameAvailable(String name){
TypedQuery<EquipmentModel> query = getEntityManager()
.createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
query.setParameter("name", name);
return query.getResultList().isEmpty();
}
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) | public boolean isEquipmentTypeInUse(EquipmentType equipmentType){ |
cejug/hurraa | src/main/java/org/cejug/hurraa/validation/impl/EquipmentTypeInUseValidator.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
| import javax.inject.Inject;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.validation.impl;
public class EquipmentTypeInUseValidator implements ConstraintValidator< EquipmentTypeInUse , EquipmentType> {
@Inject | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/validation/impl/EquipmentTypeInUseValidator.java
import javax.inject.Inject;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.validation.impl;
public class EquipmentTypeInUseValidator implements ConstraintValidator< EquipmentTypeInUse , EquipmentType> {
@Inject | private EquipmentModelBean equipmentModelBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/UserController.java | // Path: src/main/java/org/cejug/hurraa/model/User.java
// @Entity
// public class User implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// @NotNull
// private String email;
//
// //TODO: Now the passoword will be open. Later in the project we will hash it.
// @NotNull
// private String password;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Override
// public String toString() {
// return "User [id=" + id + ", name=" + name + ", mail=" + email + "]";
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/UserBean.java
// @Stateless
// public class UserBean extends AbstractBean<User> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public UserBean() {
// super(User.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.User;
import org.cejug.hurraa.model.bean.UserBean;
import org.cejug.hurraa.producer.ValidationMessages;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("user")
@Controller
public class UserController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/User.java
// @Entity
// public class User implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// @NotNull
// private String email;
//
// //TODO: Now the passoword will be open. Later in the project we will hash it.
// @NotNull
// private String password;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Override
// public String toString() {
// return "User [id=" + id + ", name=" + name + ", mail=" + email + "]";
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/UserBean.java
// @Stateless
// public class UserBean extends AbstractBean<User> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public UserBean() {
// super(User.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/UserController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.User;
import org.cejug.hurraa.model.bean.UserBean;
import org.cejug.hurraa.producer.ValidationMessages;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("user")
@Controller
public class UserController {
@Inject
private Result result;
@Inject | private UserBean userBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/UserController.java | // Path: src/main/java/org/cejug/hurraa/model/User.java
// @Entity
// public class User implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// @NotNull
// private String email;
//
// //TODO: Now the passoword will be open. Later in the project we will hash it.
// @NotNull
// private String password;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Override
// public String toString() {
// return "User [id=" + id + ", name=" + name + ", mail=" + email + "]";
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/UserBean.java
// @Stateless
// public class UserBean extends AbstractBean<User> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public UserBean() {
// super(User.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.User;
import org.cejug.hurraa.model.bean.UserBean;
import org.cejug.hurraa.producer.ValidationMessages;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("user")
@Controller
public class UserController {
@Inject
private Result result;
@Inject
private UserBean userBean;
@Inject
private ResourceBundle messagesBundle;
@Inject
@ValidationMessages
private ResourceBundle validationBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(UserController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | // Path: src/main/java/org/cejug/hurraa/model/User.java
// @Entity
// public class User implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// private String name;
//
// @NotNull
// private String email;
//
// //TODO: Now the passoword will be open. Later in the project we will hash it.
// @NotNull
// private String password;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Override
// public String toString() {
// return "User [id=" + id + ", name=" + name + ", mail=" + email + "]";
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/UserBean.java
// @Stateless
// public class UserBean extends AbstractBean<User> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public UserBean() {
// super(User.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/UserController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.User;
import org.cejug.hurraa.model.bean.UserBean;
import org.cejug.hurraa.producer.ValidationMessages;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("user")
@Controller
public class UserController {
@Inject
private Result result;
@Inject
private UserBean userBean;
@Inject
private ResourceBundle messagesBundle;
@Inject
@ValidationMessages
private ResourceBundle validationBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(UserController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | User user = userBean.findById(id); |
cejug/hurraa | src/main/java/org/cejug/hurraa/validation/EquipmentTypeInUse.java | // Path: src/main/java/org/cejug/hurraa/validation/impl/EquipmentTypeInUseValidator.java
// public class EquipmentTypeInUseValidator implements ConstraintValidator< EquipmentTypeInUse , EquipmentType> {
//
// @Inject
// private EquipmentModelBean equipmentModelBean;
//
// @Override
// public void initialize(EquipmentTypeInUse constraintAnnotation) { }
//
// @Override
// public boolean isValid(EquipmentType value, ConstraintValidatorContext context) {
// return equipmentModelBean.isEquipmentTypeInUse(value);
// }
//
// }
| import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import org.cejug.hurraa.validation.impl.EquipmentTypeInUseValidator; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.validation;
@Target({ ElementType.PARAMETER , ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME) | // Path: src/main/java/org/cejug/hurraa/validation/impl/EquipmentTypeInUseValidator.java
// public class EquipmentTypeInUseValidator implements ConstraintValidator< EquipmentTypeInUse , EquipmentType> {
//
// @Inject
// private EquipmentModelBean equipmentModelBean;
//
// @Override
// public void initialize(EquipmentTypeInUse constraintAnnotation) { }
//
// @Override
// public boolean isValid(EquipmentType value, ConstraintValidatorContext context) {
// return equipmentModelBean.isEquipmentTypeInUse(value);
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/validation/EquipmentTypeInUse.java
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import org.cejug.hurraa.validation.impl.EquipmentTypeInUseValidator;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.validation;
@Target({ ElementType.PARAMETER , ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME) | @Constraint(validatedBy = { EquipmentTypeInUseValidator.class }) |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentModelController.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-model")
@Controller
public class EquipmentModelController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentModelController.java
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-model")
@Controller
public class EquipmentModelController {
@Inject
private Result result;
@Inject | private EquipmentModelBean equipmentModelBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentModelController.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-model")
@Controller
public class EquipmentModelController {
@Inject
private Result result;
@Inject
private EquipmentModelBean equipmentModelBean;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/EquipmentModel.java
// @NamedQueries(value = {
// @NamedQuery(name = "FIND_BY_NAME" , query = "FROM EquipmentModel e WHERE e.name = :name" )
// , @NamedQuery(name = "EQUIPMENTTYPE_IN_USE" , query = "FROM EquipmentModel e WHERE e.equipmentType = :equipmentType" )
// })
// @Entity
// public class EquipmentModel {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(nullable = false , unique = true)
// private String name;
//
// @ManyToOne(optional = false)
// private EquipmentType equipmentType;
//
// public EquipmentModel() { }
//
// public EquipmentModel(Long id) {
// this.id = id;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentModel other = (EquipmentModel) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
//
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public EquipmentType getEquipmentType() {
// return equipmentType;
// }
//
// public void setEquipmentType(EquipmentType equipmentType) {
// this.equipmentType = equipmentType;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentModelController.java
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentModel;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-model")
@Controller
public class EquipmentModelController {
@Inject
private Result result;
@Inject
private EquipmentModelBean equipmentModelBean;
@Inject | private EquipmentTypeBean equipmentTypeBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentTypeController.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-type")
@Controller
public class EquipmentTypeController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentTypeController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-type")
@Controller
public class EquipmentTypeController {
@Inject
private Result result;
@Inject | private EquipmentTypeBean equipmentTypeBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentTypeController.java | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-type")
@Controller
public class EquipmentTypeController {
@Inject
private Result result;
@Inject
private EquipmentTypeBean equipmentTypeBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(EquipmentTypeController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | // Path: src/main/java/org/cejug/hurraa/model/EquipmentType.java
// @NamedQueries({
// @NamedQuery(name="NAME_IN_USE" , query="FROM EquipmentType e WHERE e.name = :name")
// })
// @Entity
// @Unique(propertyName = "name" , identityPropertyName = "id" , entityClass = EquipmentType.class)
// public class EquipmentType {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// EquipmentType other = (EquipmentType) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentTypeBean.java
// @Stateless
// public class EquipmentTypeBean extends AbstractBean<EquipmentType> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public EquipmentTypeBean() {
// super(EquipmentType.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String value) {
// Query query = getEntityManager().createNamedQuery("NAME_IN_USE" , EquipmentType.class);
// query.setParameter("name", value);
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentTypeController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.EquipmentType;
import org.cejug.hurraa.model.bean.EquipmentTypeBean;
import org.cejug.hurraa.validation.EquipmentTypeInUse;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment-type")
@Controller
public class EquipmentTypeController {
@Inject
private Result result;
@Inject
private EquipmentTypeBean equipmentTypeBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(EquipmentTypeController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | EquipmentType equipmentType = equipmentTypeBean.findById(id); |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/SectorController.java | // Path: src/main/java/org/cejug/hurraa/model/Sector.java
// @Entity
// public class Sector implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// @Column(name = "name" , unique = true , nullable = false)
// private String name;
//
// @NotNull
// @Email
// private String email;
//
// private boolean active;
//
// private boolean respondsOccurrence;
//
// public Sector() {
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// public boolean isRespondsOccurrence() {
// return respondsOccurrence;
// }
//
// public void setRespondsOccurrence(boolean respondsOccurrence) {
// this.respondsOccurrence = respondsOccurrence;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Sector other = (Sector) obj;
// if (id == null) {
// if (other.id != null) {
// return false;
// }
// } else if (!id.equals(other.id)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/SectorBean.java
// @Stateless
// public class SectorBean extends AbstractBean<Sector> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public SectorBean() {
// super(Sector.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Sector;
import org.cejug.hurraa.model.bean.SectorBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path(value = "sector")
@Controller
public class SectorController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/Sector.java
// @Entity
// public class Sector implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// @Column(name = "name" , unique = true , nullable = false)
// private String name;
//
// @NotNull
// @Email
// private String email;
//
// private boolean active;
//
// private boolean respondsOccurrence;
//
// public Sector() {
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// public boolean isRespondsOccurrence() {
// return respondsOccurrence;
// }
//
// public void setRespondsOccurrence(boolean respondsOccurrence) {
// this.respondsOccurrence = respondsOccurrence;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Sector other = (Sector) obj;
// if (id == null) {
// if (other.id != null) {
// return false;
// }
// } else if (!id.equals(other.id)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/SectorBean.java
// @Stateless
// public class SectorBean extends AbstractBean<Sector> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public SectorBean() {
// super(Sector.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/SectorController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Sector;
import org.cejug.hurraa.model.bean.SectorBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path(value = "sector")
@Controller
public class SectorController {
@Inject
private Result result;
@Inject | private SectorBean sectorBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/SectorController.java | // Path: src/main/java/org/cejug/hurraa/model/Sector.java
// @Entity
// public class Sector implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// @Column(name = "name" , unique = true , nullable = false)
// private String name;
//
// @NotNull
// @Email
// private String email;
//
// private boolean active;
//
// private boolean respondsOccurrence;
//
// public Sector() {
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// public boolean isRespondsOccurrence() {
// return respondsOccurrence;
// }
//
// public void setRespondsOccurrence(boolean respondsOccurrence) {
// this.respondsOccurrence = respondsOccurrence;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Sector other = (Sector) obj;
// if (id == null) {
// if (other.id != null) {
// return false;
// }
// } else if (!id.equals(other.id)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/SectorBean.java
// @Stateless
// public class SectorBean extends AbstractBean<Sector> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public SectorBean() {
// super(Sector.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Sector;
import org.cejug.hurraa.model.bean.SectorBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path(value = "sector")
@Controller
public class SectorController {
@Inject
private Result result;
@Inject
private SectorBean sectorBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(SectorController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | // Path: src/main/java/org/cejug/hurraa/model/Sector.java
// @Entity
// public class Sector implements Serializable {
//
// private static final long serialVersionUID = 1L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotNull
// @Column(name = "name" , unique = true , nullable = false)
// private String name;
//
// @NotNull
// @Email
// private String email;
//
// private boolean active;
//
// private boolean respondsOccurrence;
//
// public Sector() {
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public boolean isActive() {
// return active;
// }
//
// public void setActive(boolean active) {
// this.active = active;
// }
//
// public boolean isRespondsOccurrence() {
// return respondsOccurrence;
// }
//
// public void setRespondsOccurrence(boolean respondsOccurrence) {
// this.respondsOccurrence = respondsOccurrence;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Sector other = (Sector) obj;
// if (id == null) {
// if (other.id != null) {
// return false;
// }
// } else if (!id.equals(other.id)) {
// return false;
// }
// return true;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/SectorBean.java
// @Stateless
// public class SectorBean extends AbstractBean<Sector> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public SectorBean() {
// super(Sector.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
// }
// Path: src/main/java/org/cejug/hurraa/controller/SectorController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Sector;
import org.cejug.hurraa.model.bean.SectorBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path(value = "sector")
@Controller
public class SectorController {
@Inject
private Result result;
@Inject
private SectorBean sectorBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(SectorController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | Sector sector = sectorBean.findById(id); |
cejug/hurraa | src/test/java/org/cejug/hurraa/model/builder/OccurrenceFieldUpdateBuilderTest.java | // Path: src/main/java/org/cejug/hurraa/model/OccurrenceFieldUpdate.java
// @Entity
// public class OccurrenceFieldUpdate implements Serializable {
//
// private static final long serialVersionUID = 5317998715760939361L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @ManyToOne
// @JoinColumn( name="occurrenceUpdate_id" )
// private OccurrenceUpdate occurrenceUpdate;
//
// @NotBlank
// private String fieldName;
//
// @NotNull
// private String oldValue;
//
// @NotNull
// private String newValue;
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("OccurrenceFieldUpdate [id=").append(id)
// .append(", occurrenceUpdate=").append(occurrenceUpdate)
// .append(", fieldName=").append(fieldName).append(", oldValue=")
// .append(oldValue).append(", newValue=").append(newValue)
// .append("]");
// return builder.toString();
// }
//
// public OccurrenceUpdate getOccurrenceUpdate() {
// return occurrenceUpdate;
// }
//
// public void setOccurrenceUpdate(OccurrenceUpdate occurrenceUpdate) {
// this.occurrenceUpdate = occurrenceUpdate;
// }
//
// public String getFieldName() {
// return fieldName;
// }
//
// public void setFieldName(String fieldName) {
// this.fieldName = fieldName;
// }
//
// public String getOldValue() {
// return oldValue;
// }
//
// public void setOldValue(String oldValue) {
// this.oldValue = oldValue;
// }
//
// public String getNewValue() {
// return newValue;
// }
//
// public void setNewValue(String newValue) {
// this.newValue = newValue;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// }
| import static org.junit.Assert.*;
import org.cejug.hurraa.model.OccurrenceFieldUpdate;
import org.junit.Before;
import org.junit.Test; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.builder;
public class OccurrenceFieldUpdateBuilderTest {
private OccurrenceFieldUpdateBuilder builder;
@Before
public void setUp(){
builder = new OccurrenceFieldUpdateBuilder();
}
@Test
public void doesCreateOccurrenceFieldUpdateWithTheEspecifiedFields(){
String fieldName = "My Field Name";
String newValue = "New Value";
String oldValue = "Old Value";
| // Path: src/main/java/org/cejug/hurraa/model/OccurrenceFieldUpdate.java
// @Entity
// public class OccurrenceFieldUpdate implements Serializable {
//
// private static final long serialVersionUID = 5317998715760939361L;
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @ManyToOne
// @JoinColumn( name="occurrenceUpdate_id" )
// private OccurrenceUpdate occurrenceUpdate;
//
// @NotBlank
// private String fieldName;
//
// @NotNull
// private String oldValue;
//
// @NotNull
// private String newValue;
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("OccurrenceFieldUpdate [id=").append(id)
// .append(", occurrenceUpdate=").append(occurrenceUpdate)
// .append(", fieldName=").append(fieldName).append(", oldValue=")
// .append(oldValue).append(", newValue=").append(newValue)
// .append("]");
// return builder.toString();
// }
//
// public OccurrenceUpdate getOccurrenceUpdate() {
// return occurrenceUpdate;
// }
//
// public void setOccurrenceUpdate(OccurrenceUpdate occurrenceUpdate) {
// this.occurrenceUpdate = occurrenceUpdate;
// }
//
// public String getFieldName() {
// return fieldName;
// }
//
// public void setFieldName(String fieldName) {
// this.fieldName = fieldName;
// }
//
// public String getOldValue() {
// return oldValue;
// }
//
// public void setOldValue(String oldValue) {
// this.oldValue = oldValue;
// }
//
// public String getNewValue() {
// return newValue;
// }
//
// public void setNewValue(String newValue) {
// this.newValue = newValue;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// }
// Path: src/test/java/org/cejug/hurraa/model/builder/OccurrenceFieldUpdateBuilderTest.java
import static org.junit.Assert.*;
import org.cejug.hurraa.model.OccurrenceFieldUpdate;
import org.junit.Before;
import org.junit.Test;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.model.builder;
public class OccurrenceFieldUpdateBuilderTest {
private OccurrenceFieldUpdateBuilder builder;
@Before
public void setUp(){
builder = new OccurrenceFieldUpdateBuilder();
}
@Test
public void doesCreateOccurrenceFieldUpdateWithTheEspecifiedFields(){
String fieldName = "My Field Name";
String newValue = "New Value";
String oldValue = "Old Value";
| OccurrenceFieldUpdate ofu = builder.withFieldName(fieldName).withNewValue(newValue).withOldValue(oldValue).build(); |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/CostCenterController.java | // Path: src/main/java/org/cejug/hurraa/model/CostCenter.java
// @Entity
// public class CostCenter {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// private String description;
//
// private String code;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// CostCenter other = (CostCenter) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public String getCode() {
// return code;
// }
//
// public void setCode(String code) {
// this.code = code;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/CostCenterBean.java
// @Stateless
// public class CostCenterBean extends AbstractBean<CostCenter> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public CostCenterBean() {
// super(CostCenter.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.CostCenter;
import org.cejug.hurraa.model.bean.CostCenterBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("cost-center")
@Controller
public class CostCenterController {
@Inject
private Result result;
@Inject | // Path: src/main/java/org/cejug/hurraa/model/CostCenter.java
// @Entity
// public class CostCenter {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// private String description;
//
// private String code;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// CostCenter other = (CostCenter) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public String getCode() {
// return code;
// }
//
// public void setCode(String code) {
// this.code = code;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/CostCenterBean.java
// @Stateless
// public class CostCenterBean extends AbstractBean<CostCenter> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public CostCenterBean() {
// super(CostCenter.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/CostCenterController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.CostCenter;
import org.cejug.hurraa.model.bean.CostCenterBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("cost-center")
@Controller
public class CostCenterController {
@Inject
private Result result;
@Inject | private CostCenterBean costCenterBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/CostCenterController.java | // Path: src/main/java/org/cejug/hurraa/model/CostCenter.java
// @Entity
// public class CostCenter {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// private String description;
//
// private String code;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// CostCenter other = (CostCenter) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public String getCode() {
// return code;
// }
//
// public void setCode(String code) {
// this.code = code;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/CostCenterBean.java
// @Stateless
// public class CostCenterBean extends AbstractBean<CostCenter> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public CostCenterBean() {
// super(CostCenter.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// }
| import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.CostCenter;
import org.cejug.hurraa.model.bean.CostCenterBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("cost-center")
@Controller
public class CostCenterController {
@Inject
private Result result;
@Inject
private CostCenterBean costCenterBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(CostCenterController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | // Path: src/main/java/org/cejug/hurraa/model/CostCenter.java
// @Entity
// public class CostCenter {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// private String name;
//
// private String description;
//
// private String code;
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((id == null) ? 0 : id.hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// CostCenter other = (CostCenter) obj;
// if (id == null) {
// if (other.id != null)
// return false;
// } else if (!id.equals(other.id))
// return false;
// return true;
// }
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getDescription() {
// return description;
// }
//
// public void setDescription(String description) {
// this.description = description;
// }
//
// public String getCode() {
// return code;
// }
//
// public void setCode(String code) {
// this.code = code;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/CostCenterBean.java
// @Stateless
// public class CostCenterBean extends AbstractBean<CostCenter> {
//
// @PersistenceContext
// private EntityManager manager;
//
// public CostCenterBean() {
// super(CostCenter.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return this.manager;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/CostCenterController.java
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.Validator;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.CostCenter;
import org.cejug.hurraa.model.bean.CostCenterBean;
import org.cejug.hurraa.validation.Unique;
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("cost-center")
@Controller
public class CostCenterController {
@Inject
private Result result;
@Inject
private CostCenterBean costCenterBean;
@Inject
private ResourceBundle messagesBundle;
@Path(value = {"", "/"})
public void index() {
result.forwardTo(CostCenterController.class).list();
}
@Path("form")
public void form() {
}
@Path("form/{id}")
public void form(Long id) { | CostCenter costCenter = costCenterBean.findById(id); |
cejug/hurraa | src/main/java/org/cejug/hurraa/validation/Unique.java | // Path: src/main/java/org/cejug/hurraa/validation/impl/UniqueValidator.java
// public class UniqueValidator implements ConstraintValidator< Unique , Object > {
//
// // @PersistenceContext
// // private EntityManager entityManager;
//
// @PersistenceUnit
// private EntityManagerFactory entityManagerFactory;
//
// private String fieldName;
// private String identityFieldName;
// @SuppressWarnings("rawtypes")
// private Class entityClass;
//
// @Override
// public void initialize(Unique constraintAnnotation) {
// fieldName = constraintAnnotation.propertyName();
// identityFieldName = constraintAnnotation.identityPropertyName();
// entityClass = constraintAnnotation.entityClass();
// }
//
// @Override
// public boolean isValid(Object value,
// ConstraintValidatorContext context) {
// return validateUniqueness(value, context);
// }
//
// public boolean validateUniqueness(Object value,
// ConstraintValidatorContext context){
// try {
// Field field = value.getClass().getDeclaredField(fieldName);
// field.setAccessible(true);
// Object fieldValue = field.get(value);
//
// field = value.getClass().getDeclaredField( identityFieldName );
// field.setAccessible(true);
// Object identityFieldValue = field.get(value);
//
//
// StringBuilder sb = new StringBuilder( String.format( "FROM %s a WHERE a.%s = :fieldValue" , entityClass.getSimpleName() , fieldName ) );
// if(identityFieldValue != null)
// sb.append( String.format( " AND a.%s != :identifyFieldValue" , identityFieldName ) );
//
// EntityManager entityManager = entityManagerFactory.createEntityManager();
//
// Query query = entityManager.createQuery( sb.toString() );
// query.setMaxResults(1);
// query.setParameter( "fieldValue", fieldValue );
// if(identityFieldValue != null)
// query.setParameter( "identifyFieldValue", identityFieldValue );
//
// return query.getResultList().isEmpty();
// } catch (IllegalArgumentException | IllegalAccessException e) {
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// } catch (SecurityException e) {
// e.printStackTrace();
// }
//
// return false;
// }
//
// }
| import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import org.cejug.hurraa.validation.impl.UniqueValidator; | package org.cejug.hurraa.validation;
@Target({ ElementType.TYPE , ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME) | // Path: src/main/java/org/cejug/hurraa/validation/impl/UniqueValidator.java
// public class UniqueValidator implements ConstraintValidator< Unique , Object > {
//
// // @PersistenceContext
// // private EntityManager entityManager;
//
// @PersistenceUnit
// private EntityManagerFactory entityManagerFactory;
//
// private String fieldName;
// private String identityFieldName;
// @SuppressWarnings("rawtypes")
// private Class entityClass;
//
// @Override
// public void initialize(Unique constraintAnnotation) {
// fieldName = constraintAnnotation.propertyName();
// identityFieldName = constraintAnnotation.identityPropertyName();
// entityClass = constraintAnnotation.entityClass();
// }
//
// @Override
// public boolean isValid(Object value,
// ConstraintValidatorContext context) {
// return validateUniqueness(value, context);
// }
//
// public boolean validateUniqueness(Object value,
// ConstraintValidatorContext context){
// try {
// Field field = value.getClass().getDeclaredField(fieldName);
// field.setAccessible(true);
// Object fieldValue = field.get(value);
//
// field = value.getClass().getDeclaredField( identityFieldName );
// field.setAccessible(true);
// Object identityFieldValue = field.get(value);
//
//
// StringBuilder sb = new StringBuilder( String.format( "FROM %s a WHERE a.%s = :fieldValue" , entityClass.getSimpleName() , fieldName ) );
// if(identityFieldValue != null)
// sb.append( String.format( " AND a.%s != :identifyFieldValue" , identityFieldName ) );
//
// EntityManager entityManager = entityManagerFactory.createEntityManager();
//
// Query query = entityManager.createQuery( sb.toString() );
// query.setMaxResults(1);
// query.setParameter( "fieldValue", fieldValue );
// if(identityFieldValue != null)
// query.setParameter( "identifyFieldValue", identityFieldValue );
//
// return query.getResultList().isEmpty();
// } catch (IllegalArgumentException | IllegalAccessException e) {
// e.printStackTrace();
// } catch (NoSuchFieldException e) {
// e.printStackTrace();
// } catch (SecurityException e) {
// e.printStackTrace();
// }
//
// return false;
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/validation/Unique.java
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import org.cejug.hurraa.validation.impl.UniqueValidator;
package org.cejug.hurraa.validation;
@Target({ ElementType.TYPE , ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME) | @Constraint(validatedBy = { UniqueValidator.class }) |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentController.java | // Path: src/main/java/org/cejug/hurraa/model/Equipment.java
// @Entity
// public class Equipment {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(name="serial_id")
// private String serialId;
//
// @NotNull
// @Column(name="end_of_warranty")
// private Date endOfWarranty;
//
// @Column(name="last_maintenance")
// private Date lastMaintenance;
//
// @Column(name="maintenance_description")
// private String maintenanceDescription;
//
// @ManyToOne(optional=false)
// private EquipmentModel equipmentModel;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getSerialId() {
// return serialId;
// }
//
// public void setSerialId(String serialId) {
// this.serialId = serialId;
// }
//
// public Date getEndOfWarranty() {
// return endOfWarranty;
// }
//
// public void setEndOfWarranty(Date endOfWarranty) {
// this.endOfWarranty = endOfWarranty;
// }
//
// public Date getLastMaintenance() {
// return lastMaintenance;
// }
//
// public void setLastMaintenance(Date lastMaintenance) {
// this.lastMaintenance = lastMaintenance;
// }
//
// public String getMaintenanceDescription() {
// return maintenanceDescription;
// }
//
// public void setMaintenanceDescription(String maintenanceDescription) {
// this.maintenanceDescription = maintenanceDescription;
// }
//
// public EquipmentModel getEquipmentModel() {
// return equipmentModel;
// }
//
// public void setEquipmentModel(EquipmentModel equipmentModel) {
// this.equipmentModel = equipmentModel;
// }
//
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentBean.java
// @Stateless
// public class EquipmentBean extends AbstractBean<Equipment>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentBean() {
// super(Equipment.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.text.DateFormat;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Equipment;
import org.cejug.hurraa.model.bean.EquipmentBean;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment")
@Controller
public class EquipmentController {
private Result result; | // Path: src/main/java/org/cejug/hurraa/model/Equipment.java
// @Entity
// public class Equipment {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(name="serial_id")
// private String serialId;
//
// @NotNull
// @Column(name="end_of_warranty")
// private Date endOfWarranty;
//
// @Column(name="last_maintenance")
// private Date lastMaintenance;
//
// @Column(name="maintenance_description")
// private String maintenanceDescription;
//
// @ManyToOne(optional=false)
// private EquipmentModel equipmentModel;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getSerialId() {
// return serialId;
// }
//
// public void setSerialId(String serialId) {
// this.serialId = serialId;
// }
//
// public Date getEndOfWarranty() {
// return endOfWarranty;
// }
//
// public void setEndOfWarranty(Date endOfWarranty) {
// this.endOfWarranty = endOfWarranty;
// }
//
// public Date getLastMaintenance() {
// return lastMaintenance;
// }
//
// public void setLastMaintenance(Date lastMaintenance) {
// this.lastMaintenance = lastMaintenance;
// }
//
// public String getMaintenanceDescription() {
// return maintenanceDescription;
// }
//
// public void setMaintenanceDescription(String maintenanceDescription) {
// this.maintenanceDescription = maintenanceDescription;
// }
//
// public EquipmentModel getEquipmentModel() {
// return equipmentModel;
// }
//
// public void setEquipmentModel(EquipmentModel equipmentModel) {
// this.equipmentModel = equipmentModel;
// }
//
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentBean.java
// @Stateless
// public class EquipmentBean extends AbstractBean<Equipment>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentBean() {
// super(Equipment.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentController.java
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.text.DateFormat;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Equipment;
import org.cejug.hurraa.model.bean.EquipmentBean;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment")
@Controller
public class EquipmentController {
private Result result; | private EquipmentBean equipmentBean; |
cejug/hurraa | src/main/java/org/cejug/hurraa/controller/EquipmentController.java | // Path: src/main/java/org/cejug/hurraa/model/Equipment.java
// @Entity
// public class Equipment {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(name="serial_id")
// private String serialId;
//
// @NotNull
// @Column(name="end_of_warranty")
// private Date endOfWarranty;
//
// @Column(name="last_maintenance")
// private Date lastMaintenance;
//
// @Column(name="maintenance_description")
// private String maintenanceDescription;
//
// @ManyToOne(optional=false)
// private EquipmentModel equipmentModel;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getSerialId() {
// return serialId;
// }
//
// public void setSerialId(String serialId) {
// this.serialId = serialId;
// }
//
// public Date getEndOfWarranty() {
// return endOfWarranty;
// }
//
// public void setEndOfWarranty(Date endOfWarranty) {
// this.endOfWarranty = endOfWarranty;
// }
//
// public Date getLastMaintenance() {
// return lastMaintenance;
// }
//
// public void setLastMaintenance(Date lastMaintenance) {
// this.lastMaintenance = lastMaintenance;
// }
//
// public String getMaintenanceDescription() {
// return maintenanceDescription;
// }
//
// public void setMaintenanceDescription(String maintenanceDescription) {
// this.maintenanceDescription = maintenanceDescription;
// }
//
// public EquipmentModel getEquipmentModel() {
// return equipmentModel;
// }
//
// public void setEquipmentModel(EquipmentModel equipmentModel) {
// this.equipmentModel = equipmentModel;
// }
//
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentBean.java
// @Stateless
// public class EquipmentBean extends AbstractBean<Equipment>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentBean() {
// super(Equipment.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
| import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.text.DateFormat;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Equipment;
import org.cejug.hurraa.model.bean.EquipmentBean;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique; | /*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment")
@Controller
public class EquipmentController {
private Result result;
private EquipmentBean equipmentBean; | // Path: src/main/java/org/cejug/hurraa/model/Equipment.java
// @Entity
// public class Equipment {
//
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Long id;
//
// @NotBlank
// @Column(name="serial_id")
// private String serialId;
//
// @NotNull
// @Column(name="end_of_warranty")
// private Date endOfWarranty;
//
// @Column(name="last_maintenance")
// private Date lastMaintenance;
//
// @Column(name="maintenance_description")
// private String maintenanceDescription;
//
// @ManyToOne(optional=false)
// private EquipmentModel equipmentModel;
//
// public Long getId() {
// return id;
// }
//
// public void setId(Long id) {
// this.id = id;
// }
//
// public String getSerialId() {
// return serialId;
// }
//
// public void setSerialId(String serialId) {
// this.serialId = serialId;
// }
//
// public Date getEndOfWarranty() {
// return endOfWarranty;
// }
//
// public void setEndOfWarranty(Date endOfWarranty) {
// this.endOfWarranty = endOfWarranty;
// }
//
// public Date getLastMaintenance() {
// return lastMaintenance;
// }
//
// public void setLastMaintenance(Date lastMaintenance) {
// this.lastMaintenance = lastMaintenance;
// }
//
// public String getMaintenanceDescription() {
// return maintenanceDescription;
// }
//
// public void setMaintenanceDescription(String maintenanceDescription) {
// this.maintenanceDescription = maintenanceDescription;
// }
//
// public EquipmentModel getEquipmentModel() {
// return equipmentModel;
// }
//
// public void setEquipmentModel(EquipmentModel equipmentModel) {
// this.equipmentModel = equipmentModel;
// }
//
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentBean.java
// @Stateless
// public class EquipmentBean extends AbstractBean<Equipment>{
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentBean() {
// super(Equipment.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// }
//
// Path: src/main/java/org/cejug/hurraa/model/bean/EquipmentModelBean.java
// @Stateless
// public class EquipmentModelBean extends AbstractBean<EquipmentModel> {
//
// @PersistenceContext
// private EntityManager entityManager;
//
// public EquipmentModelBean() {
// super(EquipmentModel.class);
// }
//
// @Override
// protected EntityManager getEntityManager() {
// return entityManager;
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isNameAvailable(String name){
// TypedQuery<EquipmentModel> query = getEntityManager()
// .createNamedQuery( "FIND_BY_NAME", EquipmentModel.class );
// query.setParameter("name", name);
// return query.getResultList().isEmpty();
// }
//
// @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
// public boolean isEquipmentTypeInUse(EquipmentType equipmentType){
// Query query = getEntityManager().createNamedQuery("EQUIPMENTTYPE_IN_USE" , EquipmentModel.class );
// query.setParameter("equipmentType", equipmentType );
// return query.getResultList().isEmpty();
// }
//
// }
// Path: src/main/java/org/cejug/hurraa/controller/EquipmentController.java
import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.validator.SimpleMessage;
import br.com.caelum.vraptor.validator.Validator;
import java.text.DateFormat;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javax.validation.Valid;
import org.cejug.hurraa.model.Equipment;
import org.cejug.hurraa.model.bean.EquipmentBean;
import org.cejug.hurraa.model.bean.EquipmentModelBean;
import org.cejug.hurraa.producer.ValidationMessages;
import org.cejug.hurraa.validation.Unique;
/*
* Hurraa is a web application conceived to manage resources
* in companies that need manage IT resources. Create issues
* and purchase IT materials. Copyright (C) 2014 CEJUG.
*
* Hurraa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hurraa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Hurraa. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
*/
package org.cejug.hurraa.controller;
@Path("equipment")
@Controller
public class EquipmentController {
private Result result;
private EquipmentBean equipmentBean; | private EquipmentModelBean equipmentModelBean; |
Countly/countly-sdk-android | sdk/src/androidTest/java/ly/count/android/sdk/ConnectionProcessorTests.java | // Path: sdk/src/main/java/ly/count/android/sdk/UtilsNetworking.java
// protected static String sha256Hash(String toHash) {
// String hash = null;
// try {
// MessageDigest digest = MessageDigest.getInstance("SHA-256");
// byte[] bytes = toHash.getBytes("UTF-8");
// digest.update(bytes, 0, bytes.length);
// bytes = digest.digest();
//
// // This is ~55x faster than looping and String.formating()
// hash = bytesToHex(bytes);
// } catch (Throwable e) {
// Countly.sharedInstance().L.e("Cannot tamper-protect params", e);
// }
// return hash;
// }
| import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static ly.count.android.sdk.UtilsNetworking.sha256Hash;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | testDeviceId = "123";
}
@Test
public void testConstructorAndGetters() {
final String serverURL = "https://secureserver";
final CountlyStore mockStore = mock(CountlyStore.class);
final DeviceId mockDeviceId = mock(DeviceId.class);
final ConnectionProcessor connectionProcessor1 = new ConnectionProcessor(serverURL, mockStore, mockDeviceId, null, null, moduleLog);
assertEquals(serverURL, connectionProcessor1.getServerURL());
assertSame(mockStore, connectionProcessor1.getCountlyStore());
assertSame(mockDeviceId, connectionProcessor1.getDeviceId());
}
/**
* Make sure that a correct url is generated
* No salt provided and no custom endpoint
*
* @throws IOException
*/
@Test
public void testUrlConnectionForEventData() throws IOException {
ConnectionProcessor.salt = null;
final String eventData = "blahblahblah";
final URLConnection urlConnection = connectionProcessor.urlConnectionForServerRequest(eventData, null);
assertEquals(30000, urlConnection.getConnectTimeout());
assertEquals(30000, urlConnection.getReadTimeout());
assertFalse(urlConnection.getUseCaches());
assertTrue(urlConnection.getDoInput());
assertFalse(urlConnection.getDoOutput()); | // Path: sdk/src/main/java/ly/count/android/sdk/UtilsNetworking.java
// protected static String sha256Hash(String toHash) {
// String hash = null;
// try {
// MessageDigest digest = MessageDigest.getInstance("SHA-256");
// byte[] bytes = toHash.getBytes("UTF-8");
// digest.update(bytes, 0, bytes.length);
// bytes = digest.digest();
//
// // This is ~55x faster than looping and String.formating()
// hash = bytesToHex(bytes);
// } catch (Throwable e) {
// Countly.sharedInstance().L.e("Cannot tamper-protect params", e);
// }
// return hash;
// }
// Path: sdk/src/androidTest/java/ly/count/android/sdk/ConnectionProcessorTests.java
import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static ly.count.android.sdk.UtilsNetworking.sha256Hash;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
testDeviceId = "123";
}
@Test
public void testConstructorAndGetters() {
final String serverURL = "https://secureserver";
final CountlyStore mockStore = mock(CountlyStore.class);
final DeviceId mockDeviceId = mock(DeviceId.class);
final ConnectionProcessor connectionProcessor1 = new ConnectionProcessor(serverURL, mockStore, mockDeviceId, null, null, moduleLog);
assertEquals(serverURL, connectionProcessor1.getServerURL());
assertSame(mockStore, connectionProcessor1.getCountlyStore());
assertSame(mockDeviceId, connectionProcessor1.getDeviceId());
}
/**
* Make sure that a correct url is generated
* No salt provided and no custom endpoint
*
* @throws IOException
*/
@Test
public void testUrlConnectionForEventData() throws IOException {
ConnectionProcessor.salt = null;
final String eventData = "blahblahblah";
final URLConnection urlConnection = connectionProcessor.urlConnectionForServerRequest(eventData, null);
assertEquals(30000, urlConnection.getConnectTimeout());
assertEquals(30000, urlConnection.getReadTimeout());
assertFalse(urlConnection.getUseCaches());
assertTrue(urlConnection.getDoInput());
assertFalse(urlConnection.getDoOutput()); | assertEquals(new URL(connectionProcessor.getServerURL() + "/i?" + eventData + "&checksum256=" + sha256Hash(eventData + null)), urlConnection.getURL()); |
authzforce/server | webapp/src/test/java/org/ow2/authzforce/webapp/test/pep/cxf/RESTfulPdpBasedAuthzInterceptorTest.java | // Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
//
// public STSServer() {
//
// }
//
// protected void run() {
// URL busFile = STSServer.class.getResource("cxf-sts.xml");
// Bus busLocal = new SpringBusFactory().createBus(busFile);
// BusFactory.setDefaultBus(busLocal);
// setBus(busLocal);
//
// try {
// new STSServer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
//
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//
// private TokenTestUtils() {
// // complete
// }
//
// public static void updateSTSPort(BindingProvider p, String port) {
// STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location != null && location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location != null && location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// }
//
// }
| import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer; | /*
* Copyright (C) 2012-2021 THALES.
*
* This file is part of AuthzForce CE.
*
* AuthzForce CE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AuthzForce CE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AuthzForce CE. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ow2.authzforce.webapp.test.pep.cxf;
/**
* The client authenticates to the STS using a username/password, and gets a signed holder-of-key SAML Assertion in return. This is presented to the service, who verifies proof-of-possession + the
* signature of the STS on the assertion. The CXF endpoint extracts roles from the Assertion + populates the security context. Note that the CXF endpoint requires a "role" Claim via the security
* policy.
*
* The CXF Endpoint has configured the XACMLAuthorizingInterceptor, which creates a XACML 3.0 request for dispatch to the PDP, and then enforces the PDP's decision. The PDP is a REST service, that
* requires that a user must have role "boss" to access the "doubleIt" operation ("alice" has this role, "bob" does not).
*/
public class RESTfulPdpBasedAuthzInterceptorTest extends AbstractBusClientServerTestBase
{
// public static final String PDP_PORT = allocatePort(PdpServer.class);
static
{
allocatePort(PdpServer.class);
}
private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
private static final String PORT = allocatePort(Server.class); | // Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
//
// public STSServer() {
//
// }
//
// protected void run() {
// URL busFile = STSServer.class.getResource("cxf-sts.xml");
// Bus busLocal = new SpringBusFactory().createBus(busFile);
// BusFactory.setDefaultBus(busLocal);
// setBus(busLocal);
//
// try {
// new STSServer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
//
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//
// private TokenTestUtils() {
// // complete
// }
//
// public static void updateSTSPort(BindingProvider p, String port) {
// STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location != null && location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location != null && location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// }
//
// }
// Path: webapp/src/test/java/org/ow2/authzforce/webapp/test/pep/cxf/RESTfulPdpBasedAuthzInterceptorTest.java
import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer;
/*
* Copyright (C) 2012-2021 THALES.
*
* This file is part of AuthzForce CE.
*
* AuthzForce CE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AuthzForce CE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AuthzForce CE. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ow2.authzforce.webapp.test.pep.cxf;
/**
* The client authenticates to the STS using a username/password, and gets a signed holder-of-key SAML Assertion in return. This is presented to the service, who verifies proof-of-possession + the
* signature of the STS on the assertion. The CXF endpoint extracts roles from the Assertion + populates the security context. Note that the CXF endpoint requires a "role" Claim via the security
* policy.
*
* The CXF Endpoint has configured the XACMLAuthorizingInterceptor, which creates a XACML 3.0 request for dispatch to the PDP, and then enforces the PDP's decision. The PDP is a REST service, that
* requires that a user must have role "boss" to access the "doubleIt" operation ("alice" has this role, "bob" does not).
*/
public class RESTfulPdpBasedAuthzInterceptorTest extends AbstractBusClientServerTestBase
{
// public static final String PDP_PORT = allocatePort(PdpServer.class);
static
{
allocatePort(PdpServer.class);
}
private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
private static final String PORT = allocatePort(Server.class); | private static final String STS_PORT = allocatePort(STSServer.class); |
authzforce/server | webapp/src/test/java/org/ow2/authzforce/webapp/test/pep/cxf/RESTfulPdpBasedAuthzInterceptorTest.java | // Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
//
// public STSServer() {
//
// }
//
// protected void run() {
// URL busFile = STSServer.class.getResource("cxf-sts.xml");
// Bus busLocal = new SpringBusFactory().createBus(busFile);
// BusFactory.setDefaultBus(busLocal);
// setBus(busLocal);
//
// try {
// new STSServer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
//
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//
// private TokenTestUtils() {
// // complete
// }
//
// public static void updateSTSPort(BindingProvider p, String port) {
// STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location != null && location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location != null && location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// }
//
// }
| import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer; | launchServer(PdpServer.class, true));
}
private DoubleItPortType doubleItWsPort = null;
@Before
public void beforeTest() throws Exception
{
/*
* Client
*/
final URL busFile = RESTfulPdpBasedAuthzInterceptorTest.class.getResource("cxf-ws-client.xml");
this.createBus(busFile.toString());
BusFactory.setThreadDefaultBus(this.getBus());
final Service service = Service.create(DOUBLEIT_WSDL, SERVICE_QNAME);
doubleItWsPort = service.getPort(DOUBLEIT_WS_PORT_QNAME, DoubleItPortType.class);
}
private static void doubleIt(final DoubleItPortType port, final int numToDouble)
{
final int resp = port.doubleIt(numToDouble);
assertEquals(numToDouble * 2, resp);
}
@org.junit.Test
public void testAuthorizedRequest() throws Exception
{
updateAddressPort(doubleItWsPort, PORT);
final Client cxfClient = ClientProxy.getClient(doubleItWsPort);
cxfClient.getRequestContext().put("ws-security.username", "alice"); | // Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/STSServer.java
// public class STSServer extends AbstractBusTestServerBase {
//
// public STSServer() {
//
// }
//
// protected void run() {
// URL busFile = STSServer.class.getResource("cxf-sts.xml");
// Bus busLocal = new SpringBusFactory().createBus(busFile);
// BusFactory.setDefaultBus(busLocal);
// setBus(busLocal);
//
// try {
// new STSServer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
//
// Path: webapp/src/test/java/org/apache/coheigea/cxf/sts/xacml/common/TokenTestUtils.java
// public final class TokenTestUtils {
//
// private TokenTestUtils() {
// // complete
// }
//
// public static void updateSTSPort(BindingProvider p, String port) {
// STSClient stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT);
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location != null && location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location != null && location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// stsClient = (STSClient)p.getRequestContext().get(SecurityConstants.STS_CLIENT + ".sct");
// if (stsClient != null) {
// String location = stsClient.getWsdlLocation();
// if (location.contains("8080")) {
// stsClient.setWsdlLocation(location.replace("8080", port));
// } else if (location.contains("8443")) {
// stsClient.setWsdlLocation(location.replace("8443", port));
// }
// }
// }
//
// }
// Path: webapp/src/test/java/org/ow2/authzforce/webapp/test/pep/cxf/RESTfulPdpBasedAuthzInterceptorTest.java
import org.apache.coheigea.cxf.sts.xacml.common.TokenTestUtils;
import org.apache.cxf.BusFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.example.contract.doubleit.DoubleItPortType;
import org.junit.Before;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import java.net.URLClassLoader;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
import org.apache.coheigea.cxf.sts.xacml.common.STSServer;
launchServer(PdpServer.class, true));
}
private DoubleItPortType doubleItWsPort = null;
@Before
public void beforeTest() throws Exception
{
/*
* Client
*/
final URL busFile = RESTfulPdpBasedAuthzInterceptorTest.class.getResource("cxf-ws-client.xml");
this.createBus(busFile.toString());
BusFactory.setThreadDefaultBus(this.getBus());
final Service service = Service.create(DOUBLEIT_WSDL, SERVICE_QNAME);
doubleItWsPort = service.getPort(DOUBLEIT_WS_PORT_QNAME, DoubleItPortType.class);
}
private static void doubleIt(final DoubleItPortType port, final int numToDouble)
{
final int resp = port.doubleIt(numToDouble);
assertEquals(numToDouble * 2, resp);
}
@org.junit.Test
public void testAuthorizedRequest() throws Exception
{
updateAddressPort(doubleItWsPort, PORT);
final Client cxfClient = ClientProxy.getClient(doubleItWsPort);
cxfClient.getRequestContext().put("ws-security.username", "alice"); | TokenTestUtils.updateSTSPort((BindingProvider) doubleItWsPort, STS_PORT); |
martincooper/java-datatable | src/test/java/GuardTests.java | // Path: src/main/java/com/github/martincooper/datatable/Guard.java
// public class Guard {
//
// /**
// * Asserts the value is not null. Throws an IllegalArgumentException if it is.
// *
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static void notNull(Object argument, String name) {
// if (argument == null)
// throw new IllegalArgumentException("Invalid value [NULL] for argument " + name);
// }
//
// /**
// * Asserts the argument, and none of it's iterable items, is null.
// * Throws an IllegalArgumentException if it is.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static <T> void itemsNotNull(Iterable<T> argument, String name) {
// notNull(argument, name);
//
// // Check none of the items in the collection is null.
// if (!Stream.ofAll(argument).find(Objects::isNull).isEmpty())
// throw new IllegalArgumentException("Invalid value [NULL] in collection for argument " + name);
// }
//
// /**
// * Asserts the argument, and none of it's items, is null.
// * Throws an IllegalArgumentException if it is.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static <T> void itemsNotNull(T[] argument, String name) {
// notNull(argument, name);
// itemsNotNull(Stream.of(argument), name);
// }
//
// /**
// * Asserts the argument is not null. Returns in a Try.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// * @return Returns a Try testing the argument being null.
// */
// public static <T> Try<T> tryNotNull(T argument, String name) {
// return argument == null
// ? Try.failure(new IllegalArgumentException("Invalid value [NULL] for argument " + name))
// : Try.success(argument);
// }
// }
| import com.github.martincooper.datatable.Guard;
import io.vavr.collection.List;
import io.vavr.control.Try;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; |
/**
* Unit Tests for the Guard class.
* Created by Martin Cooper on 13/07/2017.
*/
public class GuardTests {
@Test
public void testSingleValidArgument() {
try{ | // Path: src/main/java/com/github/martincooper/datatable/Guard.java
// public class Guard {
//
// /**
// * Asserts the value is not null. Throws an IllegalArgumentException if it is.
// *
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static void notNull(Object argument, String name) {
// if (argument == null)
// throw new IllegalArgumentException("Invalid value [NULL] for argument " + name);
// }
//
// /**
// * Asserts the argument, and none of it's iterable items, is null.
// * Throws an IllegalArgumentException if it is.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static <T> void itemsNotNull(Iterable<T> argument, String name) {
// notNull(argument, name);
//
// // Check none of the items in the collection is null.
// if (!Stream.ofAll(argument).find(Objects::isNull).isEmpty())
// throw new IllegalArgumentException("Invalid value [NULL] in collection for argument " + name);
// }
//
// /**
// * Asserts the argument, and none of it's items, is null.
// * Throws an IllegalArgumentException if it is.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// */
// public static <T> void itemsNotNull(T[] argument, String name) {
// notNull(argument, name);
// itemsNotNull(Stream.of(argument), name);
// }
//
// /**
// * Asserts the argument is not null. Returns in a Try.
// *
// * @param <T> The argument type.
// * @param argument The argument to check.
// * @param name The name of the argument.
// * @return Returns a Try testing the argument being null.
// */
// public static <T> Try<T> tryNotNull(T argument, String name) {
// return argument == null
// ? Try.failure(new IllegalArgumentException("Invalid value [NULL] for argument " + name))
// : Try.success(argument);
// }
// }
// Path: src/test/java/GuardTests.java
import com.github.martincooper.datatable.Guard;
import io.vavr.collection.List;
import io.vavr.control.Try;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* Unit Tests for the Guard class.
* Created by Martin Cooper on 13/07/2017.
*/
public class GuardTests {
@Test
public void testSingleValidArgument() {
try{ | Guard.notNull("Test", "ArgumentOne"); |
martincooper/java-datatable | src/main/java/com/github/martincooper/datatable/DataRowCollectionBase.java | // Path: src/main/java/com/github/martincooper/datatable/TransformCollector.java
// public static <T, U> TransformCollector<T, U> transform(Function<Stream<T>, U> function) {
// return new TransformCollector<>(function);
// }
| import io.vavr.collection.*;
import io.vavr.control.Try;
import java.util.Iterator;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import static com.github.martincooper.datatable.TransformCollector.transform; | package com.github.martincooper.datatable;
/**
* DataRowCollectionBase. Handles a collection of DataRows
* Created by Martin Cooper on 17/07/2017.
*/
abstract class DataRowCollectionBase implements Iterable<DataRow> {
protected final DataTable table;
protected final Vector<DataRow> rows;
/**
* Protected DataRow constructor.
* Use 'build' to create instance.
*
* @param table The DataTable the DataRow is pointing to.
* @param rows The DataRows.
*/
DataRowCollectionBase(DataTable table, Iterable<DataRow> rows) {
this.table = table;
this.rows = Vector.ofAll(rows);
}
/**
* Returns an iterator over elements of DataRow.
*
* @return an Iterator.
*/
@Override
public Iterator<DataRow> iterator() {
return rows.iterator();
}
/**
* Returns the Data Row at the specified index.
*
* @param rowIndex The row index.
* @return Returns the Data Row.
*/
public DataRow get(Integer rowIndex) {
return this.rows.get(rowIndex);
}
/**
* The number of rows in the collection.
*
* @return Returns the number of rows.
*/
public Integer rowCount() {
return this.rows.length();
}
/**
* Returns access to the Data Row collection as a sequence of Data Rows.
*
* @return Returns the rows.
*/
public Seq<DataRow> asSeq() {
return this.rows;
}
/**
* Filters the row data using the specified predicate,
* returning the results as a DataView over the original table.
* @param predicate The filter criteria.
* @return Returns a DataView with the filter results.
*/
public DataView filter(Predicate<DataRow> predicate) {
return this.rows
.filter(predicate) | // Path: src/main/java/com/github/martincooper/datatable/TransformCollector.java
// public static <T, U> TransformCollector<T, U> transform(Function<Stream<T>, U> function) {
// return new TransformCollector<>(function);
// }
// Path: src/main/java/com/github/martincooper/datatable/DataRowCollectionBase.java
import io.vavr.collection.*;
import io.vavr.control.Try;
import java.util.Iterator;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import static com.github.martincooper.datatable.TransformCollector.transform;
package com.github.martincooper.datatable;
/**
* DataRowCollectionBase. Handles a collection of DataRows
* Created by Martin Cooper on 17/07/2017.
*/
abstract class DataRowCollectionBase implements Iterable<DataRow> {
protected final DataTable table;
protected final Vector<DataRow> rows;
/**
* Protected DataRow constructor.
* Use 'build' to create instance.
*
* @param table The DataTable the DataRow is pointing to.
* @param rows The DataRows.
*/
DataRowCollectionBase(DataTable table, Iterable<DataRow> rows) {
this.table = table;
this.rows = Vector.ofAll(rows);
}
/**
* Returns an iterator over elements of DataRow.
*
* @return an Iterator.
*/
@Override
public Iterator<DataRow> iterator() {
return rows.iterator();
}
/**
* Returns the Data Row at the specified index.
*
* @param rowIndex The row index.
* @return Returns the Data Row.
*/
public DataRow get(Integer rowIndex) {
return this.rows.get(rowIndex);
}
/**
* The number of rows in the collection.
*
* @return Returns the number of rows.
*/
public Integer rowCount() {
return this.rows.length();
}
/**
* Returns access to the Data Row collection as a sequence of Data Rows.
*
* @return Returns the rows.
*/
public Seq<DataRow> asSeq() {
return this.rows;
}
/**
* Filters the row data using the specified predicate,
* returning the results as a DataView over the original table.
* @param predicate The filter criteria.
* @return Returns a DataView with the filter results.
*/
public DataView filter(Predicate<DataRow> predicate) {
return this.rows
.filter(predicate) | .collect(transform(rows -> DataView.build(this.table, rows).get())); |
DDTH/ddth-id | ddth-id-core/src/test/java/com/github/ddth/id/test/benchmark/BenchmarkInmem.java | // Path: ddth-id-core/src/main/java/com/github/ddth/id/InmemIdGenerator.java
// public class InmemIdGenerator extends SerialIdGenerator {
//
// private static Logger LOGGER = LoggerFactory.getLogger(InmemIdGenerator.class);
//
// private LoadingCache<String, AtomicLong> counters;
//
// /**
// * {@inheritDoc}
// */
// @Override
// public InmemIdGenerator init() {
// if (counters == null) {
// counters = CacheBuilder.newBuilder().build(new CacheLoader<String, AtomicLong>() {
// @Override
// public AtomicLong load(String key) throws Exception {
// return new AtomicLong(0);
// }
// });
// }
//
// super.init();
//
// return this;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public void destroy() {
// try {
// super.destroy();
// } catch (Exception e) {
// LOGGER.warn(e.getMessage(), e);
// }
//
// if (counters != null) {
// try {
// counters.invalidateAll();
// } catch (Exception e) {
// LOGGER.warn(e.getMessage(), e);
// } finally {
// counters = null;
// }
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public long nextId(String namespace) {
// try {
// return counters.get(namespace).incrementAndGet();
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return -1;
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public long currentId(String namespace) {
// try {
// return counters.get(namespace).get();
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return -1;
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean setValue(String namespace, long value) {
// if (value < 0) {
// throw new IdException("Id value must be greater or equal to 0!");
// }
// try {
// counters.get(namespace).set(value);
// return true;
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return false;
// }
// }
// }
| import java.sql.SQLException;
import com.github.ddth.id.InmemIdGenerator; | package com.github.ddth.id.test.benchmark;
public class BenchmarkInmem extends BaseBenchmarkSerialId {
public static void main(String[] args) throws SQLException, InterruptedException {
int numRuns, numThreads, numNamespaces;
try {
numRuns = Integer.parseInt(System.getProperty("numRuns"));
} catch (Exception e) {
numRuns = 512000;
}
try {
numThreads = Integer.parseInt(System.getProperty("numThreads"));
} catch (Exception e) {
numThreads = 8;
}
try {
numNamespaces = Integer.parseInt(System.getProperty("numNamespaces"));
} catch (Exception e) {
numNamespaces = 4;
}
| // Path: ddth-id-core/src/main/java/com/github/ddth/id/InmemIdGenerator.java
// public class InmemIdGenerator extends SerialIdGenerator {
//
// private static Logger LOGGER = LoggerFactory.getLogger(InmemIdGenerator.class);
//
// private LoadingCache<String, AtomicLong> counters;
//
// /**
// * {@inheritDoc}
// */
// @Override
// public InmemIdGenerator init() {
// if (counters == null) {
// counters = CacheBuilder.newBuilder().build(new CacheLoader<String, AtomicLong>() {
// @Override
// public AtomicLong load(String key) throws Exception {
// return new AtomicLong(0);
// }
// });
// }
//
// super.init();
//
// return this;
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public void destroy() {
// try {
// super.destroy();
// } catch (Exception e) {
// LOGGER.warn(e.getMessage(), e);
// }
//
// if (counters != null) {
// try {
// counters.invalidateAll();
// } catch (Exception e) {
// LOGGER.warn(e.getMessage(), e);
// } finally {
// counters = null;
// }
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public long nextId(String namespace) {
// try {
// return counters.get(namespace).incrementAndGet();
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return -1;
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public long currentId(String namespace) {
// try {
// return counters.get(namespace).get();
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return -1;
// }
// }
//
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean setValue(String namespace, long value) {
// if (value < 0) {
// throw new IdException("Id value must be greater or equal to 0!");
// }
// try {
// counters.get(namespace).set(value);
// return true;
// } catch (ExecutionException e) {
// LOGGER.warn(e.getMessage(), e);
// return false;
// }
// }
// }
// Path: ddth-id-core/src/test/java/com/github/ddth/id/test/benchmark/BenchmarkInmem.java
import java.sql.SQLException;
import com.github.ddth.id.InmemIdGenerator;
package com.github.ddth.id.test.benchmark;
public class BenchmarkInmem extends BaseBenchmarkSerialId {
public static void main(String[] args) throws SQLException, InterruptedException {
int numRuns, numThreads, numNamespaces;
try {
numRuns = Integer.parseInt(System.getProperty("numRuns"));
} catch (Exception e) {
numRuns = 512000;
}
try {
numThreads = Integer.parseInt(System.getProperty("numThreads"));
} catch (Exception e) {
numThreads = 8;
}
try {
numNamespaces = Integer.parseInt(System.getProperty("numNamespaces"));
} catch (Exception e) {
numNamespaces = 4;
}
| try (InmemIdGenerator idGen = new InmemIdGenerator()) { |
DDTH/ddth-id | ddth-id-core/src/main/java/com/github/ddth/id/InmemIdGenerator.java | // Path: ddth-id-core/src/main/java/com/github/ddth/id/utils/IdException.java
// public class IdException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public IdException() {
// }
//
// public IdException(String message) {
// super(message);
// }
//
// public IdException(Throwable cause) {
// super(cause);
// }
//
// public IdException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Thrown to indicate that the operation is not supported/implemented.
// *
// * @author Thanh Nguyen <[email protected]>
// * @since 0.5.0
// */
// public static class OperationNotSupportedException extends IdException {
// private static final long serialVersionUID = 1L;
//
// public OperationNotSupportedException() {
// }
//
// public OperationNotSupportedException(String message) {
// super(message);
// }
// }
//
// /**
// * Thrown to indicate that the operation has failed due to timeout.
// *
// * @author Thanh Nguyen <[email protected]>
// * @since 0.5.0
// */
// public static class OperationTimeoutException extends IdException {
//
// private static final long serialVersionUID = 1L;
//
// public OperationTimeoutException() {
// }
//
// public OperationTimeoutException(String message) {
// super(message);
// }
//
// public OperationTimeoutException(Throwable cause) {
// super(cause);
// }
//
// public OperationTimeoutException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// }
| import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.ddth.id.utils.IdException;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; | */
@Override
public long nextId(String namespace) {
try {
return counters.get(namespace).incrementAndGet();
} catch (ExecutionException e) {
LOGGER.warn(e.getMessage(), e);
return -1;
}
}
/**
* {@inheritDoc}
*/
@Override
public long currentId(String namespace) {
try {
return counters.get(namespace).get();
} catch (ExecutionException e) {
LOGGER.warn(e.getMessage(), e);
return -1;
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean setValue(String namespace, long value) {
if (value < 0) { | // Path: ddth-id-core/src/main/java/com/github/ddth/id/utils/IdException.java
// public class IdException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public IdException() {
// }
//
// public IdException(String message) {
// super(message);
// }
//
// public IdException(Throwable cause) {
// super(cause);
// }
//
// public IdException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Thrown to indicate that the operation is not supported/implemented.
// *
// * @author Thanh Nguyen <[email protected]>
// * @since 0.5.0
// */
// public static class OperationNotSupportedException extends IdException {
// private static final long serialVersionUID = 1L;
//
// public OperationNotSupportedException() {
// }
//
// public OperationNotSupportedException(String message) {
// super(message);
// }
// }
//
// /**
// * Thrown to indicate that the operation has failed due to timeout.
// *
// * @author Thanh Nguyen <[email protected]>
// * @since 0.5.0
// */
// public static class OperationTimeoutException extends IdException {
//
// private static final long serialVersionUID = 1L;
//
// public OperationTimeoutException() {
// }
//
// public OperationTimeoutException(String message) {
// super(message);
// }
//
// public OperationTimeoutException(Throwable cause) {
// super(cause);
// }
//
// public OperationTimeoutException(String message, Throwable cause) {
// super(message, cause);
// }
// }
//
// }
// Path: ddth-id-core/src/main/java/com/github/ddth/id/InmemIdGenerator.java
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.ddth.id.utils.IdException;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
*/
@Override
public long nextId(String namespace) {
try {
return counters.get(namespace).incrementAndGet();
} catch (ExecutionException e) {
LOGGER.warn(e.getMessage(), e);
return -1;
}
}
/**
* {@inheritDoc}
*/
@Override
public long currentId(String namespace) {
try {
return counters.get(namespace).get();
} catch (ExecutionException e) {
LOGGER.warn(e.getMessage(), e);
return -1;
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean setValue(String namespace, long value) {
if (value < 0) { | throw new IdException("Id value must be greater or equal to 0!"); |
uPhyca/robota | robota/src/main/java/com/uphyca/robota/ui/BotActivity.java | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
| import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
// Path: robota/src/main/java/com/uphyca/robota/ui/BotActivity.java
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken | StringPreference mApiTokenPreference; |
uPhyca/robota | robota/src/main/java/com/uphyca/robota/ui/BotActivity.java | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
| import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken
StringPreference mApiTokenPreference;
@Inject
@Enabled | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
// Path: robota/src/main/java/com/uphyca/robota/ui/BotActivity.java
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken
StringPreference mApiTokenPreference;
@Inject
@Enabled | BooleanPreference mEnabledPreference; |
uPhyca/robota | robota/src/main/java/com/uphyca/robota/ui/BotActivity.java | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
| import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick; | /*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken
StringPreference mApiTokenPreference;
@Inject
@Enabled
BooleanPreference mEnabledPreference;
@InjectView(R.id.api_token)
EditText mApiToken;
@InjectView(R.id.update)
Button mUpdateButton;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); | // Path: robota/src/main/java/com/uphyca/robota/InjectionUtils.java
// public abstract class InjectionUtils {
//
// private InjectionUtils() {
// }
//
// public static ObjectGraph getObjectGraph(Context context) {
// return RobotaApplication.class.cast(context.getApplicationContext())
// .getObjectGraph();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/BooleanPreference.java
// public class BooleanPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final boolean mDefaultValue;
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, false);
// }
//
// public BooleanPreference(SharedPreferences sharedPreferences, String key, boolean defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public boolean get() {
// return mSharedPreferences.getBoolean(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(boolean value) {
// mSharedPreferences.edit()
// .putBoolean(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
//
// Path: robota/src/main/java/com/uphyca/robota/data/prefs/StringPreference.java
// public class StringPreference {
//
// private final SharedPreferences mSharedPreferences;
// private final String mKey;
// private final String mDefaultValue;
//
// public StringPreference(SharedPreferences sharedPreferences, String key) {
// this(sharedPreferences, key, null);
// }
//
// public StringPreference(SharedPreferences sharedPreferences, String key, String defaultValue) {
// mSharedPreferences = sharedPreferences;
// mKey = key;
// mDefaultValue = defaultValue;
// }
//
// public String get() {
// return mSharedPreferences.getString(mKey, mDefaultValue);
// }
//
// public boolean isSet() {
// return mSharedPreferences.contains(mKey);
// }
//
// public void set(String value) {
// mSharedPreferences.edit()
// .putString(mKey, value)
// .apply();
// }
//
// public void delete() {
// mSharedPreferences.edit()
// .remove(mKey)
// .apply();
// }
// }
// Path: robota/src/main/java/com/uphyca/robota/ui/BotActivity.java
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.uphyca.idobata.Idobata;
import com.uphyca.idobata.IdobataError;
import com.uphyca.idobata.model.Seed;
import com.uphyca.robota.InjectionUtils;
import com.uphyca.robota.R;
import com.uphyca.robota.data.api.ApiToken;
import com.uphyca.robota.data.api.Enabled;
import com.uphyca.robota.data.api.Main;
import com.uphyca.robota.data.api.Networking;
import com.uphyca.robota.data.prefs.BooleanPreference;
import com.uphyca.robota.data.prefs.StringPreference;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
/*
* Copyright (C) 2014 uPhyca Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.uphyca.robota.ui;
/**
* @author Sosuke Masui ([email protected])
*/
public class BotActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bot);
}
public static class BotFragment extends Fragment {
@Inject
Idobata mIdobata;
@Inject
@Networking
Executor mExecutor;
@Inject
@Main
Executor mDispatcher;
@Inject
@ApiToken
StringPreference mApiTokenPreference;
@Inject
@Enabled
BooleanPreference mEnabledPreference;
@InjectView(R.id.api_token)
EditText mApiToken;
@InjectView(R.id.update)
Button mUpdateButton;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); | InjectionUtils.getObjectGraph(getActivity()) |