Browse Source

Logging improvements.

pull/57/head
Kalle Stenflo 10 years ago
parent
commit
69e223e4fe
  1. 32
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java
  2. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  3. 2
      json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java
  4. 2
      json-path/src/test/java/com/jayway/jsonpath/old/HttpProviderTest.java
  5. 3
      json-path/src/test/java/com/jayway/jsonpath/old/NullHandlingTest.java
  6. 3
      json-path/src/test/resources/simplelogger.properties

32
json-path/src/main/java/com/jayway/jsonpath/Criteria.java

@ -50,7 +50,7 @@ public class Criteria implements Predicate {
@Override
boolean eval(Object expected, Object actual, PredicateContext ctx) {
boolean res = (0 == safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -58,7 +58,7 @@ public class Criteria implements Predicate {
@Override
boolean eval(Object expected, Object actual, PredicateContext ctx) {
boolean res = (0 != safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -69,7 +69,7 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 > safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -80,7 +80,7 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 >= safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -91,7 +91,7 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 < safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -102,7 +102,7 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 <= safeCompare(expected, actual));
logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected, res);
return res;
}
},
@ -117,7 +117,7 @@ public class Criteria implements Predicate {
break;
}
}
logger.debug("[{}] {} [{}] => {}", actual, name(), join(", ", exps), res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), join(", ", exps), res);
return res;
}
},
@ -126,7 +126,7 @@ public class Criteria implements Predicate {
boolean eval(Object expected, Object actual, PredicateContext ctx) {
Collection nexps = (Collection) expected;
boolean res = !nexps.contains(actual);
logger.debug("[{}] {} [{}] => {}", actual, name(), join(", ", nexps), res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), join(", ", nexps), res);
return res;
}
},
@ -149,10 +149,10 @@ public class Criteria implements Predicate {
break;
}
}
logger.debug("[{}] {} [{}] => {}", join(", ", ctx.configuration().jsonProvider().toIterable(actual)), name(), join(", ", exps), res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", join(", ", ctx.configuration().jsonProvider().toIterable(actual)), name(), join(", ", exps), res);
} else {
res = false;
logger.debug("[{}] {} [{}] => {}", "<NOT AN ARRAY>", name(), join(", ", exps), res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", "<NOT AN ARRAY>", name(), join(", ", exps), res);
}
return res;
}
@ -165,14 +165,14 @@ public class Criteria implements Predicate {
if (ctx.configuration().jsonProvider().isArray(actual)) {
int length = ctx.configuration().jsonProvider().length(actual);
res = (length == size);
logger.debug("Array with size {} {} {} => {}", length, name(), size, res);
if(logger.isDebugEnabled()) logger.debug("Array with size {} {} {} => {}", length, name(), size, res);
} else if (actual instanceof String) {
int length = ((String) actual).length();
res = length == size;
logger.debug("String with length {} {} {} => {}", length, name(), size, res);
if(logger.isDebugEnabled()) logger.debug("String with length {} {} {} => {}", length, name(), size, res);
} else {
res = false;
logger.debug("{} {} {} => {}", actual == null ? "null" : actual.getClass().getName(), name(), size, res);
if(logger.isDebugEnabled()) logger.debug("{} {} {} => {}", actual == null ? "null" : actual.getClass().getName(), name(), size, res);
}
return res;
}
@ -201,7 +201,7 @@ public class Criteria implements Predicate {
if (actual != null && actual instanceof String) {
res = pattern.matcher(actual.toString()).matches();
}
logger.debug("[{}] {} [{}] => {}", actual, name(), expected.toString(), res);
if(logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", actual, name(), expected.toString(), res);
return res;
}
},
@ -221,11 +221,11 @@ public class Criteria implements Predicate {
if (ctx.configuration().jsonProvider().isArray(actual)) {
int len = ctx.configuration().jsonProvider().length(actual);
res = (0 != len);
logger.debug("array length = {} {} => {}", len, name(), res);
if(logger.isDebugEnabled()) logger.debug("array length = {} {} => {}", len, name(), res);
} else if (actual instanceof String) {
int len = ((String) actual).length();
res = (0 != len);
logger.debug("string length = {} {} => {}", len, name(), res);
if(logger.isDebugEnabled()) logger.debug("string length = {} {} => {}", len, name(), res);
}
}
return res;

2
json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

@ -74,7 +74,7 @@ public class PathCompiler {
String cacheKey = path + isRootPath + filterList.toString();
Path p = cache.get(cacheKey);
if (p != null) {
logger.debug("Using cached path");
if(logger.isDebugEnabled()) logger.debug("Using cached path");
return p;
}

2
json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

@ -43,7 +43,7 @@ public class InlineFilterTest extends BaseTest {
Object read = reader.read("$.store.book[?(@.display-price <= $.max-price)]");
System.out.println(read);
//System.out.println(read);
}
}

2
json-path/src/test/java/com/jayway/jsonpath/old/HttpProviderTest.java

@ -11,7 +11,6 @@ import java.net.URL;
import static junit.framework.Assert.assertEquals;
@Ignore
public class HttpProviderTest {
@ -21,6 +20,7 @@ public class HttpProviderTest {
"}";
@Test
@Ignore
public void http_get() throws Exception {
URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?sensor=false");

3
json-path/src/test/java/com/jayway/jsonpath/old/NullHandlingTest.java

@ -77,8 +77,9 @@ public class NullHandlingTest {
List<Object> result = JsonPath.using(Configuration.defaultConfiguration().setOptions(Option.DEFAULT_PATH_LEAF_TO_NULL)).parse(json).read("a[?(@.b==5)].d");
Assertions.assertThat(result).hasSize(1);
Assertions.assertThat(result.get(0)).isNull();
System.out.println(result);
}

3
json-path/src/test/resources/simplelogger.properties

@ -1 +1,2 @@
#org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.log.com.jayway=debug

Loading…
Cancel
Save