diff --git a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/RequestConditionBuilder.java b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/RequestConditionBuilder.java index d16d7430..8e22e306 100644 --- a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/RequestConditionBuilder.java +++ b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/RequestConditionBuilder.java @@ -136,7 +136,19 @@ public RequestCondition build() { return new RequestCondition(configurationString); } - public RequestConditionBuilder withHeader(String blah) { + public RequestConditionBuilder withHeader(String name, String value) { + String conditionString = "\n" + + " \n" + + "\n"; + configurationString += conditionString; + return this; + } + + public RequestConditionBuilder withHeader(String pattern) { + String conditionString = "\n" + + " \n" + + "\n"; + configurationString += conditionString; return this; } diff --git a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/ResponseDescriptorBuilder.java b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/ResponseDescriptorBuilder.java index 39c8a37c..a75dffe6 100644 --- a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/ResponseDescriptorBuilder.java +++ b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/ResponseDescriptorBuilder.java @@ -20,6 +20,7 @@ import com.epam.wilma.service.unit.helper.ConfigurationParameter; import com.epam.wilma.service.unit.helper.StubConfigurationException; +import com.epam.wilma.service.unit.helper.Template; import com.epam.wilma.service.unit.helper.TemplateFormatter; import com.epam.wilma.service.unit.request.RequestCondition; import com.epam.wilma.service.unit.response.ResponseDescriptor; @@ -40,8 +41,7 @@ public class ResponseDescriptorBuilder { private String code = "200"; private String delay = "0"; private String mimeType = "text/plain"; - private String templateType = "text"; - private String templateResource = "Wilma response"; + private Template template = new Template("text", "Wilma default response"); private LinkedList templateFormatters = new LinkedList<>(); public ResponseDescriptorBuilder(RequestCondition requestCondition) { @@ -49,11 +49,13 @@ public ResponseDescriptorBuilder(RequestCondition requestCondition) { } public ResponseDescriptorBuilder plainTextResponse(String plainTextResponse) { + mimeType = "text/plain"; + template = new Template("text", plainTextResponse); return this; } public ResponseDescriptor buildResponseDescriptor() { - return new ResponseDescriptor(); + return new ResponseDescriptor(delay, code, mimeType, template, templateFormatters); } public Stub build() { @@ -84,4 +86,12 @@ public ResponseDescriptorBuilder applyFormatter(String formatterClass, Configura public ResponseDescriptorBuilder generatedResponse() { return this; } + + public ResponseDescriptorBuilder withDelay(int i) { + if (i < 0) { + throw new StubConfigurationException("Given Response Delay (" + i + ") is invalid."); + } + delay = String.valueOf(i); + return this; + } } diff --git a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/Stub.java b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/Stub.java index fca1833b..2b98eeee 100644 --- a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/Stub.java +++ b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/Stub.java @@ -74,8 +74,8 @@ public Stub(RequestCondition requestCondition, ResponseDescriptor responseDescri public String toString() { String generatedName = "generated name"; String conditionContent = requestCondition.toString(); - String responseContent = responseDescriptor.toString(); - String usedTemplateAndFormatter = responseDescriptor.toString(); + String responseContent = responseDescriptor.responseDescriptorToString(); + String usedTemplateAndFormatter = responseDescriptor.templateToString(); StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); formatter.format(STUB_CONFIGURATION_FORMATTER, generatedName, conditionContent, responseContent, usedTemplateAndFormatter); diff --git a/wilma-service-api/src/main/java/com/epam/wilma/service/unit/helper/Template.java b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/helper/Template.java new file mode 100644 index 00000000..a2d56109 --- /dev/null +++ b/wilma-service-api/src/main/java/com/epam/wilma/service/unit/helper/Template.java @@ -0,0 +1,56 @@ +package com.epam.wilma.service.unit.helper; +/*========================================================================== + Copyright 2013-2016 EPAM Systems + + This file is part of Wilma. + + Wilma 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. + + Wilma 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 Wilma. If not, see . + ===========================================================================*/ + +/** + * Class that holds a single response template information. + * + * @author Tamas_Kohegyi + * + */ +public class Template { + private String name; + private String type; + private String resource; + + /** + * General constructor of a Template class. + * + * @param type can be text|xmlfile|htmlfile|textfile|external + * @param resource is the template itself, or filename to the template or a classname that generates the template + */ + public Template(String type, String resource) { + this.name = "template-" + IdGenerator.getNextGeneratedId(); + this.type = type; + this.resource = resource; + } + /** + * Generates String value for the template. + * @return with the config string + */ + public String toString() { + + String templateString = "