Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
selcuksozuer committed Oct 31, 2019
1 parent 9c31907 commit bce5f69
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>loadium</groupId>
<artifactId>postman2jmx</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>

<dependencies>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/loadium/postman2jmx/app/Postman2Jmx.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Postman2Jmx {


public static void main(String[] args) {

try {
if (args.length != 2) {
throw new InvalidArgumentsException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.loadium.postman2jmx.model.jmx.*;
import com.loadium.postman2jmx.model.postman.PostmanCollection;
import com.loadium.postman2jmx.model.postman.PostmanItem;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor;
import org.apache.jmeter.protocol.http.control.HeaderManager;
Expand All @@ -17,9 +19,13 @@

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class AbstractJmxFileBuilder implements IJmxFileBuilder {
public abstract class AbstractJmxFileBuilder implements IJmxFileBuilder {

protected JmxFile buildJmxFile(PostmanCollection postmanCollection, String jmxOutputFilePath) throws Exception {
if (postmanCollection == null) {
Expand All @@ -34,7 +40,7 @@ protected JmxFile buildJmxFile(PostmanCollection postmanCollection, String jmxOu
config.setJMeterHome();

// TestPlan
TestPlan testPlan = JmxTestPlan.newInstance(postmanCollection.getInfo().getName());
TestPlan testPlan = JmxTestPlan.newInstance(postmanCollection.getInfo() != null ? postmanCollection.getInfo().getName() : "");

// ThreadGroup controller
LoopController loopController = JmxLoopController.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
public class JmxBinaryBodyBuilder extends AbstractJmxBodyBuilder {

@Override
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) throws Exception {
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) {
HTTPSamplerProxy httpSamplerProxy = JmxHTTPSamplerProxy.newInstance(postmanItem);
PostmanFileBody fileBody = postmanItem.getRequest().getBody().getFile();

HTTPFileArg argument = new HTTPFileArg();
argument.setPath(fileBody.getSrc());
argument.setPath(fileBody.getSrc() == null ? "" : fileBody.getSrc());
argument.setParamName(" ");
argument.setMimeType(" ");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public class JmxBodyBuilderFactory {

public static IJmxBodyBuilder getJmxBodyBuilder(PostmanItem postmanItem) throws UnsupportedJmxFileBuilderException {
String responseBodyMode = null;
try{
if (postmanItem.getRequest().getBody() != null) {
responseBodyMode = postmanItem.getRequest().getBody().getMode();
}catch (NullPointerException e) {
throw e;
}

if (responseBodyMode == null || ResponseBodyMode.EMPTY.getMode().equals(responseBodyMode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class JmxFormDataBodyBuilder extends AbstractJmxBodyBuilder {

@Override
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) throws Exception {
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) {
HTTPSamplerProxy httpSamplerProxy = JmxHTTPSamplerProxy.newInstance(postmanItem);

Arguments arguments = new Arguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class JmxRawBodyBuilder extends AbstractJmxBodyBuilder {

@Override
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) throws Exception {
public HTTPSamplerProxy buildJmxBody(PostmanItem postmanItem) {

HTTPSamplerProxy httpSamplerProxy = JmxHTTPSamplerProxy.newInstance(postmanItem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class NoPostmanCollectionItemException extends Exception {
public NoPostmanCollectionItemException() {
super("There is no postman collection item!");
super("There is no postman collection item! Please ensure that your postman file has been exported as Collection v2 or v2.1");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class NullPostmanCollectionException extends Exception {
public NullPostmanCollectionException() {
super("Postman collection model can not be null!");
super("Postman collection model can not be null! Please ensure that your postman file has been exported as Collection v2 or v2.1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.loadium.postman2jmx.model.deserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ExecDeserializer extends JsonDeserializer<ExecDeserializer.ExecData> {

public ExecDeserializer() {}

@Override
public ExecDeserializer.ExecData deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
ExecDeserializer.ExecData execData = new ExecDeserializer.ExecData();
if (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING) {
execData.addValue(jsonParser.getValueAsString());
} else if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
ObjectMapper mapper = new ObjectMapper();
List<String> values = mapper.readValue(jsonParser, List.class);
execData.setValues(values);

}
return execData;
}

public class ExecData {
private List<String> values = new ArrayList<>();

public void addValue(String value) {
this.values.add(value);
}

public List<String> getValues() {
return this.values;
}

public void setValues(List<String> values) {
this.values.addAll(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PostmanEvent() {
public PostmanEvent(String listen, PostmanScript script) {
this.listen = listen;
this.script = script;
this.variables = ValueUtils.extractVariables(script.getExec());
this.variables = ValueUtils.extractVariables(script.getExecs());
}

public String getListen() {
Expand All @@ -43,7 +43,7 @@ public PostmanScript getScript() {

public void setScript(PostmanScript script) {
this.script = script;
this.variables = ValueUtils.extractVariables(script.getExec());
this.variables = ValueUtils.extractVariables(script.getExecs());

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.loadium.postman2jmx.model.postman;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class PostmanQuery {
private String key;
private String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.loadium.postman2jmx.model.deserializer.ExecDeserializer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -12,9 +21,10 @@ public class PostmanScript {
@JsonProperty("type")
private String type;

@JsonProperty("exec")
@JsonProperty(value = "exec")
private List<String> execs = new ArrayList<>();


public PostmanScript() {
}

Expand All @@ -31,11 +41,12 @@ public void setType(String type) {
this.type = type;
}

public List<String> getExec() {
public List<String> getExecs() {
return execs;
}

public void setExec(List<String> execs) {
this.execs = execs;
@JsonDeserialize(using = ExecDeserializer.class)
public void setExecs(ExecDeserializer.ExecData execData) {
this.execs.addAll(execData.getValues());
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/loadium/postman2jmx/utils/ValueUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class ValueUtils {
private static final String[] patterns = {".environment.set", ".setGlobalVariable", ".setEnvironmentVariable", ".globals.set"};

public static String value(String value) {
if (value == null) {
return "";
}

if (value.contains("{{") && value.contains("}}")) {
value = value.replace("{{", "${");
value = value.replace("}}", "}");
Expand Down

0 comments on commit bce5f69

Please sign in to comment.