33 lines
921 B
Java
33 lines
921 B
Java
package com.eactive.testmaster.api.condition;
|
|
|
|
import com.eactive.testmaster.api.dto.MockRequest;
|
|
import com.eactive.testmaster.api.entity.MockCondition;
|
|
import com.jayway.jsonpath.JsonPath;
|
|
import com.jayway.jsonpath.PathNotFoundException;
|
|
import java.util.Map;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@Component
|
|
public class JsonPathMatcher implements ConditionMatcher {
|
|
@Override
|
|
public boolean matches(MockCondition condition, MockRequest request, Map<String, String> pathVariables) {
|
|
try {
|
|
Object value = JsonPath.read(request.getBody(), condition.getKey());
|
|
return value.toString().equals(condition.getValue());
|
|
} catch (PathNotFoundException e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getType() {
|
|
return "jsonpath";
|
|
}
|
|
|
|
@Override
|
|
public String getDisplayName() {
|
|
return "JSON Path";
|
|
}
|
|
}
|