-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add page item in as code v3 #29
base: v3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.neotys.neoload.model.v3.project.userpath; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.neotys.neoload.model.v3.project.SlaElement; | ||
import com.neotys.neoload.model.v3.validation.constraints.RequiredCheck; | ||
import com.neotys.neoload.model.v3.validation.groups.NeoLoad; | ||
import org.immutables.value.Value; | ||
|
||
import javax.validation.constraints.Pattern; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutablePage.class) | ||
@JsonDeserialize(as = ImmutablePage.class) | ||
public interface Page extends Step, SlaElement { | ||
List<Request> getChildren(); | ||
|
||
@Value.Default | ||
@RequiredCheck(groups = {NeoLoad.class}) | ||
default boolean isDynamic(){ | ||
return false; | ||
} | ||
|
||
@Value.Default | ||
@RequiredCheck(groups = {NeoLoad.class}) | ||
default String getName() { | ||
return "#page#"; | ||
} | ||
|
||
@Value.Default | ||
@RequiredCheck(groups = {NeoLoad.class}) | ||
default boolean isSequential(){ | ||
return false; | ||
} | ||
|
||
@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})(-(\\d+|\\$\\{\\w+\\}))?", groups = {NeoLoad.class}) | ||
Optional<String> getThinkTime(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,14 @@ | |
import com.neotys.neoload.model.v3.validation.groups.NeoLoad; | ||
|
||
@JsonInclude(value=Include.NON_DEFAULT) | ||
@JsonPropertyOrder({Request.NAME, Request.URL, Request.SERVER, Request.METHOD, Request.HEADERS, Request.BODY, Request.EXTRACTORS, AssertionsElement.ASSERTIONS, Request.FOLLOW_REDIRECTS, SlaElement.SLA_PROFILE}) | ||
@JsonPropertyOrder({Request.NAME, Request.URL, Request.SERVER, Request.METHOD, Request.HEADERS, Request.BODY, Request.EXTRACTORS, AssertionsElement.ASSERTIONS, Request.FOLLOW_REDIRECTS, SlaElement.SLA_PROFILE, Request.DYNAMIC_RESOURCES}) | ||
@JsonSerialize(as = ImmutableRequest.class) | ||
@JsonDeserialize(as = ImmutableRequest.class) | ||
@Value.Immutable | ||
@Value.Style(validationMethod = ValidationMethod.NONE) | ||
public interface Request extends Step, SlaElement, AssertionsElement { | ||
String NAME = "name"; | ||
String DYNAMIC_RESOURCES = "dynamicResources"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some tests are missing for this parameter and his getter, you can refer to the tests already existing for others parameters and getter of this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to update the doc with this new parameter |
||
String URL = "url"; | ||
String SERVER = "server"; | ||
String METHOD = "method"; | ||
|
@@ -65,6 +66,12 @@ public static Method of(final String name) { | |
} | ||
} | ||
|
||
@JsonProperty(DYNAMIC_RESOURCES) | ||
@Value.Default | ||
default boolean isDynamic(){ | ||
return false; | ||
} | ||
|
||
@JsonProperty(NAME) | ||
@RequiredCheck(groups={NeoLoad.class}) | ||
@Value.Default | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.neotys.neoload.model.v3.writers.neoload.userpath; | ||
|
||
import com.neotys.neoload.model.v3.project.userpath.Page; | ||
import com.neotys.neoload.model.v3.writers.neoload.ElementWriter; | ||
import com.neotys.neoload.model.v3.writers.neoload.SlaElementWriter; | ||
import com.neotys.neoload.model.v3.writers.neoload.WriterUtils; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class PageWriter extends ElementWriter { | ||
|
||
public static final String XML_TAG_NAME = "http-page"; | ||
public static final String XML_ATTRIBUTE_THINK_TIME = "thinkTime"; | ||
public static final String XML_ATTRIBUTE_THINK_TIME_START = "thinkTimeRangeStart"; | ||
public static final String XML_ATTRIBUTE_THINK_TIME_STOP = "thinkTimeRangeEnd"; | ||
public static final String XML_ATTRIBUTE_THINK_TIME_MODE = "thinkTimeMode"; | ||
|
||
public static final String MODE_RANGE_THINK_TIME = "MODE_RANGE_THINK_TIME"; | ||
|
||
public static final String XML_ATTRIBUTE_EXECUTE_RESOURCES_DYNAMICALLY = "executeResourcesDynamically"; | ||
|
||
private static Pattern patternThinkTime = Pattern.compile("(\\d+|\\$\\{\\w+\\})-(\\d+|\\$\\{\\w+\\})"); | ||
|
||
public PageWriter(final Page page) { | ||
super(page); | ||
} | ||
|
||
public static PageWriter of(final Page page){ | ||
return new PageWriter(page); | ||
} | ||
|
||
@Override | ||
public void writeXML(final Document document, final Element currentElement, final String outputFolder) { | ||
final Element xmlPage = document.createElement(XML_TAG_NAME); | ||
super.writeXML(document, xmlPage, outputFolder); | ||
final Page thePage = (Page) this.element; | ||
thePage.getThinkTime().ifPresent(thinkTime -> writeDelay(xmlPage, thinkTime)); | ||
xmlPage.setAttribute(XML_ATTRIBUTE_EXECUTE_RESOURCES_DYNAMICALLY, Boolean.toString(thePage.isDynamic())); | ||
currentElement.appendChild(xmlPage); | ||
SlaElementWriter.of(thePage).writeXML(xmlPage); | ||
thePage.getChildren().forEach(pageElem -> { | ||
WriterUtils.generateEmbeddedAction(document, xmlPage, pageElem); | ||
WriterUtils.<ElementWriter>getWriterFor(pageElem).writeXML(document, currentElement, outputFolder); | ||
}); | ||
} | ||
|
||
private void writeDelay(final Element xmlPage, final String thinkTime) { | ||
final Matcher matcher = patternThinkTime.matcher(thinkTime); | ||
if(matcher.matches()){ | ||
xmlPage.setAttribute(XML_ATTRIBUTE_THINK_TIME_MODE,MODE_RANGE_THINK_TIME); | ||
xmlPage.setAttribute(XML_ATTRIBUTE_THINK_TIME_START, matcher.group(1)); | ||
xmlPage.setAttribute(XML_ATTRIBUTE_THINK_TIME_STOP, matcher.group(2)); | ||
}else{ | ||
xmlPage.setAttribute(XML_ATTRIBUTE_THINK_TIME,thinkTime); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,15 @@ | ||
package com.neotys.neoload.model.v3.writers.neoload.userpath; | ||
|
||
import com.neotys.neoload.model.v3.project.userpath.ThinkTime; | ||
import com.neotys.neoload.model.v3.writers.neoload.ElementWriter; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
public class ThinkTimeWriter extends ElementWriter { | ||
|
||
public static final String XML_TAG_NAME = "delay-action"; | ||
public static final String XML_DURATION_ATT = "duration"; | ||
public static final String XML_ISTHINKTIME_ATT = "isThinkTime"; | ||
public class ThinkTimeWriter extends AbstractDelayActionWriter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is not part of the commit and is missing... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah bad cut it is on other pr. So I will merge. |
||
|
||
public ThinkTimeWriter(ThinkTime thinktime) { | ||
super(thinktime); | ||
super(thinktime,thinktime.getValue(),true); | ||
} | ||
|
||
public static ThinkTimeWriter of(final ThinkTime thinktime) { | ||
return new ThinkTimeWriter(thinktime); | ||
} | ||
|
||
@Override | ||
public void writeXML(final Document document, final Element currentElement, final String outputFolder) { | ||
Element xmlDelay = document.createElement(XML_TAG_NAME); | ||
super.writeXML(document, xmlDelay, outputFolder); | ||
xmlDelay.setAttribute(XML_DURATION_ATT, ((ThinkTime)element).getValue()); | ||
xmlDelay.setAttribute(XML_ISTHINKTIME_ATT, "true"); | ||
currentElement.appendChild(xmlDelay); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.neotys.neoload.model.v3.writers.neoload.userpath; | ||
|
||
import com.google.common.io.Files; | ||
import com.neotys.neoload.model.v3.project.userpath.ImmutablePage; | ||
import com.neotys.neoload.model.v3.project.userpath.ImmutableRequest; | ||
import com.neotys.neoload.model.v3.project.userpath.Page; | ||
import com.neotys.neoload.model.v3.project.userpath.Request; | ||
import com.neotys.neoload.model.v3.writers.neoload.WriterUtils; | ||
import com.neotys.neoload.model.v3.writers.neoload.WrittingTestUtils; | ||
import org.junit.Test; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.xmlunit.assertj.XmlAssert; | ||
import org.xmlunit.builder.Input; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
public class PageWriterTest { | ||
|
||
@Test | ||
public void writePageTestClassic() throws ParserConfigurationException { | ||
final Document doc = WrittingTestUtils.generateEmptyDocument(); | ||
final Element root = WrittingTestUtils.generateTestRootElement(doc); | ||
final ImmutableRequest request = Request.builder().url("http://1.com").build(); | ||
final Page page = ImmutablePage.builder() | ||
.name("myPage") | ||
.description("myDescription") | ||
.isDynamic(true) | ||
.addChildren(request) | ||
.build(); | ||
final String requestUid = WriterUtils.getElementUid(request); | ||
final String expectedResult = | ||
"<test-root>" + | ||
"<http-page executeResourcesDynamically=\"true\" name=\"myPage\" uid=\""+ WriterUtils.getElementUid(page)+"\">" + | ||
"<description>myDescription</description>" + | ||
"<embedded-action>"+ requestUid +"</embedded-action>" + | ||
"</http-page>" + | ||
"<http-action actionType=\"1\" followRedirects=\"false\" method=\"GET\" name=\"#request#\" path=\"\" slaProfileEnabled=\"false\" uid=\""+requestUid+"\"/>" + | ||
"</test-root>"; | ||
PageWriter.of(page).writeXML(doc, root, Files.createTempDir().getAbsolutePath()); | ||
|
||
XmlAssert.assertThat(Input.fromDocument(doc)).and(Input.fromString(expectedResult)).areSimilar(); | ||
} | ||
|
||
@Test | ||
public void writePageTest() throws ParserConfigurationException { | ||
final Document doc = WrittingTestUtils.generateEmptyDocument(); | ||
final Element root = WrittingTestUtils.generateTestRootElement(doc); | ||
final Request request1 = Request.builder().url("http://2.com").build(); | ||
final Request request2 = Request.builder().url("http://3.com").build(); | ||
final Page page = ImmutablePage.builder() | ||
.name("myPage") | ||
.description("myDescription") | ||
.thinkTime("10-20") | ||
.addChildren(request1) | ||
.addChildren(request2) | ||
.build(); | ||
final String request1Uid = WriterUtils.getElementUid(request1); | ||
final String request2Uid = WriterUtils.getElementUid(request2); | ||
final String expectedResult = | ||
"<test-root>" + | ||
"<http-page executeResourcesDynamically=\"false\" name=\"myPage\" thinkTimeMode=\"MODE_RANGE_THINK_TIME\" thinkTimeRangeEnd=\"20\" thinkTimeRangeStart=\"10\" uid=\""+ WriterUtils.getElementUid(page)+"\">" + | ||
"<description>myDescription</description>" + | ||
"<embedded-action>"+ request1Uid +"</embedded-action>" + | ||
"<embedded-action>"+ request2Uid +"</embedded-action>" + | ||
"</http-page>" + | ||
"<http-action actionType=\"1\" followRedirects=\"false\" method=\"GET\" name=\"#request#\" path=\"\" slaProfileEnabled=\"false\" uid=\""+ request1Uid +"\"/>" + | ||
"<http-action actionType=\"1\" followRedirects=\"false\" method=\"GET\" name=\"#request#\" path=\"\" slaProfileEnabled=\"false\" uid=\""+ request2Uid +"\"/>" + | ||
"</test-root>"; | ||
PageWriter.of(page).writeXML(doc, root, Files.createTempDir().getAbsolutePath()); | ||
|
||
XmlAssert.assertThat(Input.fromDocument(doc)).and(Input.fromString(expectedResult)).areSimilar(); | ||
} | ||
|
||
@Test | ||
public void writePageSLATest() throws ParserConfigurationException { | ||
final Document doc = WrittingTestUtils.generateEmptyDocument(); | ||
final Element root = WrittingTestUtils.generateTestRootElement(doc); | ||
final Request request1 = Request.builder().url("http://2.com").build(); | ||
final Request request2 = Request.builder().url("http://3.com").build(); | ||
final Page page = ImmutablePage.builder() | ||
.name("myPage") | ||
.description("myDescription") | ||
.thinkTime("10-20") | ||
.addChildren(request1) | ||
.addChildren(request2) | ||
.slaProfile("toto") | ||
.build(); | ||
final String request1Uid = WriterUtils.getElementUid(request1); | ||
final String request2Uid = WriterUtils.getElementUid(request2); | ||
final String expectedResult = | ||
"<test-root>" + | ||
"<http-page executeResourcesDynamically=\"false\" name=\"myPage\" slaProfileEnabled=\"true\" slaProfileName=\"toto\" thinkTimeMode=\"MODE_RANGE_THINK_TIME\" thinkTimeRangeEnd=\"20\" thinkTimeRangeStart=\"10\" uid=\""+ WriterUtils.getElementUid(page)+"\">" + | ||
"<description>myDescription</description>" + | ||
"<embedded-action>"+ request1Uid +"</embedded-action>" + | ||
"<embedded-action>"+ request2Uid +"</embedded-action>" + | ||
"</http-page>" + | ||
"<http-action actionType=\"1\" followRedirects=\"false\" method=\"GET\" name=\"#request#\" path=\"\" slaProfileEnabled=\"false\" uid=\""+ request1Uid +"\"/>" + | ||
"<http-action actionType=\"1\" followRedirects=\"false\" method=\"GET\" name=\"#request#\" path=\"\" slaProfileEnabled=\"false\" uid=\""+ request2Uid +"\"/>" + | ||
"</test-root>"; | ||
PageWriter.of(page).writeXML(doc, root, Files.createTempDir().getAbsolutePath()); | ||
|
||
XmlAssert.assertThat(Input.fromDocument(doc)).and(Input.fromString(expectedResult)).areSimilar(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tests specific for this class are missing.
You can refer to what we did previously for testing a new as-code element.
For this class: com.neotys.neoload.model.v3.project.scenario.CustomPolicyStep
We made/updated these classes: