Browse Source

Added build info to web test client.

pull/57/head
Kalle Stenflo 10 years ago
parent
commit
29e3f1843c
  1. 1
      build.gradle
  2. 14
      json-path-web-test/build.gradle
  3. 32
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java
  4. 11
      json-path-web-test/src/main/resources/webapp/index.html

1
build.gradle

@ -24,6 +24,7 @@ ext {
allprojects {
ext.displayName = null
ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss')
group = 'com.jayway.jsonpath'
version = '1.1.1' + (snapshotVersion ? "-SNAPSHOT" : "")

14
json-path-web-test/build.gradle

@ -1,13 +1,22 @@
apply plugin: 'shadow'
apply plugin: 'application'
displayName = "JsonPath Tets Bench"
displayName = "JsonPath Test Bench"
description = "Web app that compares different JsonPath implementations."
mainClassName = 'com.jayway.jsonpath.web.boot.Main'
task createBuildInfoFile << {
def buildInfoFile = new File("$buildDir/classes/main/build-info.properties")
Properties props = new Properties()
props.setProperty('version', project.version.toString())
props.setProperty('timestamp', project.buildTimestamp)
props.store(buildInfoFile.newWriter(), null)
}
jar {
dependsOn createBuildInfoFile
baseName 'json-path-web-test'
manifest {
attributes 'Implementation-Title': 'json-path-web-test',
@ -16,6 +25,7 @@ jar {
}
}
dependencies {
compile project(':json-path')
compile 'commons-io:commons-io:2.4'
@ -30,4 +40,4 @@ dependencies {
exclude module: 'jackson-annotations:com.fasterxml.jackson.core'
exclude module: 'jackson-core:com.fasterxml.jackson.core'
}
}
}

32
json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java

@ -17,7 +17,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
@Path("/")
@Produces(MediaType.TEXT_HTML)
@ -25,16 +27,31 @@ public class ApiResource {
private static final Logger logger = LoggerFactory.getLogger(ApiResource.class);
@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public Response info() {
Map<String, String> result = new HashMap<String, String>();
try {
ResourceBundle resource = ResourceBundle.getBundle("build-info");
result.put("version", resource.getString("version"));
result.put("timestamp", resource.getString("timestamp"));
} catch (Exception e){
result.put("version", "LOCAL");
result.put("timestamp", "NOW");
}
return Response.ok(result).build();
}
@GET
@Path("/validate")
@Produces(MediaType.APPLICATION_JSON)
public Response validate(@QueryParam("path") String path){
public Response validate(@QueryParam("path") String path) {
int result = -1;
try {
JsonPath compiled = JsonPath.compile(path);
result = compiled.isDefinite()?0:1;
} catch (Exception e){
result = compiled.isDefinite() ? 0 : 1;
} catch (Exception e) {
}
return Response.ok(Collections.singletonMap("result", result)).build();
}
@ -47,10 +64,10 @@ public class ApiResource {
public Response getTemplate(@FormParam("json") String json,
@FormParam("path") String path,
@FormParam("type") String type,
@FormParam("flagWrap") boolean flagWrap,
@FormParam("flagNullLeaf") boolean flagNullLeaf,
@FormParam("flagSuppress") boolean flagSuppress,
@FormParam("flagRequireProps") boolean flagRequireProps){
@FormParam("flagWrap") boolean flagWrap,
@FormParam("flagNullLeaf") boolean flagNullLeaf,
@FormParam("flagSuppress") boolean flagSuppress,
@FormParam("flagRequireProps") boolean flagRequireProps) {
boolean value = "VALUE".equalsIgnoreCase(type);
@ -60,5 +77,4 @@ public class ApiResource {
}
}

11
json-path-web-test/src/main/resources/webapp/index.html

@ -16,7 +16,10 @@
</head>
<body role="document">
<div class="container">
<h3>Jayway JsonPath evaluator</h3>
<h3>Jayway JsonPath Evaluator</h3>
<div style="margin-top: -12px; margin-bottom: 10px;">
<span id="version" style="font-size: xx-small"></span>&nbsp;-&nbsp;<span id="timestamp" style="font-size: xx-small"></span>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
@ -211,6 +214,11 @@
}
$( document ).ready(function() {
$.get('/api/info', function(data) {
$("#version").text(data.version);
$("#timestamp").text(data.timestamp);
});
$('#path-status-tool').tooltip({
container: 'body',
delay: 0
@ -288,7 +296,6 @@
success: function(data) {
$('#jayway-time').text(data.jayway.time);
//$('#jayway-res').hide().text(data.jayway.result).fadeIn();
$('#jayway-res').hide().empty();
if(data.jayway.error){
$('#jayway-error').text(data.jayway.error).show();

Loading…
Cancel
Save