From ba850e5101c8f601a60e8e7df64b414bf44be51b Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Fri, 22 May 2015 13:22:45 -0700 Subject: [PATCH 01/17] Adding streaming functionality --- .../java/com/jayway/jsonpath/Criteria.java | 150 +++++++++++- .../jayway/jsonpath/EvaluationCallback.java | 37 +++ .../main/java/com/jayway/jsonpath/Filter.java | 26 ++- .../java/com/jayway/jsonpath/Predicate.java | 3 + .../internal/token/ArrayPathToken.java | 79 +++++++ .../jsonpath/internal/token/ArrayToken.java | 48 ++++ .../jsonpath/internal/token/FloatToken.java | 33 +++ .../jsonpath/internal/token/IntToken.java | 33 +++ .../jsonpath/internal/token/ObjectToken.java | 45 ++++ .../jsonpath/internal/token/PathToken.java | 3 + .../internal/token/PredicateContextImpl.java | 2 +- .../internal/token/PredicatePathToken.java | 31 ++- .../internal/token/PropertyPathToken.java | 31 ++- .../internal/token/RootPathToken.java | 10 + .../internal/token/ScanPathToken.java | 22 ++ .../internal/token/StackElementWrapper.java | 148 ++++++++++++ .../jsonpath/internal/token/StringToken.java | 33 +++ .../jsonpath/internal/token/TokenStack.java | 217 ++++++++++++++++++ .../internal/token/TokenStackElement.java | 17 ++ .../jsonpath/internal/token/TokenType.java | 17 ++ .../internal/token/WildcardPathToken.java | 8 + 21 files changed, 986 insertions(+), 7 deletions(-) create mode 100644 json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/StackElementWrapper.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java create mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenType.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java index 67a95f164..c8a1a4ef6 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java @@ -16,7 +16,7 @@ import com.jayway.jsonpath.internal.Path; import com.jayway.jsonpath.internal.PathCompiler; -import com.jayway.jsonpath.internal.token.PredicateContextImpl; +import com.jayway.jsonpath.internal.token.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,6 +64,37 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + if (left.getType() == right.getType()) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + ArrayToken rightT = (ArrayToken)right; + break; + } + case OBJECT_TOKEN: + { + break; + } + case STRING_TOKEN: + { + break; + } + case FLOAT_TOKEN: + { + break; + } + case INTEGER_TOKEN: + { + break; + } + } + } + return false; + } + @Override public String toString() { return "=="; @@ -77,6 +108,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return "!="; @@ -93,6 +129,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return ">"; @@ -109,6 +150,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return ">="; @@ -125,6 +171,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return "<"; @@ -141,6 +192,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return "<="; @@ -160,6 +216,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", exps), res); return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, NIN { @Override @@ -169,6 +230,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", nexps), res); return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, CONTAINS { @Override @@ -191,6 +257,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res); return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, ALL { @Override @@ -219,6 +290,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, SIZE { @Override @@ -240,6 +316,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, EXISTS { @Override @@ -247,6 +328,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { //This must be handled outside throw new UnsupportedOperationException(); } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, TYPE { @Override @@ -256,6 +342,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return actType != null && expType.isAssignableFrom(actType); } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, REGEX { @Override @@ -280,6 +371,11 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { return res; } + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } + @Override public String toString() { return "=~"; @@ -292,6 +388,11 @@ boolean eval(Object expected, final Object model, final PredicateContext ctx) { Predicate exp = (Predicate) expected; return exp.apply(new PredicateContextImpl(model, ctx.root(), ctx.configuration(), pci.documentPathCache())); } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }, NOT_EMPTY { @Override @@ -310,9 +411,17 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } return res; } + + @Override + public boolean check(TokenStackElement left, TokenStackElement right) { + return false; + } }; - abstract boolean eval(Object expected, Object model, PredicateContext ctx); + abstract boolean eval(Object expected, Object model, + PredicateContext ctx); + + abstract boolean check(TokenStackElement left, TokenStackElement right); public static CriteriaType parse(String str) { if ("==".equals(str)) { @@ -414,6 +523,43 @@ private boolean eval(PredicateContext ctx) { } } + @Override + public boolean check(TokenStack stack, int idx) { + for (Criteria criteria : criteriaChain) { + if (!criteria.check2(stack, idx)) { + return false; + } + } + return true; + } + + private boolean check2(TokenStack stack, int idx) { + if (CriteriaType.EXISTS == criteriaType) { + boolean exists = ((Boolean) right); + try { + //Configuration c = Configuration.builder().jsonProvider(ctx.configuration().jsonProvider()).options(Option.REQUIRE_PROPERTIES).build(); + //Object value = ((Path) left).evaluate(ctx.item(), ctx.root(), c).getValue(); + Object value = null; + + if (exists) { + return (value != null); + } else { + return (value == null); + } + } catch (PathNotFoundException e) { + return !exists; + } + } + try { + //Object leftVal = evaluateIfPath(left, ctx); + //Object rightVal = evaluateIfPath(right, ctx); + + //return criteriaType.check(rightVal, leftVal); + } catch (ValueCompareException e) { + } catch (PathNotFoundException e) { + } + return false; + } /** * Static factory method to create a Criteria using the provided key diff --git a/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java new file mode 100644 index 000000000..5b41947fb --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 the original author or authors. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jayway.jsonpath; + +import com.jayway.jsonpath.internal.Path; + +/** + * A listener that can be registered on a {@link com.jayway.jsonpath.internal.token.TokenStack} that is notified when a + * result is found for a specific registered path + */ +public interface EvaluationCallback { + + /** + * Callback invoked when result is found + * @param path -- the specific path that was triggered + */ + void resultFound(Path path); + + /** + * Callback invoked when the parser leaves the region in which the match + * was found + * @param path -- the specific path that was untriggered + */ + void resultFoundExit(Path path); +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/Filter.java b/json-path/src/main/java/com/jayway/jsonpath/Filter.java index 26c7ed1e9..94a33aaa6 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Filter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Filter.java @@ -15,6 +15,7 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.Utils; +import com.jayway.jsonpath.internal.token.TokenStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,6 +57,8 @@ public static Filter filter(Collection predicates) { @Override public abstract boolean apply(PredicateContext ctx); + @Override + public abstract boolean check(TokenStack stack, int idx); public Filter or(final Predicate other){ return new OrFilter(this, other); @@ -80,6 +83,11 @@ public boolean apply(PredicateContext ctx) { return predicate.apply(ctx); } + @Override + public boolean check(TokenStack stack, int idx) { + return predicate.check(stack, idx); + } + @Override public String toString() { return predicate.toString(); @@ -114,6 +122,16 @@ public boolean apply(PredicateContext ctx) { return true; } + @Override + public boolean check(TokenStack stack, int idx) { + for (Predicate predicate : predicates) { + if(!predicate.check(stack, idx)){ + return false; + } + } + return true; + } + @Override public String toString() { return "(" + Utils.join(" && ", predicates) + ")"; @@ -124,7 +142,7 @@ private static final class OrFilter extends Filter { private final Predicate left; private final Predicate right; - + private OrFilter(Predicate left, Predicate right) { this.left = left; this.right = right; @@ -140,6 +158,12 @@ public boolean apply(PredicateContext ctx) { return a || right.apply(ctx); } + @Override + public boolean check(TokenStack stack, int idx) { + boolean a = left.check(stack, idx); + return a || right.check(stack, idx); + } + @Override public String toString() { return "(" + left.toString() + " || " + right.toString() + ")"; diff --git a/json-path/src/main/java/com/jayway/jsonpath/Predicate.java b/json-path/src/main/java/com/jayway/jsonpath/Predicate.java index 1d19991ea..a7e5525f3 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Predicate.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Predicate.java @@ -14,6 +14,7 @@ */ package com.jayway.jsonpath; +import com.jayway.jsonpath.internal.token.TokenStack; import com.jayway.jsonpath.spi.mapper.MappingException; /** @@ -23,6 +24,8 @@ public interface Predicate { boolean apply(PredicateContext ctx); + boolean check(TokenStack stack, int idx); + public interface PredicateContext { /** diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java index 1928d91d3..ca3bbeea2 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java @@ -178,6 +178,85 @@ public String getPathFragment() { return sb.toString(); } + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + assert(stack.getStack().size() > idx); + TokenStackElement curr = stack.getStack().get(idx); + + if (curr.getType() == TokenType.ARRAY_TOKEN) { + ArrayToken token = (ArrayToken)curr; + int tokenIdx = token.getIndex(); + switch (operation) { + case CONTEXT_SIZE: + { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + case SLICE_TO: + { + int to = criteria.get(0).intValue(); + if (tokenIdx < to) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + break; + } + case SLICE_FROM: + { + int from = criteria.get(0).intValue(); + if (from <= tokenIdx) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + break; + } + case SLICE_BETWEEN: + { + int from = criteria.get(0).intValue(); + int to = criteria.get(1).intValue(); + if (from <= tokenIdx && tokenIdx < to) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + break; + } + case INDEX_SEQUENCE: + { + for (Integer i : criteria) { + if (i.intValue() == tokenIdx) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + } + break; + } + case SINGLE_INDEX: + { + if (criteria.get(0).intValue() == tokenIdx) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + break; + } + } + } + + return false; + } + @Override boolean isTokenDefinite() { return isDefinite; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java new file mode 100644 index 000000000..3981147ae --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java @@ -0,0 +1,48 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public class ArrayToken implements TokenStackElement +{ + int currentIndex; + TokenStackElement value; // can be an object, array, or property + + public ArrayToken() + { + currentIndex = 0; + value = null; + } + + public TokenType getType() + { + return TokenType.ARRAY_TOKEN; + } + + public int getIndex() + { + return currentIndex; + } + + public TokenStackElement getValue() + { + return value; + } + + public void setValue(TokenStackElement elem) + { + if (value != null) { + ++currentIndex; + } + value = elem; + } + + public String toString() + { + return "Array[idx=" + currentIndex + "]"; + } +} + +// End ArrayToken.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java new file mode 100644 index 000000000..561eb6137 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java @@ -0,0 +1,33 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public class FloatToken implements TokenStackElement +{ + public float value; + + public FloatToken(float f) + { + value = f; + } + + public TokenType getType() + { + return TokenType.FLOAT_TOKEN; + } + + public TokenStackElement getValue() + { + return null; + } + + public void setValue(TokenStackElement elem) + { + throw new RuntimeException(); + } +} + +// End FloatToken.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java new file mode 100644 index 000000000..df3dc314a --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java @@ -0,0 +1,33 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public class IntToken implements TokenStackElement +{ + public int value; + + public IntToken(int f) + { + value = f; + } + + public TokenType getType() + { + return TokenType.INTEGER_TOKEN; + } + + public TokenStackElement getValue() + { + return null; + } + + public void setValue(TokenStackElement elem) + { + throw new RuntimeException(); + } +} + +// End IntToken.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java new file mode 100644 index 000000000..408580fdf --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java @@ -0,0 +1,45 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public class ObjectToken implements TokenStackElement +{ + String key; + TokenStackElement value; // can be an array, object, or property + + public ObjectToken() + { + key = null; + value = null; + } + + public TokenType getType() + { + return TokenType.OBJECT_TOKEN; + } + + public String getKey() + { + return key; + } + + public TokenStackElement getValue() + { + return value; + } + + public void setValue(TokenStackElement elem) + { + value = elem; + } + + public String toString() + { + return "Object[key=" + key + "]"; + } +} + +// End ObjectToken.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java index 3d1897bcf..b94a6f8a0 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java @@ -204,6 +204,9 @@ public boolean equals(Object obj) { public abstract void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx); + /** streaming API */ + public abstract boolean checkForMatch(TokenStack stack, int idx); + abstract boolean isTokenDefinite(); abstract String getPathFragment(); diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java index 3abc68d5f..f18bf60cc 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java @@ -66,7 +66,7 @@ public Object item() { @Override public T item(Class clazz) throws MappingException { - return configuration().mappingProvider().map(contextDocument, clazz, configuration); + return configuration().mappingProvider().map(contextDocument, clazz, configuration); } @Override diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicatePathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicatePathToken.java index bd6c5100f..93b871b73 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicatePathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicatePathToken.java @@ -77,13 +77,42 @@ public boolean accept(final Object obj, final Object root, final Configuration c Predicate.PredicateContext ctx = new PredicateContextImpl(obj, root, configuration, evaluationContext.documentEvalCache()); for (Predicate predicate : predicates) { - if (!predicate.apply (ctx)) { + if (!predicate.apply(ctx)) { return false; } } return true; } + private StackElementWrapper wrapper = null; + + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + assert(stack.getStack().size() > idx); + TokenStackElement curr = stack.getStack().get(idx); + + if (curr.getType() == TokenType.ARRAY_TOKEN || curr.getType() == TokenType.OBJECT_TOKEN) { + if (null == wrapper) { + wrapper = new StackElementWrapper(stack, idx); + } else { + wrapper.reset(idx); + } + + for (Predicate predicate : predicates) { + if (!predicate.apply(wrapper)) { + //if (!predicate.check(stack, idx)) { + return false; + } + } + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + return false; + } + @Override public String getPathFragment() { return FRAGMENTS[predicates.size() - 1]; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java index f7824036d..35405d827 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java @@ -14,17 +14,20 @@ */ package com.jayway.jsonpath.internal.token; +import java.util.List; +import java.util.logging.Logger; + import com.jayway.jsonpath.PathNotFoundException; import com.jayway.jsonpath.internal.PathRef; import com.jayway.jsonpath.internal.Utils; -import java.util.List; - /** * */ public class PropertyPathToken extends PathToken { + protected static Logger log = Logger.getLogger("com.jayway.jsonpath"); + private final List properties; public PropertyPathToken(List properties) { @@ -44,6 +47,30 @@ public void evaluate(String currentPath, PathRef parent, Object model, Evaluatio handleObjectProperty(currentPath, model, ctx, properties); } + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + assert(stack.getStack().size() > idx); + TokenStackElement curr = stack.getStack().get(idx); + + if (curr.getType() == TokenType.OBJECT_TOKEN) { + ObjectToken token = (ObjectToken)curr; + if (token.getKey() != null) { + for (String checkKey : properties) { + log.info("checking key " + checkKey + " against " + token.getKey()); + if (token.getKey().equals(checkKey)) { + if (isLeaf()) { + return stack.getStack().size() - 1 == idx; + } + return next().checkForMatch(stack, idx + 1); + } + } + } + } + + return false; + } + @Override boolean isTokenDefinite() { return true; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/RootPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/RootPathToken.java index 21f63787a..85117d272 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/RootPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/RootPathToken.java @@ -54,6 +54,16 @@ public void evaluate(String currentPath, PathRef pathRef, Object model, Evaluati } } + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + assert(0 == idx); + if (0 == stack.getStack().size()) { + return isLeaf(); + } + return !isLeaf() && next().checkForMatch(stack, 0); + } + @Override public String getPathFragment() { return "$"; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java index 5bb0d0e51..0cc502e44 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java @@ -96,6 +96,28 @@ private static Predicate createScanPredicate(final PathToken target, final Evalu } } + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + assert(stack.getStack().size() > idx); + TokenStackElement curr = stack.getStack().get(idx); + + if (curr.getType() == TokenType.ARRAY_TOKEN + || curr.getType() == TokenType.OBJECT_TOKEN) + { + //if ((idx - 1) == stack.getStack().size() && isLeaf()) + if (isLeaf()) { + return true; + } + for (int i = idx; i < stack.getStack().size(); ++i) { + if (next().checkForMatch(stack, i)) { + return true; + } + } + } + + return false; + } @Override boolean isTokenDefinite() { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StackElementWrapper.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StackElementWrapper.java new file mode 100644 index 000000000..036338c57 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StackElementWrapper.java @@ -0,0 +1,148 @@ + +package com.jayway.jsonpath.internal.token; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.Predicate; +import com.jayway.jsonpath.spi.mapper.MappingException; + +/** + * + */ +public class StackElementWrapper implements Predicate.PredicateContext +{ + private Map cache; + + private TokenStack stack; + private int idx; + private TokenStackElement elem; + + public StackElementWrapper(TokenStack s, int i) + { + stack = s; + idx = i; + elem = stack.getStack().get(i); + } + + public void reset(int i) + { + if (idx < i) { + // we are moving down the stack, so no cache removals are necessary + idx = i; + elem = stack.getStack().get(i); + } else if (idx > i) { + // we just popped up the stack, so we need to remove some things + // from the cache + TokenStackElement elem = null; + for (int j = i; j < idx; ++j) { + elem = stack.getStack().get(j); + popCache(this.elem); + //cache.remove(this.elem); + } + this.elem = elem; + idx = i; + } else { + TokenStackElement elem = stack.getStack().get(i); + if (this.elem != elem) { + popCache(this.elem); // just remove the previous thing + this.elem = elem; + } + } + } + + protected Object unwrap(TokenStackElement elem) + { + Object o = cache.get(elem); + + switch (elem.getType()) { + case ARRAY_TOKEN: + { + ArrayToken token = (ArrayToken)elem; + List l = (List)o; + if (null == l) { + + l = new ArrayList(token.getIndex() + 1); + cache.put(elem, l); + } + ((ArrayList)l).ensureCapacity(token.getIndex() + 1); + //for (int i = 0; i < token.getIndex(); ++i) { + // l.add(null); + //} + l.set(token.getIndex(), unwrap(token.getValue())); + return l; + } + case OBJECT_TOKEN: + { + ObjectToken token = (ObjectToken)elem; + Map m = (Map)o; + if (null == m) { + + m = new HashMap(); + cache.put(elem, m); + } + m.put(token.getKey(), unwrap(token.getValue())); + return m; + } + case STRING_TOKEN: + { + if (o != null) return o; + o = ((StringToken)elem).value; + //cache.put(elem, o); + return o; + } + case FLOAT_TOKEN: + { + if (o != null) return o; + o = new Float(((FloatToken)elem).value); + //cache.put(elem, o); + return o; + } + case INTEGER_TOKEN: + { + if (o != null) return o; + o = new Integer(((IntToken)elem).value); + //cache.put(elem, o); + return o; + } + default: + { + assert(false); + } + } + + return null; + } + + public void popCache(TokenStackElement elem) + { + cache.remove(elem); + } + + public Object item() + { + return unwrap(elem); + } + + public T item(Class clazz) throws MappingException + { + return configuration().mappingProvider().map( + item(), clazz, configuration()); + } + + public Object root() + { + return this; // ???? maybe unwrap the root element instead, + // but that's very very very expensive + // return unwrap(stack.getStack().get(0)); + } + + public Configuration configuration() + { + return stack.configuration(); + } +} + diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java new file mode 100644 index 000000000..2e1ae138c --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java @@ -0,0 +1,33 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public class StringToken implements TokenStackElement +{ + public String value; + + public StringToken(String s) + { + value = s; + } + + public TokenType getType() + { + return TokenType.STRING_TOKEN; + } + + public TokenStackElement getValue() + { + return null; + } + + public void setValue(TokenStackElement elem) + { + throw new RuntimeException(); + } +} + +// End StringToken.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java new file mode 100644 index 000000000..6c6844abd --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -0,0 +1,217 @@ + +package com.jayway.jsonpath.internal.token; + +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.EvaluationCallback; +import com.jayway.jsonpath.internal.Path; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; + +/** + * + * @author Hunter Payne + **/ +public class TokenStack +{ + protected static Logger log = Logger.getLogger("com.jayway.jsonpath"); + + protected Configuration conf; + protected Stack elements; + protected List paths; + protected Map matchedPaths; + + private TokenStackElement curr; + + public TokenStack(Configuration conf) + { + this.conf = conf; + paths = new ArrayList(); + matchedPaths = new HashMap(); + elements = new Stack(); + } + + public Stack getStack() + { + return elements; + } + + /** + * registers a path for which to fire results + */ + public void registerPath(Path path) + { + paths.add(path); + } + + // reads tokens and goes to first leaf + public void read(JsonParser parser, EvaluationCallback callback) + { + assert(callback != null); + try { + //boolean lookingForRow = true; + //TokenStackElement rowToken = null; + boolean needsPathCheck = false; + while (parser.nextToken() != null) { + boolean saveMatch = false; + switch (parser.getCurrentToken()) { + case START_ARRAY: + { + if (curr != null) { + TokenStackElement newElem = new ArrayToken(); + curr.setValue(newElem); + curr = newElem; + } else { + curr = new ArrayToken(); + } + saveMatch = true; + needsPathCheck = true; + elements.push(curr); + break; + } + case END_ARRAY: + { + Path match = matchedPaths.remove(curr); + if (match != null) { + callback.resultFoundExit(match); + } + elements.pop(); + if (elements.empty()) curr = null; + else curr = elements.peek(); + saveMatch = true; + needsPathCheck = true; + + break; + } + case VALUE_EMBEDDED_OBJECT: + case START_OBJECT: + { + if (curr != null) { + TokenStackElement newElem = new ObjectToken(); + curr.setValue(newElem); + curr = newElem; + } else { + curr = new ObjectToken(); + } + //if (!elements.empty()) + saveMatch = true; + needsPathCheck = true; + elements.push(curr); + break; + } + case END_OBJECT: + { + Path match = matchedPaths.remove(curr); + if (match != null) { + callback.resultFoundExit(match); + } + elements.pop(); + if (elements.empty()) curr = null; + else curr = elements.peek(); + saveMatch = true; + needsPathCheck = true; + break; + } + case FIELD_NAME: + { + assert(curr instanceof ObjectToken); + ((ObjectToken)curr).key = parser.getText(); + break; + } + case VALUE_FALSE: + { + StringToken newToken = new StringToken("FALSE"); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_TRUE: + { + StringToken newToken = new StringToken("TRUE"); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NUMBER_FLOAT: + { + FloatToken newToken = + new FloatToken((float)parser.getValueAsDouble()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NUMBER_INT: + { + IntToken newToken = + new IntToken(parser.getValueAsInt()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_STRING: + { + StringToken newToken = + new StringToken(parser.getText()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NULL: + { + curr.setValue(null); + needsPathCheck = true; + break; + } + default: + assert false; + } + // now check the paths for matches + if (needsPathCheck) { + for (Path path : paths) { + if (path.checkForMatch(this)) { + if (saveMatch) { + Path oldMatch = matchedPaths.get(curr); + if (oldMatch != null) { + callback.resultFoundExit(oldMatch); + } + matchedPaths.put(curr, path); + break; + } + callback.resultFound(path); + } + } + needsPathCheck = false; + } + } + } catch (Exception e) { + //e.printStackTrace(); + log.log(Level.INFO, e.getMessage(), e); + } + log.fine("finished read"); + } + + public String toString() + { + StringBuilder sb = new StringBuilder(); + sb.append("Token Stack depth="); + sb.append(elements.size()); + for (TokenStackElement elem : elements) { + sb.append(" "); + sb.append(elem.toString()); + } + sb.append(" "); + sb.append(elements.peek().getValue()); + return sb.toString(); + } + + public Configuration configuration() + { + return conf; + } +} + +// End TokenStack.java + diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java new file mode 100644 index 000000000..ea1027d14 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java @@ -0,0 +1,17 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public interface TokenStackElement +{ + public TokenType getType(); // otherwise its an object + + public TokenStackElement getValue(); + + public void setValue(TokenStackElement elem); +} + +// End TokenStackElement.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenType.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenType.java new file mode 100644 index 000000000..d8af2b521 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenType.java @@ -0,0 +1,17 @@ + +package com.jayway.jsonpath.internal.token; + +/** + * + * @author Hunter Payne + **/ +public enum TokenType +{ + ARRAY_TOKEN, + OBJECT_TOKEN, + STRING_TOKEN, + FLOAT_TOKEN, + INTEGER_TOKEN +} + +// End TokenType.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/WildcardPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/WildcardPathToken.java index 243c00c76..2e7bcc440 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/WildcardPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/WildcardPathToken.java @@ -44,6 +44,14 @@ public void evaluate(String currentPath, PathRef parent, Object model, Evaluatio } } + @Override + public boolean checkForMatch(TokenStack stack, int idx) + { + if (idx + 1 < stack.getStack().size()) { + return !isLeaf() && next().checkForMatch(stack, idx + 1); + } + return isLeaf(); + } @Override boolean isTokenDefinite() { From 28486207d21f2f70731c40726e142539e129e393 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Fri, 22 May 2015 13:24:08 -0700 Subject: [PATCH 02/17] Adding more streaming changes --- .../java/com/jayway/jsonpath/internal/CompiledPath.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java b/json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java index eed16fede..dc176772e 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java @@ -17,6 +17,7 @@ import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.internal.token.EvaluationContextImpl; import com.jayway.jsonpath.internal.token.PathToken; +import com.jayway.jsonpath.internal.token.TokenStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +62,11 @@ public EvaluationContext evaluate(Object document, Object rootDocument, Configur return evaluate(document, rootDocument, configuration, false); } + @Override + public boolean checkForMatch(TokenStack stack) { + return root.checkForMatch(stack, 0); + } + @Override public boolean isDefinite() { return root.isPathDefinite(); From ea8b1efd9a3d9e541ae26ee27f5b48d519225556 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Fri, 22 May 2015 13:24:29 -0700 Subject: [PATCH 03/17] Adding more streaming changes --- .../src/main/java/com/jayway/jsonpath/internal/Path.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/Path.java b/json-path/src/main/java/com/jayway/jsonpath/internal/Path.java index b87b7b55d..b468f276c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/Path.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/Path.java @@ -15,6 +15,7 @@ package com.jayway.jsonpath.internal; import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.internal.token.TokenStack; /** * @@ -43,6 +44,12 @@ public interface Path { */ EvaluationContext evaluate(Object document, Object rootDocument, Configuration configuration, boolean forUpdate); + /** + * checks the parser state represented by stack and determines if this + * path matches it + */ + boolean checkForMatch(TokenStack stack); + /** * * @return true id this path is definite From 26cf2739655daaf5cfbb95978c66cc111b263407 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Fri, 22 May 2015 13:24:41 -0700 Subject: [PATCH 04/17] Changes to make tests compile --- .../src/test/java/com/jayway/jsonpath/FilterTest.java | 6 ++++++ .../src/test/java/com/jayway/jsonpath/PredicateTest.java | 6 ++++++ .../test/java/com/jayway/jsonpath/old/FilterTest.java | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java index 45956b527..971064535 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.regex.Pattern; +import com.jayway.jsonpath.internal.token.TokenStack; import static com.jayway.jsonpath.Criteria.where; import static com.jayway.jsonpath.Filter.filter; import static org.assertj.core.api.Assertions.assertThat; @@ -384,6 +385,11 @@ public boolean apply(PredicateContext ctx) { return i == 1; } + + @Override + public boolean check(TokenStack stack, int idx) { + return false; + } }; assertThat(filter(where("string-key").eq("string").and("$").matches(p)).apply(createPredicateContext(json))).isEqualTo(true); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java index 62939070e..d6b3afd42 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import com.jayway.jsonpath.internal.token.TokenStack; import static com.jayway.jsonpath.JsonPath.using; import static org.assertj.core.api.Assertions.assertThat; @@ -19,6 +20,11 @@ public void predicates_filters_can_be_applied() { public boolean apply(PredicateContext ctx) { return ctx.item(Map.class).containsKey("isbn"); } + + @Override + public boolean check(TokenStack stack, int idx) { + return false; + } }; assertThat(reader.read("$.store.book[?].isbn", List.class, booksWithISBN)).containsOnly("0-395-19395-8", "0-553-21311-3"); diff --git a/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java index 07d386467..63677c038 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java @@ -8,6 +8,7 @@ import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Predicate; import com.jayway.jsonpath.spi.json.JsonProvider; +import com.jayway.jsonpath.internal.token.TokenStack; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -346,6 +347,10 @@ public boolean apply(PredicateContext ctx) { } return false; } + @Override + public boolean check(TokenStack stack, int idx) { + return false; + } }; Filter rootChildFilter = filter(where("name").regex(Pattern.compile("rootChild_[A|B]"))); @@ -366,6 +371,10 @@ public void arrays_of_objects_can_be_filtered() throws Exception { public boolean apply(PredicateContext ctx) { return 1 == (Integer)ctx.item(); } + @Override + public boolean check(TokenStack stack, int idx) { + return false; + } }; List res = JsonPath.read(doc, "$.items[?]", customFilter); From a9a9f685ed987d95a91d00f45794155007fc4535 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 25 May 2015 17:24:44 -0700 Subject: [PATCH 05/17] Adding unit testing for the streaming API --- .../internal/token/ArrayPathToken.java | 2 +- .../internal/token/PropertyPathToken.java | 5 +- .../internal/token/ScanPathToken.java | 2 +- .../jsonpath/internal/token/TokenStack.java | 255 ++++---- .../com/jayway/jsonpath/CallbackRecorder.java | 56 ++ .../java/com/jayway/jsonpath/JacksonTest.java | 552 +++++++++++++++++- 6 files changed, 736 insertions(+), 136 deletions(-) create mode 100644 json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java index ca3bbeea2..2cfeefaec 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java @@ -181,7 +181,7 @@ public String getPathFragment() { @Override public boolean checkForMatch(TokenStack stack, int idx) { - assert(stack.getStack().size() > idx); + if (stack.getStack().size() <= idx) return false; TokenStackElement curr = stack.getStack().get(idx); if (curr.getType() == TokenType.ARRAY_TOKEN) { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java index 35405d827..5b4048718 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PropertyPathToken.java @@ -26,8 +26,6 @@ */ public class PropertyPathToken extends PathToken { - protected static Logger log = Logger.getLogger("com.jayway.jsonpath"); - private final List properties; public PropertyPathToken(List properties) { @@ -50,14 +48,13 @@ public void evaluate(String currentPath, PathRef parent, Object model, Evaluatio @Override public boolean checkForMatch(TokenStack stack, int idx) { - assert(stack.getStack().size() > idx); + if (stack.getStack().size() <= idx) return false; TokenStackElement curr = stack.getStack().get(idx); if (curr.getType() == TokenType.OBJECT_TOKEN) { ObjectToken token = (ObjectToken)curr; if (token.getKey() != null) { for (String checkKey : properties) { - log.info("checking key " + checkKey + " against " + token.getKey()); if (token.getKey().equals(checkKey)) { if (isLeaf()) { return stack.getStack().size() - 1 == idx; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java index 0cc502e44..e2bef8793 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ScanPathToken.java @@ -99,7 +99,7 @@ private static Predicate createScanPredicate(final PathToken target, final Evalu @Override public boolean checkForMatch(TokenStack stack, int idx) { - assert(stack.getStack().size() > idx); + if (stack.getStack().size() <= idx) return false; TokenStackElement curr = stack.getStack().get(idx); if (curr.getType() == TokenType.ARRAY_TOKEN diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index 6c6844abd..10bd78d6b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -47,150 +47,147 @@ public void registerPath(Path path) paths.add(path); } - // reads tokens and goes to first leaf + /** + * reads from stream and notifies the callback of matched registered paths + */ public void read(JsonParser parser, EvaluationCallback callback) + throws Exception { assert(callback != null); - try { - //boolean lookingForRow = true; - //TokenStackElement rowToken = null; - boolean needsPathCheck = false; - while (parser.nextToken() != null) { - boolean saveMatch = false; - switch (parser.getCurrentToken()) { - case START_ARRAY: - { - if (curr != null) { - TokenStackElement newElem = new ArrayToken(); - curr.setValue(newElem); - curr = newElem; - } else { - curr = new ArrayToken(); - } - saveMatch = true; - needsPathCheck = true; - elements.push(curr); - break; - } - case END_ARRAY: - { - Path match = matchedPaths.remove(curr); - if (match != null) { - callback.resultFoundExit(match); - } - elements.pop(); - if (elements.empty()) curr = null; - else curr = elements.peek(); - saveMatch = true; - needsPathCheck = true; - break; + boolean needsPathCheck = false; + while (parser.nextToken() != null) { + boolean saveMatch = false; + switch (parser.getCurrentToken()) { + case START_ARRAY: + { + if (curr != null) { + TokenStackElement newElem = new ArrayToken(); + curr.setValue(newElem); + curr = newElem; + } else { + curr = new ArrayToken(); } - case VALUE_EMBEDDED_OBJECT: - case START_OBJECT: - { - if (curr != null) { - TokenStackElement newElem = new ObjectToken(); - curr.setValue(newElem); - curr = newElem; - } else { - curr = new ObjectToken(); - } - //if (!elements.empty()) - saveMatch = true; - needsPathCheck = true; - elements.push(curr); - break; + saveMatch = true; + needsPathCheck = true; + elements.push(curr); + break; + } + case END_ARRAY: + { + Path match = matchedPaths.remove(curr); + if (match != null) { + callback.resultFoundExit(match); } - case END_OBJECT: - { - Path match = matchedPaths.remove(curr); - if (match != null) { + elements.pop(); + if (elements.empty()) curr = null; + else curr = elements.peek(); + break; + } + case VALUE_EMBEDDED_OBJECT: + case START_OBJECT: + { + if (curr != null && curr.getType() == TokenType.ARRAY_TOKEN) { + + if (((ArrayToken)curr).getValue() != null && + matchedPaths.containsKey(curr)) { + + Path match = matchedPaths.remove(curr); callback.resultFoundExit(match); + + if (match.checkForMatch(this)) { + + matchedPaths.put(curr, match); + callback.resultFound(match); + } } - elements.pop(); - if (elements.empty()) curr = null; - else curr = elements.peek(); - saveMatch = true; - needsPathCheck = true; - break; - } - case FIELD_NAME: - { - assert(curr instanceof ObjectToken); - ((ObjectToken)curr).key = parser.getText(); - break; - } - case VALUE_FALSE: - { - StringToken newToken = new StringToken("FALSE"); - curr.setValue(newToken); - needsPathCheck = true; - break; } - case VALUE_TRUE: - { - StringToken newToken = new StringToken("TRUE"); - curr.setValue(newToken); - needsPathCheck = true; - break; - } - case VALUE_NUMBER_FLOAT: - { - FloatToken newToken = - new FloatToken((float)parser.getValueAsDouble()); - curr.setValue(newToken); - needsPathCheck = true; - break; - } - case VALUE_NUMBER_INT: - { - IntToken newToken = - new IntToken(parser.getValueAsInt()); - curr.setValue(newToken); - needsPathCheck = true; - break; - } - case VALUE_STRING: - { - StringToken newToken = - new StringToken(parser.getText()); - curr.setValue(newToken); - needsPathCheck = true; - break; - } - case VALUE_NULL: - { - curr.setValue(null); - needsPathCheck = true; - break; + + if (curr != null) { + TokenStackElement newElem = new ObjectToken(); + curr.setValue(newElem); + curr = newElem; + } else { + curr = new ObjectToken(); } - default: - assert false; + saveMatch = true; + needsPathCheck = true; + elements.push(curr); + break; + } + case END_OBJECT: + { + Path match = matchedPaths.remove(curr); + if (match != null) { + callback.resultFoundExit(match); } - // now check the paths for matches - if (needsPathCheck) { - for (Path path : paths) { - if (path.checkForMatch(this)) { - if (saveMatch) { - Path oldMatch = matchedPaths.get(curr); - if (oldMatch != null) { - callback.resultFoundExit(oldMatch); - } - matchedPaths.put(curr, path); - break; - } - callback.resultFound(path); - } + elements.pop(); + if (elements.empty()) curr = null; + else curr = elements.peek(); + break; + } + case FIELD_NAME: + { + assert(curr instanceof ObjectToken); + ((ObjectToken)curr).key = parser.getText(); + break; + } + case VALUE_FALSE: + { + StringToken newToken = new StringToken("FALSE"); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_TRUE: + { + StringToken newToken = new StringToken("TRUE"); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NUMBER_FLOAT: + { + FloatToken newToken = + new FloatToken((float)parser.getValueAsDouble()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NUMBER_INT: + { + IntToken newToken = new IntToken(parser.getValueAsInt()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_STRING: + { + StringToken newToken = new StringToken(parser.getText()); + curr.setValue(newToken); + needsPathCheck = true; + break; + } + case VALUE_NULL: + { + curr.setValue(null); + needsPathCheck = true; + break; + } + default: + assert false; + } + // now check the paths for matches + if (needsPathCheck) { + for (Path path : paths) { + if (path.checkForMatch(this)) { + if (saveMatch) matchedPaths.put(curr, path); + callback.resultFound(path); } - needsPathCheck = false; } + needsPathCheck = false; } - } catch (Exception e) { - //e.printStackTrace(); - log.log(Level.INFO, e.getMessage(), e); } - log.fine("finished read"); } public String toString() diff --git a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java new file mode 100644 index 000000000..a1ef55a91 --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java @@ -0,0 +1,56 @@ +package com.jayway.jsonpath; + +import java.util.List; +import java.util.ArrayList; + +import com.jayway.jsonpath.EvaluationCallback; +import com.jayway.jsonpath.internal.Path; + +public class CallbackRecorder implements EvaluationCallback { + + public static class CallbackEvent { + private Path path; + private boolean exit; + public CallbackEvent(Path path, boolean exit) { + this.path = path; + this.exit = exit; + } + + public Path getPath() { + return path; + } + + public boolean isExit() { + return exit; + } + + public boolean equals(Object o) { + if (o instanceof CallbackEvent) { + CallbackEvent other = (CallbackEvent)o; + return other.getPath() == path && other.isExit() == exit; + } + return false; + } + } + + private List results; + + public CallbackRecorder() { + + results = new ArrayList(); + } + + public void resultFound(Path path) { + System.err.println("found result " + path); + results.add(new CallbackEvent(path, false)); + } + + public void resultFoundExit(Path path) { + System.err.println("exiting result " + path); + results.add(new CallbackEvent(path, true)); + } + + public List getResults() { + return results; + } +} diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 7799c9d7a..5b4f24564 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -3,11 +3,22 @@ import org.junit.Test; import java.util.Date; +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.nio.charset.Charset; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonFactory; + +import com.jayway.jsonpath.EvaluationCallback; +import com.jayway.jsonpath.internal.Path; +import com.jayway.jsonpath.internal.PathCompiler; +import com.jayway.jsonpath.internal.token.*; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; -public class JacksonTest extends BaseTest { +public class JacksonTest extends BaseTest implements EvaluationCallback { @Test public void an_object_can_be_mapped_to_pojo() { @@ -45,4 +56,543 @@ public void jackson_converts_dates() { assertThat(date).isEqualTo(now); } + protected TokenStack stack = null; + protected CallbackRecorder recorder = null; + protected Path idPath = null; + protected int match = 0; + + @Test + public void streamingTest() throws Exception { + + Path path = + PathCompiler.compile("$..completed_tasks[0:]"); + idPath = + PathCompiler.compile("$..completed_tasks[0:].id"); + stack = new TokenStack(JACKSON_CONFIGURATION); + + recorder = new CallbackRecorder(); + String res = "issue_76.json"; + InputStream stream = + getClass().getClassLoader().getResourceAsStream(res); + assert(stream != null); + + JsonFactory factory = new JsonFactory(); + stack.registerPath(path); + stack.registerPath(idPath); + stack.read(factory.createJsonParser(stream), this); + Thread.sleep(1000); + + assert(recorder.getResults().get(0). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(1). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(2). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(3). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(4). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(5). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(6). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(7). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(8). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(9). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(10). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(11). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(12). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(13). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(14). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(15). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(16). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(17). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(18). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(19). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(20). + equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(21). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(22). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(23). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + + assert(recorder.getResults().get(24). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(25). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(26). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(27). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(28). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(29). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(30). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(31). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(32). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(33). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(34). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(35). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(36). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(37). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(38). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(39). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(40). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(41). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(42). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(43). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(44). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(45). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(46). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(47). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(48). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(49). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(50). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(51). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(52). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(53). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(54). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(55). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(56). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(57). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(58). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(59). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(60). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(61). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(62). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(63). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(64). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(65). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(66). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(67). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(68). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(69). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(70). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(71). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(72). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(73). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(74). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(75). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(76). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(77). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(78). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(79). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(80). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(81). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(82). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(83). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(84). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(85). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(86). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(87). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(88). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(89). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(90). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(91). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(92). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(93). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(94). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(95). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(96). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(97). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(98). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(99). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(100). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(101). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(102). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(103). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(104). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(105). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(106). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(107). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(108). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(109). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(110). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(111). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(112). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(113). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(114). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(115). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(116). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(117). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(118). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(119). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(120). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(121). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(122). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(123). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(124). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(125). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(126). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(127). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(128). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(129). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(130). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(131). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(132). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(133). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(134). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(135). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(136). + equals(new CallbackRecorder.CallbackEvent(path, true))); + + assert(recorder.getResults().get(137). + equals(new CallbackRecorder.CallbackEvent(path, false))); + assert(recorder.getResults().get(138). + equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(139). + equals(new CallbackRecorder.CallbackEvent(path, true))); + } + + public void resultFound(Path path) { + if (path == idPath) { + switch (match++) { + case 0: + checkResult(stack, "mesos-jenkins-172c6f74-12bc-44fe-849a-ad902ddc2b64"); + break; + case 1: + checkResult(stack, "mesos-jenkins-cd18b433-e2ee-4a4e-875b-6ea82d90a53a"); + break; + case 2: + checkResult(stack, "mesos-jenkins-66fca7c0-88f7-4a1a-9796-a6de2e337b0a"); + break; + case 3: + checkResult(stack, "mesos-jenkins-258ad47c-85bf-4fe0-b7c4-4f0cc70f2998"); + break; + case 4: + checkResult(stack, "mesos-jenkins-f30e5e34-2ef6-4993-9260-73ee3520c0a5"); + break; + case 5: + checkResult(stack, "mesos-jenkins-1fc0bbd8-f0ff-48cd-a7f7-24a9436ba6bc"); + break; + case 6: + checkResult(stack, "mesos-jenkins-62b44026-843d-4813-a6a8-e95215250bb1"); + break; + case 7: + checkResult(stack, "mesos-jenkins-807b9b8a-3283-4e78-94e1-9dc17df4df77"); + break; + case 8: + checkResult(stack, "test_dv_helloworld.95f49d05-c9bf-11e4-a1fc-56847afe9799"); + break; + case 9: + checkResult(stack, "test_dv_helloworld.a40abda6-ca02-11e4-a1fc-56847afe9799"); + break; + case 10: + checkResult(stack, "test_dv_helloworld.3946a287-ca67-11e4-a1fc-56847afe9799"); + break; + case 11: + checkResult(stack, "test_dv_helloworld.fec0c74c-ce11-11e4-a1fc-56847afe9799"); + break; + case 12: + checkResult(stack, "test_jenkins-master.33d4007e-cf37-11e4-a1fc-56847afe9799"); + break; + case 13: + checkResult(stack, "test_jenkins-master.359deb0f-cf37-11e4-a1fc-56847afe9799"); + break; + case 14: + checkResult(stack, "test_jenkins-master.50773d6a-cf37-11e4-a1fc-56847afe9799"); + break; + case 15: + checkResult(stack, "test_jenkins-master.638fd9ce-cf37-11e4-a1fc-56847afe9799"); + break; + case 16: + checkResult(stack, "test_jenkins-master.81fd2852-cf37-11e4-a1fc-56847afe9799"); + break; + case 17: + checkResult(stack, "test_jenkins-master.afedb77b-cf37-11e4-a1fc-56847afe9799"); + break; + case 18: + checkResult(stack, "test_jenkins-master.0243c011-cf38-11e4-a1fc-56847afe9799"); + break; + case 19: + checkResult(stack, "test_dv_helloworld.4bdb1099-d1de-11e4-a1fc-56847afe9799"); + break; + case 20: + checkResult(stack, "sdp_shared_jenkins-master.eb8f2863-c9a2-11e4-a1fc-56847afe9799"); + break; + case 21: + checkResult(stack, "test_dv_helloworld.c7865efb-cd05-11e4-a1fc-56847afe9799"); + break; + case 22: + checkResult(stack, "test_jenkins-master.37684ad0-cf37-11e4-a1fc-56847afe9799"); + break; + case 23: + checkResult(stack, "test_jenkins-master.3c2e3752-cf37-11e4-a1fc-56847afe9799"); + break; + case 24: + checkResult(stack, "test_jenkins-master.405b3f34-cf37-11e4-a1fc-56847afe9799"); + break; + case 25: + checkResult(stack, "test_jenkins-master.44886e26-cf37-11e4-a1fc-56847afe9799"); + break; + case 26: + checkResult(stack, "test_jenkins-master.54a4936b-cf37-11e4-a1fc-56847afe9799"); + break; + case 27: + checkResult(stack, "test_jenkins-master.58d1e96c-cf37-11e4-a1fc-56847afe9799"); + break; + case 28: + checkResult(stack, "test_jenkins-master.5d97fcfd-cf37-11e4-a1fc-56847afe9799"); + break; + case 29: + checkResult(stack, "test_jenkins-master.6986f34f-cf37-11e4-a1fc-56847afe9799"); + break; + case 30: + checkResult(stack, "test_jenkins-master.790a33f1-cf37-11e4-a1fc-56847afe9799"); + break; + case 31: + checkResult(stack, "test_jenkins-master.8c2149b3-cf37-11e4-a1fc-56847afe9799"); + break; + case 32: + checkResult(stack, "test_jenkins-master.9c3d47e4-cf37-11e4-a1fc-56847afe9799"); + break; + case 33: + checkResult(stack, "test_jenkins-master.a06a01a6-cf37-11e4-a1fc-56847afe9799"); + break; + case 34: + checkResult(stack, "test_jenkins-master.fa821fbd-cf37-11e4-a1fc-56847afe9799"); + break; + case 35: + checkResult(stack, "test_jenkins-master.fbb39ade-cf37-11e4-a1fc-56847afe9799"); + break; + case 36: + checkResult(stack, "test_jenkins-master.ffe0f0e0-cf37-11e4-a1fc-56847afe9799"); + break; + case 37: + checkResult(stack, "test_jenkins-master.04a68f42-cf38-11e4-a1fc-56847afe9799"); + break; + case 38: + checkResult(stack, "test_jenkins-master.4ce2cc09-cf37-11e4-a1fc-56847afe9799"); + break; + case 39: + checkResult(stack, "test_jenkins-master.a792e469-cf37-11e4-a1fc-56847afe9799"); + break; + case 40: + checkResult(stack, "test_jenkins-master.fe166a0f-cf37-11e4-a1fc-56847afe9799"); + break; + case 41: + checkResult(stack, "test_jenkins-master.0670c7f3-cf38-11e4-a1fc-56847afe9799"); + break; + case 42: + checkResult(stack, "test_dev_frontend.3950b432-d234-11e4-bc5e-56847afe9799"); + break; + case 43: + checkResult(stack, "test_dv_helloworld.c3a7d253-d241-11e4-bc5e-56847afe9799"); + break; + case 44: + checkResult(stack, "test_dv_helloworld.d7c6b3c4-d244-11e4-bc5e-56847afe9799"); + break; + case 45: + checkResult(stack, "test_dev_frontend.a0f3f185-d2e6-11e4-bc5e-56847afe9799"); + break; + } + //} else { + } + recorder.resultFound(path); + } + + public void resultFoundExit(Path path) { + assert(path != idPath); + recorder.resultFoundExit(path); + } + + protected void checkResult(TokenStack stack, Object expected) { + checkResult(stack.getStack().peek(), expected); + } + + protected void checkResult(TokenStackElement elem, Object expected) { + switch (elem.getType()) { + case STRING_TOKEN: + { + StringToken token = (StringToken)elem; + assert(token.value.equals(expected)); + break; + } + case FLOAT_TOKEN: + { + FloatToken token = (FloatToken)elem; + assert(expected instanceof Float); + assert(token.value == ((Float)expected).floatValue()); + break; + } + case INTEGER_TOKEN: + { + IntToken token = (IntToken)elem; + assert(expected instanceof Integer); + assert(token.value == ((Integer)expected).intValue()); + break; + } + case ARRAY_TOKEN: + case OBJECT_TOKEN: + { + checkResult(elem.getValue(), expected); + break; + } + default: + { + assert(false); + } + } + } } From 6c59889996709045aed0b6f95968894c4b3d470c Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 25 May 2015 17:43:52 -0700 Subject: [PATCH 06/17] Making the testing a bit more flexible --- .../java/com/jayway/jsonpath/JacksonTest.java | 281 +++++++++--------- 1 file changed, 141 insertions(+), 140 deletions(-) diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 5b4f24564..e49ce886a 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -76,332 +76,333 @@ public void streamingTest() throws Exception { getClass().getClassLoader().getResourceAsStream(res); assert(stream != null); + int count = 0; JsonFactory factory = new JsonFactory(); stack.registerPath(path); stack.registerPath(idPath); stack.read(factory.createJsonParser(stream), this); Thread.sleep(1000); - assert(recorder.getResults().get(0). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(1). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(2). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(3). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(4). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(5). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(6). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(7). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(8). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(9). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(10). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(11). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(12). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(13). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(14). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(15). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(16). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(17). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(18). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(19). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(20). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(21). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(22). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(23). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(24). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(25). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(26). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(27). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(28). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(29). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(30). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(31). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(32). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(33). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(34). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(35). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(36). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(37). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(38). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(39). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(40). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(41). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(42). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(43). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(44). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(45). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(46). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(47). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(48). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(49). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(50). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(51). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(52). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(53). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(54). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(55). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(56). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(57). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(58). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(59). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(60). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(61). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(62). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(63). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(64). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(65). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(66). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(67). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(68). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(69). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(70). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(71). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(72). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(73). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(74). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(75). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(76). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(77). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(78). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(79). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(80). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(81). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(82). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(83). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(84). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(85). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(86). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(87). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(88). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(89). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(90). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(91). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(92). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(93). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(94). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(95). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(96). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(97). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(98). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(99). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(100). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(101). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(102). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(103). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(104). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(105). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(106). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(107). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(108). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(109). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(110). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(111). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(112). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(113). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(114). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(115). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(116). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(117). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(118). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(119). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(120). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(121). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(122). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(123). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(124). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(125). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(126). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(127). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(128). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(129). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(130). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(131). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(132). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(133). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(134). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(135). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(136). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); - assert(recorder.getResults().get(137). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); - assert(recorder.getResults().get(138). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); - assert(recorder.getResults().get(139). + assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); } From d59251d72fe4d05fa258beb2c85e3609a8f26acb Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 25 May 2015 18:31:45 -0700 Subject: [PATCH 07/17] Improving unit test for streaming to cover floats and ints --- .../java/com/jayway/jsonpath/JacksonTest.java | 488 +++++++++++++++++- 1 file changed, 487 insertions(+), 1 deletion(-) diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index e49ce886a..a8a23863a 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -60,6 +60,10 @@ public void jackson_converts_dates() { protected CallbackRecorder recorder = null; protected Path idPath = null; protected int match = 0; + protected Path floatPath = null; + protected int floatMatch = 0; + protected Path intPath = null; + protected int intMatch = 0; @Test public void streamingTest() throws Exception { @@ -68,6 +72,10 @@ public void streamingTest() throws Exception { PathCompiler.compile("$..completed_tasks[0:]"); idPath = PathCompiler.compile("$..completed_tasks[0:].id"); + floatPath = + PathCompiler.compile("$..completed_tasks[0:].resources.cpus"); + intPath = + PathCompiler.compile("$..completed_tasks[0:].resources.mem"); stack = new TokenStack(JACKSON_CONFIGURATION); recorder = new CallbackRecorder(); @@ -80,6 +88,8 @@ public void streamingTest() throws Exception { JsonFactory factory = new JsonFactory(); stack.registerPath(path); stack.registerPath(idPath); + stack.registerPath(floatPath); + stack.registerPath(intPath); stack.read(factory.createJsonParser(stream), this); Thread.sleep(1000); @@ -87,24 +97,40 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -112,24 +138,40 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -143,6 +185,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -150,6 +196,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -157,6 +207,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -164,6 +218,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -171,6 +229,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -178,6 +240,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -185,6 +251,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -192,6 +262,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -199,6 +273,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -206,6 +284,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -213,6 +295,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -220,6 +306,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -227,6 +317,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -234,6 +328,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -241,6 +339,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -248,6 +350,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -255,6 +361,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -262,6 +372,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -269,6 +383,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -276,6 +394,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -283,6 +405,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -290,6 +416,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -297,6 +427,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -304,6 +438,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -311,6 +449,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -318,6 +460,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -325,6 +471,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -332,6 +482,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -339,6 +493,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -346,6 +504,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -353,6 +515,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -360,6 +526,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -367,6 +537,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -374,6 +548,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -381,6 +559,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -388,6 +570,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -395,6 +581,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); @@ -402,6 +592,10 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(idPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(floatPath, false))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); } @@ -548,13 +742,304 @@ public void resultFound(Path path) { checkResult(stack, "test_dev_frontend.a0f3f185-d2e6-11e4-bc5e-56847afe9799"); break; } - //} else { + } else if (path == floatPath) { + + switch (floatMatch++) { + case 0: + checkResult(stack, new Float(0.2)); + break; + case 1: + checkResult(stack, new Float(0.2)); + break; + case 2: + checkResult(stack, new Float(0.2)); + break; + case 3: + checkResult(stack, new Float(0.2)); + break; + case 4: + checkResult(stack, new Float(0.2)); + break; + case 5: + checkResult(stack, new Float(0.2)); + break; + case 6: + checkResult(stack, new Float(0.2)); + break; + case 7: + checkResult(stack, new Float(0.2)); + break; + case 8: + checkResult(stack, new Float(0.1)); + break; + case 9: + checkResult(stack, new Float(0.1)); + break; + case 10: + checkResult(stack, new Float(0.1)); + break; + case 11: + checkResult(stack, new Float(0.1)); + break; + case 12: + checkResult(stack, new Float(0.3)); + break; + case 13: + checkResult(stack, new Float(0.3)); + break; + case 14: + checkResult(stack, new Float(0.3)); + break; + case 15: + checkResult(stack, new Float(0.3)); + break; + case 16: + checkResult(stack, new Float(0.3)); + break; + case 17: + checkResult(stack, new Float(0.3)); + break; + case 18: + checkResult(stack, new Float(0.3)); + break; + case 19: + checkResult(stack, new Float(0.1)); + break; + case 20: + checkResult(stack, new Float(0.3)); + break; + case 21: + checkResult(stack, new Float(0.1)); + break; + case 22: + checkResult(stack, new Float(0.3)); + break; + case 23: + checkResult(stack, new Float(0.3)); + break; + case 24: + checkResult(stack, new Float(0.3)); + break; + case 25: + checkResult(stack, new Float(0.3)); + break; + case 26: + checkResult(stack, new Float(0.3)); + break; + case 27: + checkResult(stack, new Float(0.3)); + break; + case 28: + checkResult(stack, new Float(0.3)); + break; + case 29: + checkResult(stack, new Float(0.3)); + break; + case 30: + checkResult(stack, new Float(0.3)); + break; + case 31: + checkResult(stack, new Float(0.3)); + break; + case 32: + checkResult(stack, new Float(0.3)); + break; + case 33: + checkResult(stack, new Float(0.3)); + break; + case 34: + checkResult(stack, new Float(0.3)); + break; + case 35: + checkResult(stack, new Float(0.3)); + break; + case 36: + checkResult(stack, new Float(0.3)); + break; + case 37: + checkResult(stack, new Float(0.3)); + break; + case 38: + checkResult(stack, new Float(0.3)); + break; + case 39: + checkResult(stack, new Float(0.3)); + break; + case 40: + checkResult(stack, new Float(0.3)); + break; + case 41: + checkResult(stack, new Float(0.3)); + break; + case 42: + checkResult(stack, new Float(0.2)); + break; + case 43: + checkResult(stack, new Float(0.1)); + break; + case 44: + checkResult(stack, new Float(0.1)); + break; + case 45: + checkResult(stack, new Float(0.2)); + break; + default: + assert(false); + break; + } + } else if (path == intPath) { + + switch (intMatch++) { + case 0: + checkResult(stack, new Integer(704)); + break; + case 1: + checkResult(stack, new Integer(704)); + break; + case 2: + checkResult(stack, new Integer(704)); + break; + case 3: + checkResult(stack, new Integer(704)); + break; + case 4: + checkResult(stack, new Integer(704)); + break; + case 5: + checkResult(stack, new Integer(704)); + break; + case 6: + checkResult(stack, new Integer(704)); + break; + case 7: + checkResult(stack, new Integer(704)); + break; + case 8: + checkResult(stack, new Integer(32)); + break; + case 9: + checkResult(stack, new Integer(32)); + break; + case 10: + checkResult(stack, new Integer(32)); + break; + case 11: + checkResult(stack, new Integer(32)); + break; + case 12: + checkResult(stack, new Integer(768)); + break; + case 13: + checkResult(stack, new Integer(768)); + break; + case 14: + checkResult(stack, new Integer(768)); + break; + case 15: + checkResult(stack, new Integer(768)); + break; + case 16: + checkResult(stack, new Integer(768)); + break; + case 17: + checkResult(stack, new Integer(768)); + break; + case 18: + checkResult(stack, new Integer(768)); + break; + case 19: + checkResult(stack, new Integer(32)); + break; + case 20: + checkResult(stack, new Integer(768)); + break; + case 21: + checkResult(stack, new Integer(32)); + break; + case 22: + checkResult(stack, new Integer(768)); + break; + case 23: + checkResult(stack, new Integer(768)); + break; + case 24: + checkResult(stack, new Integer(768)); + break; + case 25: + checkResult(stack, new Integer(768)); + break; + case 26: + checkResult(stack, new Integer(768)); + break; + case 27: + checkResult(stack, new Integer(768)); + break; + case 28: + checkResult(stack, new Integer(768)); + break; + case 29: + checkResult(stack, new Integer(768)); + break; + case 30: + checkResult(stack, new Integer(768)); + break; + case 31: + checkResult(stack, new Integer(768)); + break; + case 32: + checkResult(stack, new Integer(768)); + break; + case 33: + checkResult(stack, new Integer(768)); + break; + case 34: + checkResult(stack, new Integer(768)); + break; + case 35: + checkResult(stack, new Integer(768)); + break; + case 36: + checkResult(stack, new Integer(768)); + break; + case 37: + checkResult(stack, new Integer(768)); + break; + case 38: + checkResult(stack, new Integer(768)); + break; + case 39: + checkResult(stack, new Integer(768)); + break; + case 40: + checkResult(stack, new Integer(768)); + break; + case 41: + checkResult(stack, new Integer(768)); + break; + case 42: + checkResult(stack, new Integer(1024)); + break; + case 43: + checkResult(stack, new Integer(32)); + break; + case 44: + checkResult(stack, new Integer(32)); + break; + case 45: + checkResult(stack, new Integer(1024)); + break; + default: + assert(false); + break; + } } recorder.resultFound(path); } public void resultFoundExit(Path path) { assert(path != idPath); + assert(path != floatPath); + assert(path != intPath); recorder.resultFoundExit(path); } @@ -581,6 +1066,7 @@ protected void checkResult(TokenStackElement elem, Object expected) { { IntToken token = (IntToken)elem; assert(expected instanceof Integer); + System.err.println("comparing " + token.value + " expected " + expected); assert(token.value == ((Integer)expected).intValue()); break; } From 29bbbfb17ace26f3eeeb301091a9b27c5aadca87 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 25 May 2015 18:33:59 -0700 Subject: [PATCH 08/17] Removing a debug statement --- json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index a8a23863a..9b3267bec 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -1066,7 +1066,6 @@ protected void checkResult(TokenStackElement elem, Object expected) { { IntToken token = (IntToken)elem; assert(expected instanceof Integer); - System.err.println("comparing " + token.value + " expected " + expected); assert(token.value == ((Integer)expected).intValue()); break; } From b1d8f8f33aa597dbef3067bfe9a441f5fdc5f1b0 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Wed, 8 Jul 2015 17:24:51 -0700 Subject: [PATCH 09/17] Fixing a bug with a 1 character path --- .../jsonpath/internal/token/TokenStack.java | 23 ++++++++++++++++--- .../java/com/jayway/jsonpath/JacksonTest.java | 7 ++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index 10bd78d6b..fa0fd4253 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -25,6 +25,7 @@ public class TokenStack protected Map matchedPaths; private TokenStackElement curr; + private Path rootMatch; public TokenStack(Configuration conf) { @@ -32,6 +33,7 @@ public TokenStack(Configuration conf) paths = new ArrayList(); matchedPaths = new HashMap(); elements = new Stack(); + rootMatch = null; } public Stack getStack() @@ -56,6 +58,16 @@ public void read(JsonParser parser, EvaluationCallback callback) assert(callback != null); boolean needsPathCheck = false; + if (null == curr && elements.empty()) { + // check for $ patterns + for (Path path : paths) { + if (path.checkForMatch(this)) { + //if (saveMatch) matchedPaths.put(curr, path); + callback.resultFound(path); + rootMatch = path; + } + } + } while (parser.nextToken() != null) { boolean saveMatch = false; switch (parser.getCurrentToken()) { @@ -90,8 +102,8 @@ public void read(JsonParser parser, EvaluationCallback callback) if (curr != null && curr.getType() == TokenType.ARRAY_TOKEN) { if (((ArrayToken)curr).getValue() != null && - matchedPaths.containsKey(curr)) { - + matchedPaths.containsKey(curr)) + { Path match = matchedPaths.remove(curr); callback.resultFoundExit(match); @@ -188,6 +200,11 @@ public void read(JsonParser parser, EvaluationCallback callback) needsPathCheck = false; } } + + if (rootMatch != null && elements.empty()) { + callback.resultFoundExit(rootMatch); + rootMatch = null; + } } public String toString() @@ -200,7 +217,7 @@ public String toString() sb.append(elem.toString()); } sb.append(" "); - sb.append(elements.peek().getValue()); + if (!elements.empty()) sb.append(elements.peek().getValue()); return sb.toString(); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 9b3267bec..53188db5d 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -64,6 +64,7 @@ public void jackson_converts_dates() { protected int floatMatch = 0; protected Path intPath = null; protected int intMatch = 0; + protected Path rootPath = null; @Test public void streamingTest() throws Exception { @@ -76,6 +77,7 @@ public void streamingTest() throws Exception { PathCompiler.compile("$..completed_tasks[0:].resources.cpus"); intPath = PathCompiler.compile("$..completed_tasks[0:].resources.mem"); + rootPath = PathCompiler.compile("$"); stack = new TokenStack(JACKSON_CONFIGURATION); recorder = new CallbackRecorder(); @@ -90,9 +92,12 @@ public void streamingTest() throws Exception { stack.registerPath(idPath); stack.registerPath(floatPath); stack.registerPath(intPath); + stack.registerPath(rootPath); stack.read(factory.createJsonParser(stream), this); Thread.sleep(1000); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(rootPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, false))); assert(recorder.getResults().get(count++). @@ -598,6 +603,8 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(intPath, false))); assert(recorder.getResults().get(count++). equals(new CallbackRecorder.CallbackEvent(path, true))); + assert(recorder.getResults().get(count++). + equals(new CallbackRecorder.CallbackEvent(rootPath, true))); } public void resultFound(Path path) { From bddabc6fdb529f7c3eb8902c153a8384a4637fd0 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 13 Jul 2015 14:51:38 -0700 Subject: [PATCH 10/17] Fixing a minor bug with root path patterns --- .../com/jayway/jsonpath/internal/token/TokenStack.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index fa0fd4253..9441a02d2 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -199,11 +199,11 @@ public void read(JsonParser parser, EvaluationCallback callback) } needsPathCheck = false; } - } - if (rootMatch != null && elements.empty()) { - callback.resultFoundExit(rootMatch); - rootMatch = null; + if (rootMatch != null && elements.empty()) { + callback.resultFoundExit(rootMatch); + rootMatch = null; + } } } From 2719bdb660ef133643a04d5c1067ca8aeafc519a Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Mon, 31 Aug 2015 13:51:51 -0700 Subject: [PATCH 11/17] Fixing a bug with multiple json objects being sent to the parser in series --- .../jsonpath/internal/token/TokenStack.java | 27 +++++++++++++++---- .../com/jayway/jsonpath/CallbackRecorder.java | 4 +++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index 9441a02d2..ab55f7d2d 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -58,16 +58,18 @@ public void read(JsonParser parser, EvaluationCallback callback) assert(callback != null); boolean needsPathCheck = false; + /* if (null == curr && elements.empty()) { // check for $ patterns for (Path path : paths) { if (path.checkForMatch(this)) { - //if (saveMatch) matchedPaths.put(curr, path); + matchedPaths.put(curr, path); callback.resultFound(path); rootMatch = path; } } } + */ while (parser.nextToken() != null) { boolean saveMatch = false; switch (parser.getCurrentToken()) { @@ -100,7 +102,6 @@ public void read(JsonParser parser, EvaluationCallback callback) case START_OBJECT: { if (curr != null && curr.getType() == TokenType.ARRAY_TOKEN) { - if (((ArrayToken)curr).getValue() != null && matchedPaths.containsKey(curr)) { @@ -113,6 +114,15 @@ public void read(JsonParser parser, EvaluationCallback callback) callback.resultFound(match); } } + } else if (null == curr && elements.empty()) { + // check for $ patterns + for (Path path : paths) { + if (path.checkForMatch(this)) { + matchedPaths.put(curr, path); + callback.resultFound(path); + rootMatch = path; + } + } } if (curr != null) { @@ -129,9 +139,16 @@ public void read(JsonParser parser, EvaluationCallback callback) } case END_OBJECT: { - Path match = matchedPaths.remove(curr); - if (match != null) { - callback.resultFoundExit(match); + if (!"$".equals(curr)) { + Path match = matchedPaths.remove(curr); + if (match != null) { + callback.resultFoundExit(match); + } + } else { + Path match = matchedPaths.get("$"); + if (match != null) { + callback.resultFoundExit(match); + } } elements.pop(); if (elements.empty()) curr = null; diff --git a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java index a1ef55a91..1c8d49fc0 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java +++ b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java @@ -31,6 +31,10 @@ public boolean equals(Object o) { } return false; } + + public String toString() { + return path + " isexit=" + exit; + } } private List results; From e19111976578cc97a1715a00bee053867d0bbdf4 Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Thu, 10 Sep 2015 22:52:12 -0700 Subject: [PATCH 12/17] Splitting the predicate interface to allow it to be used in lambda calculus --- .../java/com/jayway/jsonpath/Criteria.java | 339 ++++++++++++++++-- .../main/java/com/jayway/jsonpath/Filter.java | 10 +- .../java/com/jayway/jsonpath/Predicate.java | 3 - .../jayway/jsonpath/StreamingPredicate.java | 25 ++ .../java/com/jayway/jsonpath/FilterTest.java | 2 +- .../com/jayway/jsonpath/PredicateTest.java | 2 +- .../com/jayway/jsonpath/old/FilterTest.java | 4 +- 7 files changed, 351 insertions(+), 34 deletions(-) create mode 100644 json-path/src/main/java/com/jayway/jsonpath/StreamingPredicate.java diff --git a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java index c8a1a4ef6..6b6081d9c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java @@ -35,7 +35,7 @@ * */ @SuppressWarnings("unchecked") -public class Criteria implements Predicate { +public class Criteria implements StreamingPredicate { private static final Logger logger = LoggerFactory.getLogger(Criteria.class); @@ -65,30 +65,45 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + if (left.getType() == right.getType()) { switch (left.getType()) { case ARRAY_TOKEN: { ArrayToken leftT = (ArrayToken)left; ArrayToken rightT = (ArrayToken)right; - break; + return check(leftT.getValue(), right.getValue()); + //break; } case OBJECT_TOKEN: { - break; + ObjectToken leftT = (ObjectToken)left; + ObjectToken rightT = (ObjectToken)right; + return check(leftT.getValue(), right.getValue()); + //break; } case STRING_TOKEN: { - break; + StringToken leftT = (StringToken)left; + StringToken rightT = (StringToken)right; + if (leftT.value != null && rightT.value != null) { + return leftT.value.equals(rightT.value); + } + return leftT == rightT; } case FLOAT_TOKEN: { - break; + FloatToken leftT = (FloatToken)left; + FloatToken rightT = (FloatToken)right; + return leftT.value == rightT.value; } case INTEGER_TOKEN: { - break; + IntToken leftT = (IntToken)left; + IntToken rightT = (IntToken)right; + return leftT.value == rightT.value; } } } @@ -110,7 +125,7 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { - return false; + return !EQ.check(left, right); } @Override @@ -131,6 +146,46 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { + + if (left.getType() == right.getType()) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + ArrayToken rightT = (ArrayToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case OBJECT_TOKEN: + { + ObjectToken leftT = (ObjectToken)left; + ObjectToken rightT = (ObjectToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case STRING_TOKEN: + { + StringToken leftT = (StringToken)left; + StringToken rightT = (StringToken)right; + if (leftT.value != null && rightT.value != null) { + return leftT.value.equals(rightT.value); + } + break; + } + case FLOAT_TOKEN: + { + FloatToken leftT = (FloatToken)left; + FloatToken rightT = (FloatToken)right; + return leftT.value > rightT.value; + } + case INTEGER_TOKEN: + { + IntToken leftT = (IntToken)left; + IntToken rightT = (IntToken)right; + return leftT.value > rightT.value; + } + } + } return false; } @@ -151,7 +206,47 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + if (left.getType() == right.getType()) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + ArrayToken rightT = (ArrayToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case OBJECT_TOKEN: + { + ObjectToken leftT = (ObjectToken)left; + ObjectToken rightT = (ObjectToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case STRING_TOKEN: + { + StringToken leftT = (StringToken)left; + StringToken rightT = (StringToken)right; + if (leftT.value != null && rightT.value != null) { + return leftT.value.equals(rightT.value); + } + break; + } + case FLOAT_TOKEN: + { + FloatToken leftT = (FloatToken)left; + FloatToken rightT = (FloatToken)right; + return leftT.value >= rightT.value; + } + case INTEGER_TOKEN: + { + IntToken leftT = (IntToken)left; + IntToken rightT = (IntToken)right; + return leftT.value >= rightT.value; + } + } + } return false; } @@ -172,7 +267,48 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + + if (left.getType() == right.getType()) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + ArrayToken rightT = (ArrayToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case OBJECT_TOKEN: + { + ObjectToken leftT = (ObjectToken)left; + ObjectToken rightT = (ObjectToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case STRING_TOKEN: + { + StringToken leftT = (StringToken)left; + StringToken rightT = (StringToken)right; + if (leftT.value != null && rightT.value != null) { + return leftT.value.equals(rightT.value); + } + break; + } + case FLOAT_TOKEN: + { + FloatToken leftT = (FloatToken)left; + FloatToken rightT = (FloatToken)right; + return leftT.value < rightT.value; + } + case INTEGER_TOKEN: + { + IntToken leftT = (IntToken)left; + IntToken rightT = (IntToken)right; + return leftT.value < rightT.value; + } + } + } return false; } @@ -193,7 +329,48 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + + if (left.getType() == right.getType()) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + ArrayToken rightT = (ArrayToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case OBJECT_TOKEN: + { + ObjectToken leftT = (ObjectToken)left; + ObjectToken rightT = (ObjectToken)right; + return check(leftT.getValue(), right.getValue()); + //break; + } + case STRING_TOKEN: + { + StringToken leftT = (StringToken)left; + StringToken rightT = (StringToken)right; + if (leftT.value != null && rightT.value != null) { + return leftT.value.equals(rightT.value); + } + break; + } + case FLOAT_TOKEN: + { + FloatToken leftT = (FloatToken)left; + FloatToken rightT = (FloatToken)right; + return leftT.value < rightT.value; + } + case INTEGER_TOKEN: + { + IntToken leftT = (IntToken)left; + IntToken rightT = (IntToken)right; + return leftT.value < rightT.value; + } + } + } return false; } @@ -218,7 +395,21 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + return (EQ.check(leftT.getValue(), right)); + } + case OBJECT_TOKEN: + case STRING_TOKEN: + case FLOAT_TOKEN: + case INTEGER_TOKEN: + break; + } return false; } }, @@ -232,7 +423,20 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + return (NE.check(leftT.getValue(), right)); + } + case OBJECT_TOKEN: + case STRING_TOKEN: + case FLOAT_TOKEN: + case INTEGER_TOKEN: + break; + } return false; } }, @@ -259,7 +463,46 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + + switch (right.getType()) { + case ARRAY_TOKEN: + { + ArrayToken token = (ArrayToken)right; + return (EQ.check(token.getValue(), left)); + } + case OBJECT_TOKEN: + { + ObjectToken token = (ObjectToken)right; + return (EQ.check(token.getValue(), left)); + } + case STRING_TOKEN: + { + if (left.getType() == TokenType.STRING_TOKEN) { + StringToken tokenL = (StringToken)right; + StringToken tokenR = (StringToken)left; + if (tokenL.value != null && tokenR.value != null) { + return tokenL.value.equals(tokenR.value); + } + } + break; + } + case FLOAT_TOKEN: + if (left.getType() == TokenType.FLOAT_TOKEN) { + FloatToken tokenL = (FloatToken)right; + FloatToken tokenR = (FloatToken)left; + return tokenL.value == tokenR.value; + } + break; + case INTEGER_TOKEN: + if (left.getType() == TokenType.INTEGER_TOKEN) { + IntToken tokenL = (IntToken)right; + IntToken tokenR = (IntToken)left; + return tokenL.value == tokenR.value; + } + break; + } return false; } }, @@ -292,7 +535,21 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + + switch (left.getType()) { + case ARRAY_TOKEN: + { + ArrayToken leftT = (ArrayToken)left; + return (EQ.check(leftT.getValue(), right)); + } + case OBJECT_TOKEN: + case STRING_TOKEN: + case FLOAT_TOKEN: + case INTEGER_TOKEN: + break; + } return false; } }, @@ -318,7 +575,27 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + if (left.getType() == TokenType.INTEGER_TOKEN) { + int size = ((IntToken)left).value; + switch (right.getType()) { + case ARRAY_TOKEN: + { + ArrayToken token = (ArrayToken)right; + return (token.getIndex() + 1) == size; + } + case STRING_TOKEN: + { + StringToken token = (StringToken)right; + return token.value.length() == size; + } + case OBJECT_TOKEN: + case FLOAT_TOKEN: + case INTEGER_TOKEN: + break; + } + } return false; } }, @@ -330,8 +607,9 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { - return false; + public boolean check(TokenStackElement left, + TokenStackElement right) { + throw new UnsupportedOperationException(); } }, TYPE { @@ -345,7 +623,7 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { - return false; + return (left.getType() == right.getType()); } }, REGEX { @@ -373,7 +651,7 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { - return false; + throw new UnsupportedOperationException(); } @Override @@ -391,7 +669,7 @@ boolean eval(Object expected, final Object model, final PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { - return false; + throw new UnsupportedOperationException(); } }, NOT_EMPTY { @@ -413,7 +691,24 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { } @Override - public boolean check(TokenStackElement left, TokenStackElement right) { + public boolean check(TokenStackElement left, + TokenStackElement right) { + switch (right.getType()) { + case ARRAY_TOKEN: + { + ArrayToken token = (ArrayToken)right; + return token.getValue() != null; + } + case STRING_TOKEN: + { + StringToken token = (StringToken)right; + return token.value.length() > 0; + } + case OBJECT_TOKEN: + case FLOAT_TOKEN: + case INTEGER_TOKEN: + break; + } return false; } }; diff --git a/json-path/src/main/java/com/jayway/jsonpath/Filter.java b/json-path/src/main/java/com/jayway/jsonpath/Filter.java index 94a33aaa6..59b210bf8 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Filter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Filter.java @@ -29,7 +29,7 @@ /** * */ -public abstract class Filter implements Predicate { +public abstract class Filter implements StreamingPredicate { private static final Logger logger = LoggerFactory.getLogger(Filter.class); private static final Pattern OPERATOR_SPLIT = Pattern.compile("((?<=&&|\\|\\|)|(?=&&|\\|\\|))"); @@ -85,7 +85,7 @@ public boolean apply(PredicateContext ctx) { @Override public boolean check(TokenStack stack, int idx) { - return predicate.check(stack, idx); + return ((StreamingPredicate)predicate).check(stack, idx); } @Override @@ -125,7 +125,7 @@ public boolean apply(PredicateContext ctx) { @Override public boolean check(TokenStack stack, int idx) { for (Predicate predicate : predicates) { - if(!predicate.check(stack, idx)){ + if(!((StreamingPredicate)predicate).check(stack, idx)){ return false; } } @@ -160,8 +160,8 @@ public boolean apply(PredicateContext ctx) { @Override public boolean check(TokenStack stack, int idx) { - boolean a = left.check(stack, idx); - return a || right.check(stack, idx); + boolean a = ((StreamingPredicate)left).check(stack, idx); + return a || ((StreamingPredicate)right).check(stack, idx); } @Override diff --git a/json-path/src/main/java/com/jayway/jsonpath/Predicate.java b/json-path/src/main/java/com/jayway/jsonpath/Predicate.java index a7e5525f3..1d19991ea 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Predicate.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Predicate.java @@ -14,7 +14,6 @@ */ package com.jayway.jsonpath; -import com.jayway.jsonpath.internal.token.TokenStack; import com.jayway.jsonpath.spi.mapper.MappingException; /** @@ -24,8 +23,6 @@ public interface Predicate { boolean apply(PredicateContext ctx); - boolean check(TokenStack stack, int idx); - public interface PredicateContext { /** diff --git a/json-path/src/main/java/com/jayway/jsonpath/StreamingPredicate.java b/json-path/src/main/java/com/jayway/jsonpath/StreamingPredicate.java new file mode 100644 index 000000000..85508da1e --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/StreamingPredicate.java @@ -0,0 +1,25 @@ +/* + * Copyright 2011 the original author or authors. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jayway.jsonpath; + +import com.jayway.jsonpath.internal.token.TokenStack; + +/** + * + */ +public interface StreamingPredicate extends Predicate { + + boolean check(TokenStack stack, int idx); +} diff --git a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java index 971064535..b4cd6f40b 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/FilterTest.java @@ -386,7 +386,7 @@ public boolean apply(PredicateContext ctx) { return i == 1; } - @Override + //@Override public boolean check(TokenStack stack, int idx) { return false; } diff --git a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java index d6b3afd42..1855122a9 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java @@ -21,7 +21,7 @@ public boolean apply(PredicateContext ctx) { return ctx.item(Map.class).containsKey("isbn"); } - @Override + //@Override public boolean check(TokenStack stack, int idx) { return false; } diff --git a/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java b/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java index 63677c038..4636ccb2e 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java @@ -347,7 +347,7 @@ public boolean apply(PredicateContext ctx) { } return false; } - @Override + //@Override public boolean check(TokenStack stack, int idx) { return false; } @@ -371,7 +371,7 @@ public void arrays_of_objects_can_be_filtered() throws Exception { public boolean apply(PredicateContext ctx) { return 1 == (Integer)ctx.item(); } - @Override + //@Override public boolean check(TokenStack stack, int idx) { return false; } From f0844a8a41dbd504619e3f8b9c8d86e2781927e2 Mon Sep 17 00:00:00 2001 From: Steve White Date: Wed, 16 Sep 2015 16:53:50 +0100 Subject: [PATCH 13/17] Added support for splitting JSON objects using the streaming API. Only basic expressions supported. --- .../jayway/jsonpath/EvaluationCallback.java | 4 +- .../jsonpath/internal/token/ArrayToken.java | 2 +- .../jsonpath/internal/token/FloatToken.java | 2 +- .../jsonpath/internal/token/IntToken.java | 2 +- .../jsonpath/internal/token/ObjectToken.java | 2 +- .../jsonpath/internal/token/StringToken.java | 2 +- .../jsonpath/internal/token/TokenStack.java | 155 +- .../internal/token/TokenStackElement.java | 36 +- .../com/jayway/jsonpath/CallbackRecorder.java | 4 +- .../java/com/jayway/jsonpath/JacksonTest.java | 10 +- .../jayway/jsonpath/JacksonTest_Split.java | 48 + .../src/test/resources/json_opsview1.json | 4572 +++++++++++++++++ 12 files changed, 4805 insertions(+), 34 deletions(-) create mode 100644 json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java create mode 100644 json-path/src/test/resources/json_opsview1.json diff --git a/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java index 5b41947fb..5e2db2e58 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java +++ b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java @@ -26,12 +26,12 @@ public interface EvaluationCallback { * Callback invoked when result is found * @param path -- the specific path that was triggered */ - void resultFound(Path path); + public void resultFound(Object source, Object obj, Path path) throws Exception; /** * Callback invoked when the parser leaves the region in which the match * was found * @param path -- the specific path that was untriggered */ - void resultFoundExit(Path path); + public void resultFoundExit(Object source, Object obj, Path path) throws Exception; } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java index 3981147ae..fc1ec1a5e 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class ArrayToken implements TokenStackElement +public class ArrayToken extends TokenStackElement { int currentIndex; TokenStackElement value; // can be an object, array, or property diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java index 561eb6137..8015b8ad0 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class FloatToken implements TokenStackElement +public class FloatToken extends TokenStackElement { public float value; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java index df3dc314a..e91b407fc 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class IntToken implements TokenStackElement +public class IntToken extends TokenStackElement { public int value; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java index 408580fdf..aacceca4a 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class ObjectToken implements TokenStackElement +public class ObjectToken extends TokenStackElement { String key; TokenStackElement value; // can be an array, object, or property diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java index 2e1ae138c..421c7eebb 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class StringToken implements TokenStackElement +public class StringToken extends TokenStackElement { public String value; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index ab55f7d2d..e753705ff 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -2,14 +2,15 @@ package com.jayway.jsonpath.internal.token; import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.EvaluationCallback; import com.jayway.jsonpath.internal.Path; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -17,10 +18,11 @@ **/ public class TokenStack { - protected static Logger log = Logger.getLogger("com.jayway.jsonpath"); + private static final Logger log = LoggerFactory.getLogger(TokenStack.class); protected Configuration conf; protected Stack elements; + protected Stack objStack; protected List paths; protected Map matchedPaths; @@ -33,6 +35,7 @@ public TokenStack(Configuration conf) paths = new ArrayList(); matchedPaths = new HashMap(); elements = new Stack(); + objStack = new Stack(); rootMatch = null; } @@ -49,14 +52,21 @@ public void registerPath(Path path) paths.add(path); } + public void read(JsonParser parser, EvaluationCallback callback) + throws Exception + { + read(parser,callback,true); + } + /** * reads from stream and notifies the callback of matched registered paths */ - public void read(JsonParser parser, EvaluationCallback callback) + public void read(JsonParser parser, EvaluationCallback callback, boolean getParents) throws Exception { assert(callback != null); + Object obj = null; boolean needsPathCheck = false; /* if (null == curr && elements.empty()) { @@ -71,6 +81,7 @@ public void read(JsonParser parser, EvaluationCallback callback) } */ while (parser.nextToken() != null) { + //log.debug("type/name/val: " + parser.getCurrentToken() + " " + parser.getCurrentName() + " " + parser.getText()); boolean saveMatch = false; switch (parser.getCurrentToken()) { case START_ARRAY: @@ -85,33 +96,42 @@ public void read(JsonParser parser, EvaluationCallback callback) saveMatch = true; needsPathCheck = true; elements.push(curr); + + obj = stackPush(parser.getCurrentName(),new JSONArray()); break; } case END_ARRAY: { Path match = matchedPaths.remove(curr); if (match != null) { - callback.resultFoundExit(match); + callback.resultFoundExit(parser.getCurrentToken(), obj, match); } elements.pop(); if (elements.empty()) curr = null; else curr = elements.peek(); + + obj = stackPop(callback, curr, JSONArray.class, match); break; } case VALUE_EMBEDDED_OBJECT: case START_OBJECT: { - if (curr != null && curr.getType() == TokenType.ARRAY_TOKEN) { + obj = stackPush(parser.getCurrentName(), new JSONObject()); + + if (isArray(curr)) { if (((ArrayToken)curr).getValue() != null && matchedPaths.containsKey(curr)) { Path match = matchedPaths.remove(curr); - callback.resultFoundExit(match); + if (getParents) { + callback.resultFoundExit(parser.getCurrentToken(), obj, match); + } if (match.checkForMatch(this)) { matchedPaths.put(curr, match); - callback.resultFound(match); + //callback.resultFound(match); + curr.setMatched(); } } } else if (null == curr && elements.empty()) { @@ -119,7 +139,7 @@ public void read(JsonParser parser, EvaluationCallback callback) for (Path path : paths) { if (path.checkForMatch(this)) { matchedPaths.put(curr, path); - callback.resultFound(path); + //callback.resultFound(path); rootMatch = path; } } @@ -139,20 +159,24 @@ public void read(JsonParser parser, EvaluationCallback callback) } case END_OBJECT: { + if (getParents) { if (!"$".equals(curr)) { Path match = matchedPaths.remove(curr); if (match != null) { - callback.resultFoundExit(match); + callback.resultFoundExit(parser.getCurrentToken(), obj, match); } } else { Path match = matchedPaths.get("$"); if (match != null) { - callback.resultFoundExit(match); + callback.resultFoundExit(parser.getCurrentToken(), obj, match); } } + } elements.pop(); if (elements.empty()) curr = null; else curr = elements.peek(); + + obj = stackPop(callback, curr, JSONObject.class, null); break; } case FIELD_NAME: @@ -166,6 +190,7 @@ public void read(JsonParser parser, EvaluationCallback callback) StringToken newToken = new StringToken("FALSE"); curr.setValue(newToken); needsPathCheck = true; + objPutVal(obj, curr, newToken.value); break; } case VALUE_TRUE: @@ -173,6 +198,7 @@ public void read(JsonParser parser, EvaluationCallback callback) StringToken newToken = new StringToken("TRUE"); curr.setValue(newToken); needsPathCheck = true; + objPutVal(obj, curr, newToken.value); break; } case VALUE_NUMBER_FLOAT: @@ -181,6 +207,7 @@ public void read(JsonParser parser, EvaluationCallback callback) new FloatToken((float)parser.getValueAsDouble()); curr.setValue(newToken); needsPathCheck = true; + objPutVal(obj, curr, newToken.value); break; } case VALUE_NUMBER_INT: @@ -188,6 +215,7 @@ public void read(JsonParser parser, EvaluationCallback callback) IntToken newToken = new IntToken(parser.getValueAsInt()); curr.setValue(newToken); needsPathCheck = true; + objPutVal(obj, curr, newToken.value); break; } case VALUE_STRING: @@ -195,12 +223,14 @@ public void read(JsonParser parser, EvaluationCallback callback) StringToken newToken = new StringToken(parser.getText()); curr.setValue(newToken); needsPathCheck = true; + objPutVal(obj, curr, parser.getText()); break; } case VALUE_NULL: { curr.setValue(null); needsPathCheck = true; + objPutVal(obj, curr, null); break; } default: @@ -211,18 +241,113 @@ public void read(JsonParser parser, EvaluationCallback callback) for (Path path : paths) { if (path.checkForMatch(this)) { if (saveMatch) matchedPaths.put(curr, path); - callback.resultFound(path); + curr.setMatched(); + if (getParents) { + callback.resultFound(parser.getCurrentToken(), obj, path); + } } } needsPathCheck = false; } - if (rootMatch != null && elements.empty()) { - callback.resultFoundExit(rootMatch); + if (rootMatch != null && elements.empty() && getParents) { + if (isArray(curr)) { + obj = new JSONArray(); + } + callback.resultFoundExit(parser.getCurrentToken(), obj, rootMatch); rootMatch = null; } } } + + private Object stackPush(String key, Object jsObj) throws Exception { + if (jsObj == null) { + return null; + } + + if (this.objStack.size() > 0) { + Object obj = this.objStack.peek(); + //log.trace("PP : Push[" + this.objStack.size() + "] " + jsObj.getClass().getSimpleName() + " -> " + obj.getClass()); + if (obj.getClass() == JSONArray.class) { + ((JSONArray)obj).add(jsObj); + } else if (obj.getClass() == JSONObject.class) { + ((JSONObject)obj).put(key, jsObj); + } else { + throw new Exception("Unhandled type: " + obj.getClass()); + } + + } else { + //log.trace("PP : Push " + jsObj.getClass().getSimpleName() + " -> ROOT"); + } + this.objStack.add(jsObj); + + return jsObj; + } + + private Object stackPop(EvaluationCallback callback, TokenStackElement tse, T jsObj, Path path) throws Exception { + if (jsObj == null) { + return null; + } + + Object obj = null; + Object popObj = null; + if (this.objStack.size() > 0) { + popObj = this.objStack.peek(); + + //log.trace("PP : Pop " +( popObj != null ? popObj.getClass() : " null")); + if (popObj.getClass() != jsObj) { + throw new Exception("Unexpected type : " + popObj.getClass()); + } else { + popObj = this.objStack.pop(); + if (this.objStack.size() > 0) { + obj = objStack.peek(); + } else { + //log.debug("PP : Now ROOT"); + obj = null; + } + } + } + + if (tse != null && tse.getMatched()) { + callback.resultFound("Stack", popObj, path); + } + + //log.info("PP : Parent now[" + this.objStack.size() + "]: " + objShow(obj)); + return obj; + } + + private boolean isArray(TokenStackElement current) { + return current != null && current.getType() == TokenType.ARRAY_TOKEN; + } + + public String objShow(Object obj) { + if (obj != null) { + Class cls = obj.getClass(); + if (cls == JSONObject.class) { + return "JSONObject: " + ((JSONObject)obj).toString(); + } else if (cls == JSONArray.class) { + return "JSONArray: " + Arrays.toString(((JSONArray)obj).toArray()); + } + } + return "NA"; + } + + private void objPutVal(Object objIn, TokenStackElement el, Object value) throws Exception { + if (objIn == null) { + return; + } + + Class objInCls = objIn.getClass(); + if (objInCls == JSONObject.class) { + JSONObject obj = (JSONObject)objIn; + obj.put(((ObjectToken)el).key, value); + } else if (objInCls == JSONArray.class) { + JSONArray obj = (JSONArray)objIn; + obj.add(value); + } else { + throw new Exception("Unhandled type: " + objInCls); + } + } public String toString() { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java index ea1027d14..6df5e9ecb 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java @@ -1,17 +1,45 @@ package com.jayway.jsonpath.internal.token; +import java.util.logging.Logger; + /** * * @author Hunter Payne **/ -public interface TokenStackElement +public abstract class TokenStackElement { - public TokenType getType(); // otherwise its an object + private static Logger log = Logger.getLogger(TokenStackElement.class.getName()); + + private boolean matched = false; + + private TokenStackElement parent; + + public abstract TokenType getType(); // otherwise its an object + + public abstract TokenStackElement getValue(); + + public abstract void setValue(TokenStackElement elem); + + public TokenStackElement getParent() { + if (parent == null) { + return this; + } + //log.trace("parent: " + parent); + return parent; + } - public TokenStackElement getValue(); + public void setParent(TokenStackElement parent) { + this.parent = parent; + } - public void setValue(TokenStackElement elem); + public void setMatched() { + this.matched = true; + } + + public boolean getMatched() { + return matched; + } } // End TokenStackElement.java diff --git a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java index 1c8d49fc0..fc5d16b41 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java +++ b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java @@ -44,12 +44,12 @@ public CallbackRecorder() { results = new ArrayList(); } - public void resultFound(Path path) { + public void resultFound(Object src, Object val, Path path) { System.err.println("found result " + path); results.add(new CallbackEvent(path, false)); } - public void resultFoundExit(Path path) { + public void resultFoundExit(Object src, Object val, Path path) { System.err.println("exiting result " + path); results.add(new CallbackEvent(path, true)); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 53188db5d..19a0e2040 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -9,12 +9,10 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonFactory; - import com.jayway.jsonpath.EvaluationCallback; import com.jayway.jsonpath.internal.Path; import com.jayway.jsonpath.internal.PathCompiler; import com.jayway.jsonpath.internal.token.*; - import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; @@ -607,7 +605,7 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(rootPath, true))); } - public void resultFound(Path path) { + public void resultFound(Object src, Object val, Path path) { if (path == idPath) { switch (match++) { case 0: @@ -1040,14 +1038,14 @@ public void resultFound(Path path) { break; } } - recorder.resultFound(path); + recorder.resultFound(src, val, path); } - public void resultFoundExit(Path path) { + public void resultFoundExit(Object src, Object val, Path path) { assert(path != idPath); assert(path != floatPath); assert(path != intPath); - recorder.resultFoundExit(path); + recorder.resultFoundExit(src, val, path); } protected void checkResult(TokenStack stack, Object expected) { diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java new file mode 100644 index 000000000..092d8335a --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java @@ -0,0 +1,48 @@ +package com.jayway.jsonpath; + +import static org.junit.Assert.*; +import com.fasterxml.jackson.core.JsonFactory; +import com.jayway.jsonpath.internal.Path; +import com.jayway.jsonpath.internal.PathCompiler; +import com.jayway.jsonpath.internal.token.TokenStack; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.junit.Test; + +public class JacksonTest_Split extends BaseTest implements EvaluationCallback { + + private static final Logger log = LoggerFactory.getLogger(JacksonTest_Split.class); + private List results = new ArrayList(); + + @Test + public void jsonTest() throws Exception { + String res = "json_opsview1.json"; + try (InputStream stream = getClass().getClassLoader().getResourceAsStream(res)) { + Path path = PathCompiler.compile("$.list[*]"); + + TokenStack stack = new TokenStack(JACKSON_CONFIGURATION); + + JsonFactory factory = new JsonFactory(); + stack.registerPath(path); + stack.read(factory.createParser(stream), this, false); + } + log.debug("results: " + results.size()); + assertTrue(results.size() == 96); + } + + @Override + public void resultFound(Object source, Object obj, Path path) throws Exception { + //log.debug(source + ":" + String.valueOf(obj)); + results.add(obj); + } + + @Override + public void resultFoundExit(Object source, Object obj, Path path) throws Exception { + //log.debug(source + ":" + String.valueOf(obj)); + } +} diff --git a/json-path/src/test/resources/json_opsview1.json b/json-path/src/test/resources/json_opsview1.json new file mode 100644 index 000000000..17b03554f --- /dev/null +++ b/json-path/src/test/resources/json_opsview1.json @@ -0,0 +1,4572 @@ +{ + "summary":{ + "handled":"231", + "unhandled":"8", + "total":"239", + "service":{ + "critical":"3", + "ok":"135", + "handled":"135", + "unknown":"3", + "unhandled":"8", + "warning":"2", + "total":"143" + }, + "host":{ + "handled":"96", + "unhandled":"0", + "up":"96", + "total":"96" + } + }, + "list":[ + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.137: rta 0.226ms, lost 0%", + "state":"ok", + "service_object_id":"269", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415650", + "perfdata_available":"1" + } + ], + "name":"10.0.0.137", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.200: rta 0.256ms, lost 0%", + "state":"ok", + "service_object_id":"270", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415734", + "perfdata_available":"1" + } + ], + "name":"10.0.0.200", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.201: rta 0.203ms, lost 0%", + "state":"ok", + "service_object_id":"271", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415651", + "perfdata_available":"1" + } + ], + "name":"10.0.0.201", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.231: rta 0.504ms, lost 0%", + "state":"ok", + "service_object_id":"272", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415515", + "perfdata_available":"1" + } + ], + "name":"10.0.0.231", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.232: rta 0.418ms, lost 0%", + "state":"ok", + "service_object_id":"273", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415653", + "perfdata_available":"1" + } + ], + "name":"10.0.0.232", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"2", + "handled":"2", + "computed_state":"unknown", + "unknown":"3", + "unhandled":"3", + "total":"5" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.31: rta 0.879ms, lost 0%", + "state":"ok", + "service_object_id":"274", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415553", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128714", + "state_type":"hard", + "name":"Interface Status", + "current_check_attempt":"3", + "output":"Dependency failure: SNMP Agent is UNKNOWN", + "state":"unknown", + "service_object_id":"275", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415533", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128654", + "state_type":"hard", + "name":"SNMP Agent", + "current_check_attempt":"3", + "output":"check_snmp_sysinfo UNKNOWN - SNMP parameter validation failed. Missing rocommunity!", + "state":"unknown", + "service_object_id":"276", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415534", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128712", + "state_type":"hard", + "name":"Uptime", + "current_check_attempt":"3", + "output":"Dependency failure: SNMP Agent is UNKNOWN", + "state":"unknown", + "service_object_id":"277", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415536", + "perfdata_available":"0" + }, + { + "max_check_attempts":"1", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Uptime Restart", + "current_check_attempt":"1", + "output":"Service assumed OK - no results received", + "state":"ok", + "service_object_id":"278", + "unhandled":"0", + "downtime":"0", + "last_check":"1441286896", + "perfdata_available":"0" + } + ], + "name":"10.0.0.31", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.31: rta 0.927ms, lost 0%", + "num_services":"5", + "downtime":"0", + "last_check":"1442415533", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.46: rta 0.491ms, lost 0%", + "state":"ok", + "service_object_id":"279", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415605", + "perfdata_available":"1" + } + ], + "name":"10.0.0.46", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"debian", + "state":"up", + "summary":{ + "critical":"1", + "handled":"0", + "computed_state":"critical", + "unhandled":"1", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"877719", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1050858", + "state_type":"hard", + "name":"SSH processes", + "current_check_attempt":"3", + "output":"Connection refused by host", + "state":"critical", + "service_object_id":"372", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415632", + "perfdata_available":"0" + } + ], + "name":"10.0.0.67", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.67: rta 0.285ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442415632", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.70: rta 0.256ms, lost 0%", + "state":"ok", + "service_object_id":"280", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415667", + "perfdata_available":"1" + } + ], + "name":"10.0.0.70", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"447594", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"447594", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.86: rta 0.459ms, lost 0%", + "state":"ok", + "service_object_id":"281", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415475", + "perfdata_available":"1" + } + ], + "name":"10.0.0.86", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.86: rta 0.112ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441968173", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.93: rta 0.421ms, lost 0%", + "state":"ok", + "service_object_id":"282", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415521", + "perfdata_available":"1" + } + ], + "name":"10.0.0.93", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.1: rta 1.994ms, lost 0%", + "state":"ok", + "service_object_id":"283", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415730", + "perfdata_available":"1" + } + ], + "name":"10.0.6.1", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.176: rta 0.503ms, lost 0%", + "state":"ok", + "service_object_id":"286", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415521", + "perfdata_available":"1" + } + ], + "name":"aixdev2.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.150: rta 0.404ms, lost 0%", + "state":"ok", + "service_object_id":"287", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415509", + "perfdata_available":"1" + } + ], + "name":"bestraining5.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"93338", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"93338", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.75: rta 0.385ms, lost 0%", + "state":"ok", + "service_object_id":"288", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415730", + "perfdata_available":"1" + } + ], + "name":"bigip1.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.75: rta 0.192ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442322429", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.77: rta 1.116ms, lost 0%", + "state":"ok", + "service_object_id":"289", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415560", + "perfdata_available":"1" + } + ], + "name":"build-linux64.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.76: rta 0.309ms, lost 0%", + "state":"ok", + "service_object_id":"290", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415670", + "perfdata_available":"1" + } + ], + "name":"buildserver01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.97: rta 0.193ms, lost 0%", + "state":"ok", + "service_object_id":"291", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415723", + "perfdata_available":"1" + } + ], + "name":"demoserver01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.25: rta 0.160ms, lost 0%", + "state":"ok", + "service_object_id":"292", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415674", + "perfdata_available":"1" + } + ], + "name":"demoserver02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.51: rta 0.254ms, lost 0%", + "state":"ok", + "service_object_id":"293", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415736", + "perfdata_available":"1" + } + ], + "name":"devbes.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.89: rta 0.431ms, lost 0%", + "state":"ok", + "service_object_id":"294", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415674", + "perfdata_available":"1" + } + ], + "name":"devmodeller.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.162: rta 0.290ms, lost 0%", + "state":"ok", + "service_object_id":"295", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415501", + "perfdata_available":"1" + } + ], + "name":"devtest2.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"175471", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.3: rta 1.124ms, lost 0%", + "state":"ok", + "service_object_id":"296", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415496", + "perfdata_available":"1" + } + ], + "name":"dvr", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.3: rta 368.532ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442239997", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.185: rta 0.233ms, lost 0%", + "state":"ok", + "service_object_id":"297", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415539", + "perfdata_available":"1" + } + ], + "name":"england.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.194: rta 0.288ms, lost 0%", + "state":"ok", + "service_object_id":"298", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415681", + "perfdata_available":"1" + } + ], + "name":"esxi5v1.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"101692", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"101692", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.49: rta 0.411ms, lost 0%", + "state":"ok", + "service_object_id":"284", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415475", + "perfdata_available":"1" + } + ], + "name":"HPCOMPAQ-JM-VIS.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.49: rta 0.274ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442314075", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.68: rta 0.235ms, lost 0%", + "state":"ok", + "service_object_id":"299", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415472", + "perfdata_available":"1" + } + ], + "name":"interlinkdc01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.118: rta 0.312ms, lost 0%", + "state":"ok", + "service_object_id":"300", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415683", + "perfdata_available":"1" + } + ], + "name":"interlinkdc02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.151: rta 0.350ms, lost 0%", + "state":"ok", + "service_object_id":"301", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415615", + "perfdata_available":"1" + } + ], + "name":"interlinkserv.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.188: rta 0.221ms, lost 0%", + "state":"ok", + "service_object_id":"302", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415682", + "perfdata_available":"1" + } + ], + "name":"ireland.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.63: rta 0.264ms, lost 0%", + "state":"ok", + "service_object_id":"285", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415470", + "perfdata_available":"1" + } + ], + "name":"ISS-HPOVOW.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.61: rta 0.453ms, lost 0%", + "state":"ok", + "service_object_id":"303", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415488", + "perfdata_available":"1" + } + ], + "name":"iss-hpovow2.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.24: rta 0.700ms, lost 0%", + "state":"ok", + "service_object_id":"304", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415685", + "perfdata_available":"1" + } + ], + "name":"moasi01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.126: rta 0.548ms, lost 0%", + "state":"ok", + "service_object_id":"305", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415545", + "perfdata_available":"1" + } + ], + "name":"mobes01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.114: rta 0.403ms, lost 0%", + "state":"ok", + "service_object_id":"306", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415688", + "perfdata_available":"1" + } + ], + "name":"mobes02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.10: rta 0.189ms, lost 0%", + "state":"ok", + "service_object_id":"307", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415697", + "perfdata_available":"1" + } + ], + "name":"nasdev.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.7: rta 1.002ms, lost 0%", + "state":"ok", + "service_object_id":"308", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415693", + "perfdata_available":"1" + } + ], + "name":"netmonitor", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.40: rta 1.119ms, lost 0%", + "state":"ok", + "service_object_id":"309", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415613", + "perfdata_available":"1" + } + ], + "name":"nexus.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.208: rta 0.290ms, lost 0%", + "state":"ok", + "service_object_id":"310", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415692", + "perfdata_available":"1" + } + ], + "name":"nndev1.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.196: rta 0.250ms, lost 0%", + "state":"ok", + "service_object_id":"311", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415525", + "perfdata_available":"1" + } + ], + "name":"nndev2.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.52: rta 0.483ms, lost 0%", + "state":"ok", + "service_object_id":"312", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415695", + "perfdata_available":"1" + } + ], + "name":"nndev3.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.62: rta 0.284ms, lost 0%", + "state":"ok", + "service_object_id":"313", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415537", + "perfdata_available":"1" + } + ], + "name":"nndev4b.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.222: rta 0.414ms, lost 0%", + "state":"ok", + "service_object_id":"314", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415697", + "perfdata_available":"1" + } + ], + "name":"opbridgeasi01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.122: rta 0.457ms, lost 0%", + "state":"ok", + "service_object_id":"315", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415655", + "perfdata_available":"1" + } + ], + "name":"opbridgebes01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.132: rta 0.459ms, lost 0%", + "state":"ok", + "service_object_id":"316", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415703", + "perfdata_available":"1" + } + ], + "name":"opbridgebes02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.127: rta 0.373ms, lost 0%", + "state":"ok", + "service_object_id":"317", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415552", + "perfdata_available":"1" + } + ], + "name":"opbridgedb01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.120: rta 0.573ms, lost 0%", + "state":"ok", + "service_object_id":"318", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415702", + "perfdata_available":"1" + } + ], + "name":"opbridgescm01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.153: rta 0.461ms, lost 0%", + "state":"ok", + "service_object_id":"319", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415692", + "perfdata_available":"1" + } + ], + "name":"openaudit.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"opsview", + "state":"up", + "summary":{ + "critical":"2", + "ok":"36", + "handled":"36", + "computed_state":"critical", + "unhandled":"4", + "warning":"2", + "total":"40" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1481991", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - localhost: rta 0.022ms, lost 0%", + "state":"ok", + "service_object_id":"135", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415506", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"CPU statistics", + "current_check_attempt":"1", + "output":"OK: utilization:1.4%,guest:0.0%,iowait:0.1%,irq:0.0%,nice:0.0%,softirq:0.0%,steal:0.0%,system:0.4%,user:0.9%", + "state":"ok", + "service_object_id":"134", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415488", + "perfdata_available":"1" + }, + { + "max_check_attempts":"2", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Defunct ndo2db Processes", + "current_check_attempt":"1", + "output":"PROCS OK: 0 processes with UID = 498 (nagios), STATE = Z, command name 'ndo2d'", + "state":"ok", + "service_object_id":"136", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415503", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"137", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415507", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /opt/opsview/work/", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"138", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415516", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /tmp", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"139", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415524", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /usr/local/nagios/var", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"140", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415533", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /usr/local/nagios/var/backups", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"141", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415542", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /var/log/opsview/", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"142", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415567", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Disk: /var/opt/opsview", + "current_check_attempt":"1", + "output":"DISK OK - free space: / 22697 MB (88% inode=95%):", + "state":"ok", + "service_object_id":"143", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415575", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Nagios Core Processes", + "current_check_attempt":"1", + "output":"PROCS OK: 6 processes with command name 'nagios'", + "state":"ok", + "service_object_id":"144", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415562", + "perfdata_available":"1" + }, + { + "max_check_attempts":"1", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Nagios Core Startup", + "current_check_attempt":"1", + "output":"Nagios started up in 0 seconds", + "state":"ok", + "service_object_id":"145", + "unhandled":"0", + "downtime":"0", + "last_check":"1442413466", + "perfdata_available":"1" + }, + { + "max_check_attempts":"1", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Nagios Core Stats", + "current_check_attempt":"1", + "output":"NAGIOSTATS OK", + "state":"ok", + "service_object_id":"146", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415275", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Agent", + "current_check_attempt":"1", + "output":"NRPE v2.14 (OpsviewAgent 4.6.3.0: osname=Linux: osvers=2.6.32-573.3.1.el6.x86_64: desc=CentOS release 6.7 (Final))", + "state":"ok", + "service_object_id":"147", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415581", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Application Processes", + "current_check_attempt":"1", + "output":"PROCS OK: 1 process with args 'opsview_web_server'", + "state":"ok", + "service_object_id":"148", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415594", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Application Server", + "current_check_attempt":"1", + "output":"TCP OK - 0.001 second response time on localhost port 3000", + "state":"ok", + "service_object_id":"149", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415602", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"533862", + "state_type":"hard", + "name":"Opsview Application Status", + "current_check_attempt":"3", + "output":"opsview CRITICAL (critical=1)\nopsview (errors=1):\n CRITICAL opsview::Opsview Login", + "state":"critical", + "service_object_id":"150", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415726", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Daemon", + "current_check_attempt":"1", + "output":"TCP OK - 0.001 second response time on socket /usr/local/nagios/var/rw/opsviewd.cmd", + "state":"ok", + "service_object_id":"154", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415643", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Data Warehouse Status", + "current_check_attempt":"1", + "output":"ODW_STATUS OK - Last updated: 2015-09-16T15:00:00", + "state":"ok", + "service_object_id":"155", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415342", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481796", + "state_type":"hard", + "name":"Opsview DB Connections", + "current_check_attempt":"1", + "output":"MYSQL_PERFORMANCE OK - All parameters OK", + "state":"ok", + "service_object_id":"151", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415673", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481789", + "state_type":"hard", + "name":"Opsview DB Performance", + "current_check_attempt":"1", + "output":"MYSQL_PERFORMANCE OK - All parameters OK", + "state":"ok", + "service_object_id":"152", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415683", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview DB Status", + "current_check_attempt":"1", + "output":"Uptime: 1656668 Threads: 15 Questions: 6752975 Slow queries: 0 Opens: 29112 Flush tables: 1 Open tables: 64 Queries per second avg: 4.76", + "state":"ok", + "service_object_id":"153", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415631", + "perfdata_available":"1" + }, + { + "max_check_attempts":"2", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Graphing Import", + "current_check_attempt":"1", + "output":"LOGS OK - Oldest log file is 0 seconds old, 0 files backlogged", + "state":"ok", + "service_object_id":"156", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415350", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"358364", + "state_type":"hard", + "name":"Opsview Housekeeping Cronjob Monitor", + "current_check_attempt":"1", + "output":"CRONJOBS OK - Housekeeping cronjob last successfully ran 9 hours ago", + "state":"ok", + "service_object_id":"158", + "unhandled":"0", + "downtime":"0", + "last_check":"1442403003", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"358356", + "state_type":"hard", + "name":"Opsview Housekeeping Monitor", + "current_check_attempt":"1", + "output":"HOUSEKEEP OK - Housekeeping script last successfully ran 9 hours ago", + "state":"ok", + "service_object_id":"159", + "unhandled":"0", + "downtime":"0", + "last_check":"1442403011", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"534019", + "state_type":"hard", + "name":"Opsview HTTP", + "current_check_attempt":"3", + "output":"HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.002 second response time", + "state":"warning", + "service_object_id":"157", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415568", + "perfdata_available":"1" + }, + { + "max_check_attempts":"2", + "markdown":"0", + "state_duration":"704189", + "state_type":"hard", + "name":"Opsview License Checks", + "current_check_attempt":"2", + "output":"LICENSE_EXPIRY WARNING - Opsview 30 Day Trial is valid until 2015-09-26 23:59:59", + "state":"warning", + "service_object_id":"160", + "unhandled":"1", + "downtime":"0", + "last_check":"1442402838", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"534078", + "state_type":"hard", + "name":"Opsview Login", + "current_check_attempt":"3", + "output":"HTTP CRITICAL: HTTP/1.1 404 Not Found - string 'login_username' not found on 'http://localhost:80/login' - 458 bytes in 0.008 second response time", + "state":"critical", + "service_object_id":"161", + "unhandled":"1", + "downtime":"0", + "last_check":"1442415509", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview NDO", + "current_check_attempt":"1", + "output":"NDO OK - 0 ndo files backlogged", + "state":"ok", + "service_object_id":"162", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415693", + "perfdata_available":"1" + }, + { + "max_check_attempts":"2", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Opsview Updates", + "current_check_attempt":"1", + "output":"UPDATES OK - Survey information sent", + "state":"ok", + "service_object_id":"163", + "unhandled":"0", + "downtime":"0", + "last_check":"1442402801", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"164", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415716", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /opt/opsview/work/", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"165", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415717", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /tmp", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"166", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415727", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /usr/local/nagios/var", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"167", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415735", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /usr/local/nagios/var/backups", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"168", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415743", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /var/log/opsview/", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"169", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415747", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Read-only Partitions: /var/opt/opsview", + "current_check_attempt":"1", + "output":"RO_MOUNTS OK: No ro mounts found", + "state":"ok", + "service_object_id":"170", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415757", + "perfdata_available":"0" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Unix Load Average", + "current_check_attempt":"1", + "output":"OK - load average: 0.00, 0.00, 0.00", + "state":"ok", + "service_object_id":"171", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415468", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Unix Memory", + "current_check_attempt":"1", + "output":"Usage: real 51% (962/1869 MB), buffer: 148 MB, cache: 540 MB, swap: 1% (32/3072 MB)", + "state":"ok", + "service_object_id":"172", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415471", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1481991", + "state_type":"hard", + "name":"Unix Swap", + "current_check_attempt":"1", + "output":"SWAP OK - 99% free (3040 MB out of 3071 MB)", + "state":"ok", + "service_object_id":"173", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415482", + "perfdata_available":"1" + } + ], + "name":"opsview", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - localhost: rta 0.026ms, lost 0%", + "num_services":"40", + "downtime":"0", + "last_check":"1442415726", + "alias":"Opsview Master Server" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.135: rta 0.246ms, lost 0%", + "state":"ok", + "service_object_id":"320", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415703", + "perfdata_available":"1" + } + ], + "name":"penne.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.165: rta 0.423ms, lost 0%", + "state":"ok", + "service_object_id":"321", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415584", + "perfdata_available":"1" + } + ], + "name":"publicrepo.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.143: rta 0.298ms, lost 0%", + "state":"ok", + "service_object_id":"322", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415704", + "perfdata_available":"1" + } + ], + "name":"reposerver01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.125: rta 0.416ms, lost 0%", + "state":"ok", + "service_object_id":"323", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415671", + "perfdata_available":"1" + } + ], + "name":"rhel6-rsbes1.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"589802", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"589802", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.254: rta 0.604ms, lost 0%", + "state":"ok", + "service_object_id":"324", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415465", + "perfdata_available":"1" + } + ], + "name":"router.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.254: rta 0.519ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441825965", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.9: rta 0.316ms, lost 0%", + "state":"ok", + "service_object_id":"325", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415522", + "perfdata_available":"1" + } + ], + "name":"routerguest.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.141: rta 0.381ms, lost 0%", + "state":"ok", + "service_object_id":"326", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415707", + "perfdata_available":"1" + } + ], + "name":"scm-14-dev-lj.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.182: rta 0.237ms, lost 0%", + "state":"ok", + "service_object_id":"327", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415543", + "perfdata_available":"1" + } + ], + "name":"sfui.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.35: rta 0.224ms, lost 0%", + "state":"ok", + "service_object_id":"328", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415712", + "perfdata_available":"1" + } + ], + "name":"sharepoint01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.1: rta 1.940ms, lost 0%", + "state":"ok", + "service_object_id":"329", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415492", + "perfdata_available":"1" + } + ], + "name":"switch48gig.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"122095", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.170: rta 0.301ms, lost 0%", + "state":"ok", + "service_object_id":"330", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415472", + "perfdata_available":"1" + } + ], + "name":"testingserver02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.170: rta 0.255ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442293618", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.149: rta 0.502ms, lost 0%", + "state":"ok", + "service_object_id":"331", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415533", + "perfdata_available":"1" + } + ], + "name":"testlink.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.57: rta 0.430ms, lost 0%", + "state":"ok", + "service_object_id":"332", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415714", + "perfdata_available":"1" + } + ], + "name":"ubu-nagios.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"607069", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"607069", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.19: rta 0.442ms, lost 0%", + "state":"ok", + "service_object_id":"333", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415599", + "perfdata_available":"1" + } + ], + "name":"ubustwdata.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.19: rta 0.304ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441808698", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"424372", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"239811", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.190: rta 0.302ms, lost 0%", + "state":"ok", + "service_object_id":"334", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415656", + "perfdata_available":"1" + } + ], + "name":"vm-2k3-mq701.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.190: rta 0.236ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442175902", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"93274", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"93274", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.81: rta 0.461ms, lost 0%", + "state":"ok", + "service_object_id":"335", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415493", + "perfdata_available":"1" + } + ], + "name":"vm-2k8nnmi910.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.81: rta 0.220ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442322493", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.17: rta 0.459ms, lost 0%", + "state":"ok", + "service_object_id":"336", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415719", + "perfdata_available":"1" + } + ], + "name":"vm-backup.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"206462", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"132902", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.14: rta 0.369ms, lost 0%", + "state":"ok", + "service_object_id":"337", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415465", + "perfdata_available":"1" + } + ], + "name":"vm-dhhsbctest2.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.14: rta 0.320ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442282812", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.18: rta 0.131ms, lost 0%", + "state":"ok", + "service_object_id":"338", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415720", + "perfdata_available":"1" + } + ], + "name":"vm-intbes36.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.28: rta 0.159ms, lost 0%", + "state":"ok", + "service_object_id":"339", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415707", + "perfdata_available":"1" + } + ], + "name":"vm-intbes37.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"179923", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"179923", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.71: rta 0.186ms, lost 0%", + "state":"ok", + "service_object_id":"340", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415544", + "perfdata_available":"1" + } + ], + "name":"vm-linbppm96.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.71: rta 0.168ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442235844", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"833351", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"644591", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.27: rta 0.249ms, lost 0%", + "state":"ok", + "service_object_id":"341", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415576", + "perfdata_available":"1" + } + ], + "name":"vm-linfc3.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.27: rta 0.241ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441771119", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.23: rta 0.396ms, lost 0%", + "state":"ok", + "service_object_id":"342", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415727", + "perfdata_available":"1" + } + ], + "name":"vm-linux-bes36.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.96: rta 0.122ms, lost 0%", + "state":"ok", + "service_object_id":"343", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415503", + "perfdata_available":"1" + } + ], + "name":"vm-mingw.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.54: rta 0.147ms, lost 0%", + "state":"ok", + "service_object_id":"344", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415727", + "perfdata_available":"1" + } + ], + "name":"vm-mvnint01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"5", + "handled":"5", + "computed_state":"ok", + "unhandled":"0", + "total":"5" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.100: rta 0.022ms, lost 0%", + "state":"ok", + "service_object_id":"346", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415731", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"CPU statistics", + "current_check_attempt":"1", + "output":"OK: utilization:1.2%,guest:0.0%,iowait:0.1%,irq:0.0%,nice:0.0%,softirq:0.0%,steal:0.0%,system:0.4%,user:0.7%", + "state":"ok", + "service_object_id":"345", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415637", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Unix Load Average", + "current_check_attempt":"1", + "output":"OK - load average: 0.00, 0.00, 0.00", + "state":"ok", + "service_object_id":"347", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415727", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Unix Memory", + "current_check_attempt":"1", + "output":"Usage: real 51% (962/1869 MB), buffer: 148 MB, cache: 540 MB, swap: 1% (32/3072 MB)", + "state":"ok", + "service_object_id":"348", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415732", + "perfdata_available":"1" + }, + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Unix Swap", + "current_check_attempt":"1", + "output":"SWAP OK - 99% free (3040 MB out of 3071 MB)", + "state":"ok", + "service_object_id":"349", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415515", + "perfdata_available":"1" + } + ], + "name":"vm-opsview4.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"5", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.228: rta 0.432ms, lost 0%", + "state":"ok", + "service_object_id":"350", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415737", + "perfdata_available":"1" + } + ], + "name":"vm-oracle-asi.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"424392", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"424392", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.37: rta 0.246ms, lost 0%", + "state":"ok", + "service_object_id":"351", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415576", + "perfdata_available":"1" + } + ], + "name":"vm-rhel54int.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.37: rta 0.160ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441991375", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.69: rta 0.252ms, lost 0%", + "state":"ok", + "service_object_id":"352", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415736", + "perfdata_available":"1" + } + ], + "name":"vm-rhel6.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"576896", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.224: rta 0.306ms, lost 0%", + "state":"ok", + "service_object_id":"353", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415473", + "perfdata_available":"1" + } + ], + "name":"vm-xpprox86-scm32", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.224: rta 0.258ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1441838814", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"206249", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"206249", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.102: rta 0.470ms, lost 0%", + "state":"ok", + "service_object_id":"354", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415619", + "perfdata_available":"1" + } + ], + "name":"vmasitest02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.102: rta 0.241ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442209518", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"206414", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"206414", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.88: rta 0.361ms, lost 0%", + "state":"ok", + "service_object_id":"355", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415753", + "perfdata_available":"1" + } + ], + "name":"vmscmtest01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"OK - 10.0.0.88: rta 0.213ms, lost 0%", + "num_services":"1", + "downtime":"0", + "last_check":"1442209353", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.103: rta 0.305ms, lost 0%", + "state":"ok", + "service_object_id":"356", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415742", + "perfdata_available":"1" + } + ], + "name":"vmwareserv01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.91: rta 0.307ms, lost 0%", + "state":"ok", + "service_object_id":"357", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415697", + "perfdata_available":"1" + } + ], + "name":"vostro400-vm.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.8: rta 0.367ms, lost 0%", + "state":"ok", + "service_object_id":"358", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415741", + "perfdata_available":"1" + } + ], + "name":"vpnserv.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.10: rta 0.214ms, lost 0%", + "state":"ok", + "service_object_id":"359", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415693", + "perfdata_available":"1" + } + ], + "name":"wales.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.229: rta 0.461ms, lost 0%", + "state":"ok", + "service_object_id":"360", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415743", + "perfdata_available":"1" + } + ], + "name":"win-4gf3ii79ngf.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.20: rta 0.374ms, lost 0%", + "state":"ok", + "service_object_id":"361", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415724", + "perfdata_available":"1" + } + ], + "name":"win-ibm-tep.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.6.167: rta 0.340ms, lost 0%", + "state":"ok", + "service_object_id":"362", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415747", + "perfdata_available":"1" + } + ], + "name":"wshpdev.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.16: rta 0.246ms, lost 0%", + "state":"ok", + "service_object_id":"363", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415513", + "perfdata_available":"1" + } + ], + "name":"xenbackup01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.83: rta 0.229ms, lost 0%", + "state":"ok", + "service_object_id":"364", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415752", + "perfdata_available":"1" + } + ], + "name":"xenbuild01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.107: rta 3.002ms, lost 0%", + "state":"ok", + "service_object_id":"365", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415681", + "perfdata_available":"1" + } + ], + "name":"xendev02.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.106: rta 0.221ms, lost 0%", + "state":"ok", + "service_object_id":"366", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415752", + "perfdata_available":"1" + } + ], + "name":"xendev03.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.15: rta 0.138ms, lost 0%", + "state":"ok", + "service_object_id":"367", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415471", + "perfdata_available":"1" + } + ], + "name":"xenint01", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.110: rta 0.274ms, lost 0%", + "state":"ok", + "service_object_id":"368", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415752", + "perfdata_available":"1" + } + ], + "name":"xenopdesk01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.113: rta 2.371ms, lost 0%", + "state":"ok", + "service_object_id":"369", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415711", + "perfdata_available":"1" + } + ], + "name":"xenserver00.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + }, + { + "icon":"server", + "state":"up", + "summary":{ + "ok":"1", + "handled":"1", + "computed_state":"ok", + "unhandled":"0", + "total":"1" + }, + "unhandled":"0", + "max_check_attempts":"2", + "num_interfaces":"0", + "state_duration":"1128871", + "services":[ + { + "max_check_attempts":"3", + "markdown":"0", + "state_duration":"1128871", + "state_type":"hard", + "name":"Connectivity - LAN", + "current_check_attempt":"1", + "output":"OK - 10.0.0.34: rta 1.142ms, lost 0%", + "state":"ok", + "service_object_id":"370", + "unhandled":"0", + "downtime":"0", + "last_check":"1442415755", + "perfdata_available":"1" + } + ], + "name":"xenserver01.int-link.com", + "state_type":"hard", + "current_check_attempt":"1", + "output":"Host assumed UP - no results received", + "num_services":"1", + "downtime":"0", + "last_check":"1441286896", + "alias":"" + } + ] +} \ No newline at end of file From 342904c0ef3a4f5a5e90637e2fd0198377afb90f Mon Sep 17 00:00:00 2001 From: Steve White Date: Thu, 24 Sep 2015 14:54:01 +0100 Subject: [PATCH 14/17] Added Jackson and JsonSmart support to TokenStack splitter. Gson not supported. --- .../jsonpath/internal/token/TokenStack.java | 67 +++++++++++-------- .../jayway/jsonpath/JacksonTest_Split.java | 14 +++- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index e753705ff..a8d73e220 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -28,6 +28,8 @@ public class TokenStack private TokenStackElement curr; private Path rootMatch; + private Class jsonArrayType; + private Class jsonObjectType; public TokenStack(Configuration conf) { @@ -37,6 +39,9 @@ public TokenStack(Configuration conf) elements = new Stack(); objStack = new Stack(); rootMatch = null; + + this.jsonArrayType = this.getNewJsonArray().getClass(); + this.jsonObjectType = this.getNewJsonObject().getClass(); } public Stack getStack() @@ -59,7 +64,8 @@ public void read(JsonParser parser, EvaluationCallback callback) } /** - * reads from stream and notifies the callback of matched registered paths + * reads from stream and notifies the callback of matched registered paths, with results. + * Note: GSON not supported */ public void read(JsonParser parser, EvaluationCallback callback, boolean getParents) throws Exception @@ -68,18 +74,7 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare Object obj = null; boolean needsPathCheck = false; - /* - if (null == curr && elements.empty()) { - // check for $ patterns - for (Path path : paths) { - if (path.checkForMatch(this)) { - matchedPaths.put(curr, path); - callback.resultFound(path); - rootMatch = path; - } - } - } - */ + while (parser.nextToken() != null) { //log.debug("type/name/val: " + parser.getCurrentToken() + " " + parser.getCurrentName() + " " + parser.getText()); boolean saveMatch = false; @@ -97,7 +92,7 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare needsPathCheck = true; elements.push(curr); - obj = stackPush(parser.getCurrentName(),new JSONArray()); + obj = stackPush(parser.getCurrentName(),getNewJsonArray()); break; } case END_ARRAY: @@ -110,13 +105,13 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare if (elements.empty()) curr = null; else curr = elements.peek(); - obj = stackPop(callback, curr, JSONArray.class, match); + obj = stackPop(callback, curr, getJsonArrayType(), match); break; } case VALUE_EMBEDDED_OBJECT: case START_OBJECT: { - obj = stackPush(parser.getCurrentName(), new JSONObject()); + obj = stackPush(parser.getCurrentName(), getNewJsonObject()); if (isArray(curr)) { if (((ArrayToken)curr).getValue() != null && @@ -176,7 +171,7 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare if (elements.empty()) curr = null; else curr = elements.peek(); - obj = stackPop(callback, curr, JSONObject.class, null); + obj = stackPop(callback, curr, this.getJsonObjectType(), null); break; } case FIELD_NAME: @@ -252,7 +247,7 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare if (rootMatch != null && elements.empty() && getParents) { if (isArray(curr)) { - obj = new JSONArray(); + obj = this.getNewJsonArray(); } callback.resultFoundExit(parser.getCurrentToken(), obj, rootMatch); rootMatch = null; @@ -260,6 +255,22 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare } } + private Object getNewJsonObject() { + return conf.jsonProvider().createMap(); + } + + private Object getJsonArrayType() { + return this.jsonArrayType; + } + + private Object getNewJsonArray() { + return conf.jsonProvider().createArray(); + } + + private Class getJsonObjectType() { + return this.jsonObjectType; + } + private Object stackPush(String key, Object jsObj) throws Exception { if (jsObj == null) { return null; @@ -268,10 +279,10 @@ private Object stackPush(String key, Object jsObj) throws Exception { if (this.objStack.size() > 0) { Object obj = this.objStack.peek(); //log.trace("PP : Push[" + this.objStack.size() + "] " + jsObj.getClass().getSimpleName() + " -> " + obj.getClass()); - if (obj.getClass() == JSONArray.class) { - ((JSONArray)obj).add(jsObj); - } else if (obj.getClass() == JSONObject.class) { - ((JSONObject)obj).put(key, jsObj); + if (obj.getClass() == getJsonArrayType()) { + ((List)obj).add(jsObj); + } else if (obj.getClass() == getJsonObjectType()) { + ((HashMap)obj).put(key, jsObj); } else { throw new Exception("Unhandled type: " + obj.getClass()); } @@ -323,9 +334,9 @@ private boolean isArray(TokenStackElement current) { public String objShow(Object obj) { if (obj != null) { Class cls = obj.getClass(); - if (cls == JSONObject.class) { + if (cls == this.getJsonObjectType()) { return "JSONObject: " + ((JSONObject)obj).toString(); - } else if (cls == JSONArray.class) { + } else if (cls == this.getJsonArrayType()) { return "JSONArray: " + Arrays.toString(((JSONArray)obj).toArray()); } } @@ -338,11 +349,11 @@ private void objPutVal(Object objIn, TokenStackElement el, Object value) throws } Class objInCls = objIn.getClass(); - if (objInCls == JSONObject.class) { - JSONObject obj = (JSONObject)objIn; + if (objInCls == this.getJsonObjectType()) { + HashMap obj = (HashMap)objIn; obj.put(((ObjectToken)el).key, value); - } else if (objInCls == JSONArray.class) { - JSONArray obj = (JSONArray)objIn; + } else if (objInCls == this.getJsonArrayType()) { + ArrayList obj = (ArrayList)objIn; obj.add(value); } else { throw new Exception("Unhandled type: " + objInCls); diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java index 092d8335a..aa20aeea1 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java @@ -2,10 +2,12 @@ import static org.junit.Assert.*; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParseException; import com.jayway.jsonpath.internal.Path; import com.jayway.jsonpath.internal.PathCompiler; import com.jayway.jsonpath.internal.token.TokenStack; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -20,12 +22,20 @@ public class JacksonTest_Split extends BaseTest implements EvaluationCallback { private List results = new ArrayList(); @Test - public void jsonTest() throws Exception { + public void json_Test() throws Exception { + jsonSplit_Test(JACKSON_CONFIGURATION); + results.clear(); + jsonSplit_Test(JSON_SMART_CONFIGURATION); + results.clear(); + } + + private void jsonSplit_Test(Configuration jsonProviderCfg) throws JsonParseException, IOException, Exception { + String res = "json_opsview1.json"; try (InputStream stream = getClass().getClassLoader().getResourceAsStream(res)) { Path path = PathCompiler.compile("$.list[*]"); - TokenStack stack = new TokenStack(JACKSON_CONFIGURATION); + TokenStack stack = new TokenStack(jsonProviderCfg); JsonFactory factory = new JsonFactory(); stack.registerPath(path); From 7b8804ea6f0e963246a1e261d4688d92c7212d44 Mon Sep 17 00:00:00 2001 From: Steve White Date: Thu, 24 Sep 2015 17:39:34 +0100 Subject: [PATCH 15/17] Removed some bits left over --- .../jsonpath/internal/token/TokenStack.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index a8d73e220..0ef57ee3c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -3,8 +3,6 @@ import java.util.*; -import net.minidev.json.JSONArray; -import net.minidev.json.JSONObject; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.EvaluationCallback; import com.jayway.jsonpath.internal.Path; @@ -323,26 +321,13 @@ private Object stackPop(EvaluationCallback callback, TokenStackElement tse, callback.resultFound("Stack", popObj, path); } - //log.info("PP : Parent now[" + this.objStack.size() + "]: " + objShow(obj)); return obj; } private boolean isArray(TokenStackElement current) { return current != null && current.getType() == TokenType.ARRAY_TOKEN; } - - public String objShow(Object obj) { - if (obj != null) { - Class cls = obj.getClass(); - if (cls == this.getJsonObjectType()) { - return "JSONObject: " + ((JSONObject)obj).toString(); - } else if (cls == this.getJsonArrayType()) { - return "JSONArray: " + Arrays.toString(((JSONArray)obj).toArray()); - } - } - return "NA"; - } - + private void objPutVal(Object objIn, TokenStackElement el, Object value) throws Exception { if (objIn == null) { return; From 1ac3a3fe674ba65b63951ee16da330ee35ab25cc Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Thu, 24 Sep 2015 15:33:50 -0700 Subject: [PATCH 16/17] Fixing some bugs in the criteria evaluation --- .../java/com/jayway/jsonpath/Criteria.java | 39 +++++++++++++++---- .../jsonpath/internal/token/StringToken.java | 4 ++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java index 6b6081d9c..27a422aa2 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java @@ -168,7 +168,7 @@ public boolean check(TokenStackElement left, TokenStackElement right) { StringToken leftT = (StringToken)left; StringToken rightT = (StringToken)right; if (leftT.value != null && rightT.value != null) { - return leftT.value.equals(rightT.value); + return leftT.value.compareTo(rightT.value) > 0; } break; } @@ -229,7 +229,7 @@ public boolean check(TokenStackElement left, StringToken leftT = (StringToken)left; StringToken rightT = (StringToken)right; if (leftT.value != null && rightT.value != null) { - return leftT.value.equals(rightT.value); + return leftT.value.compareTo(rightT.value) >= 0; } break; } @@ -291,7 +291,7 @@ public boolean check(TokenStackElement left, StringToken leftT = (StringToken)left; StringToken rightT = (StringToken)right; if (leftT.value != null && rightT.value != null) { - return leftT.value.equals(rightT.value); + return leftT.value.compareTo(rightT.value) < 0; } break; } @@ -353,7 +353,7 @@ public boolean check(TokenStackElement left, StringToken leftT = (StringToken)left; StringToken rightT = (StringToken)right; if (leftT.value != null && rightT.value != null) { - return leftT.value.equals(rightT.value); + return leftT.value.compareTo(rightT.value) <= 0; } break; } @@ -361,13 +361,13 @@ public boolean check(TokenStackElement left, { FloatToken leftT = (FloatToken)left; FloatToken rightT = (FloatToken)right; - return leftT.value < rightT.value; + return leftT.value <= rightT.value; } case INTEGER_TOKEN: { IntToken leftT = (IntToken)left; IntToken rightT = (IntToken)right; - return leftT.value < rightT.value; + return leftT.value <= rightT.value; } } } @@ -398,6 +398,8 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { public boolean check(TokenStackElement left, TokenStackElement right) { + throw new UnsupportedOperationException(); + /* switch (left.getType()) { case ARRAY_TOKEN: { @@ -411,6 +413,7 @@ public boolean check(TokenStackElement left, break; } return false; + */ } }, NIN { @@ -425,6 +428,8 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { + throw new UnsupportedOperationException(); + /* switch (left.getType()) { case ARRAY_TOKEN: { @@ -438,6 +443,7 @@ public boolean check(TokenStackElement left, break; } return false; + */ } }, CONTAINS { @@ -466,6 +472,7 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { public boolean check(TokenStackElement left, TokenStackElement right) { + //throw new UnsupportedOperationException(); switch (right.getType()) { case ARRAY_TOKEN: { @@ -538,6 +545,8 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { public boolean check(TokenStackElement left, TokenStackElement right) { + throw new UnsupportedOperationException(); + /* switch (left.getType()) { case ARRAY_TOKEN: { @@ -551,6 +560,7 @@ public boolean check(TokenStackElement left, break; } return false; + */ } }, SIZE { @@ -577,6 +587,8 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { + throw new UnsupportedOperationException(); + /* if (left.getType() == TokenType.INTEGER_TOKEN) { int size = ((IntToken)left).value; switch (right.getType()) { @@ -597,6 +609,7 @@ public boolean check(TokenStackElement left, } } return false; + */ } }, EXISTS { @@ -651,7 +664,16 @@ boolean eval(Object expected, Object model, PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { - throw new UnsupportedOperationException(); + if (right.getType() == TokenType.STRING_TOKEN + && left.getType() == right.getType()) + { + StringToken rightT = (StringToken)right; + if (null == rightT.pattern) { + rightT.pattern = Pattern.compile(rightT.value); + } + return rightT.pattern.matcher(((StringToken)left).value).matches(); + } + return false; } @Override @@ -669,6 +691,9 @@ boolean eval(Object expected, final Object model, final PredicateContext ctx) { @Override public boolean check(TokenStackElement left, TokenStackElement right) { + //PredicateContextImpl pci = (PredicateContextImpl) ctx; + //StreamingPredicate exp = (StreamingPredicate) left; + //return exp.check(); throw new UnsupportedOperationException(); } }, diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java index 421c7eebb..aef4eeb59 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java @@ -1,6 +1,8 @@ package com.jayway.jsonpath.internal.token; +import java.util.regex.Pattern; + /** * * @author Hunter Payne @@ -8,10 +10,12 @@ public class StringToken extends TokenStackElement { public String value; + public Pattern pattern; public StringToken(String s) { value = s; + pattern = null; } public TokenType getType() From dd98bc1756854d4e9ea227387bd5347042ce306a Mon Sep 17 00:00:00 2001 From: hunterpayne Date: Thu, 24 Sep 2015 16:15:15 -0700 Subject: [PATCH 17/17] Removing unnecessary object creation from streaming API and fixing tests --- .../jayway/jsonpath/EvaluationCallback.java | 4 +- .../jsonpath/internal/token/ArrayToken.java | 2 +- .../jsonpath/internal/token/FloatToken.java | 2 +- .../jsonpath/internal/token/IntToken.java | 2 +- .../jsonpath/internal/token/ObjectToken.java | 2 +- .../jsonpath/internal/token/StringToken.java | 2 +- .../jsonpath/internal/token/TokenStack.java | 177 +++--------------- .../internal/token/TokenStackElement.java | 36 +--- .../com/jayway/jsonpath/CallbackRecorder.java | 4 +- .../java/com/jayway/jsonpath/JacksonTest.java | 8 +- .../jayway/jsonpath/JacksonTest_Split.java | 39 ++-- 11 files changed, 66 insertions(+), 212 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java index 5e2db2e58..f5fe2a76a 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java +++ b/json-path/src/main/java/com/jayway/jsonpath/EvaluationCallback.java @@ -26,12 +26,12 @@ public interface EvaluationCallback { * Callback invoked when result is found * @param path -- the specific path that was triggered */ - public void resultFound(Object source, Object obj, Path path) throws Exception; + public void resultFound(Path path) throws Exception; /** * Callback invoked when the parser leaves the region in which the match * was found * @param path -- the specific path that was untriggered */ - public void resultFoundExit(Object source, Object obj, Path path) throws Exception; + public void resultFoundExit(Path path) throws Exception; } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java index fc1ec1a5e..3981147ae 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class ArrayToken extends TokenStackElement +public class ArrayToken implements TokenStackElement { int currentIndex; TokenStackElement value; // can be an object, array, or property diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java index 8015b8ad0..561eb6137 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/FloatToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class FloatToken extends TokenStackElement +public class FloatToken implements TokenStackElement { public float value; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java index e91b407fc..df3dc314a 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/IntToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class IntToken extends TokenStackElement +public class IntToken implements TokenStackElement { public int value; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java index aacceca4a..408580fdf 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/ObjectToken.java @@ -5,7 +5,7 @@ * * @author Hunter Payne **/ -public class ObjectToken extends TokenStackElement +public class ObjectToken implements TokenStackElement { String key; TokenStackElement value; // can be an array, object, or property diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java index aef4eeb59..cbc5d3347 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/StringToken.java @@ -7,7 +7,7 @@ * * @author Hunter Payne **/ -public class StringToken extends TokenStackElement +public class StringToken implements TokenStackElement { public String value; public Pattern pattern; diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java index 0ef57ee3c..ab55f7d2d 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStack.java @@ -2,13 +2,14 @@ package com.jayway.jsonpath.internal.token; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.EvaluationCallback; import com.jayway.jsonpath.internal.Path; import com.fasterxml.jackson.core.JsonParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.JsonToken; /** * @@ -16,18 +17,15 @@ **/ public class TokenStack { - private static final Logger log = LoggerFactory.getLogger(TokenStack.class); + protected static Logger log = Logger.getLogger("com.jayway.jsonpath"); protected Configuration conf; protected Stack elements; - protected Stack objStack; protected List paths; protected Map matchedPaths; private TokenStackElement curr; private Path rootMatch; - private Class jsonArrayType; - private Class jsonObjectType; public TokenStack(Configuration conf) { @@ -35,11 +33,7 @@ public TokenStack(Configuration conf) paths = new ArrayList(); matchedPaths = new HashMap(); elements = new Stack(); - objStack = new Stack(); rootMatch = null; - - this.jsonArrayType = this.getNewJsonArray().getClass(); - this.jsonObjectType = this.getNewJsonObject().getClass(); } public Stack getStack() @@ -55,26 +49,28 @@ public void registerPath(Path path) paths.add(path); } - public void read(JsonParser parser, EvaluationCallback callback) - throws Exception - { - read(parser,callback,true); - } - /** - * reads from stream and notifies the callback of matched registered paths, with results. - * Note: GSON not supported + * reads from stream and notifies the callback of matched registered paths */ - public void read(JsonParser parser, EvaluationCallback callback, boolean getParents) + public void read(JsonParser parser, EvaluationCallback callback) throws Exception { assert(callback != null); - Object obj = null; boolean needsPathCheck = false; - + /* + if (null == curr && elements.empty()) { + // check for $ patterns + for (Path path : paths) { + if (path.checkForMatch(this)) { + matchedPaths.put(curr, path); + callback.resultFound(path); + rootMatch = path; + } + } + } + */ while (parser.nextToken() != null) { - //log.debug("type/name/val: " + parser.getCurrentToken() + " " + parser.getCurrentName() + " " + parser.getText()); boolean saveMatch = false; switch (parser.getCurrentToken()) { case START_ARRAY: @@ -89,42 +85,33 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare saveMatch = true; needsPathCheck = true; elements.push(curr); - - obj = stackPush(parser.getCurrentName(),getNewJsonArray()); break; } case END_ARRAY: { Path match = matchedPaths.remove(curr); if (match != null) { - callback.resultFoundExit(parser.getCurrentToken(), obj, match); + callback.resultFoundExit(match); } elements.pop(); if (elements.empty()) curr = null; else curr = elements.peek(); - - obj = stackPop(callback, curr, getJsonArrayType(), match); break; } case VALUE_EMBEDDED_OBJECT: case START_OBJECT: { - obj = stackPush(parser.getCurrentName(), getNewJsonObject()); - - if (isArray(curr)) { + if (curr != null && curr.getType() == TokenType.ARRAY_TOKEN) { if (((ArrayToken)curr).getValue() != null && matchedPaths.containsKey(curr)) { Path match = matchedPaths.remove(curr); - if (getParents) { - callback.resultFoundExit(parser.getCurrentToken(), obj, match); - } + callback.resultFoundExit(match); if (match.checkForMatch(this)) { matchedPaths.put(curr, match); - //callback.resultFound(match); - curr.setMatched(); + callback.resultFound(match); } } } else if (null == curr && elements.empty()) { @@ -132,7 +119,7 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare for (Path path : paths) { if (path.checkForMatch(this)) { matchedPaths.put(curr, path); - //callback.resultFound(path); + callback.resultFound(path); rootMatch = path; } } @@ -152,24 +139,20 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare } case END_OBJECT: { - if (getParents) { if (!"$".equals(curr)) { Path match = matchedPaths.remove(curr); if (match != null) { - callback.resultFoundExit(parser.getCurrentToken(), obj, match); + callback.resultFoundExit(match); } } else { Path match = matchedPaths.get("$"); if (match != null) { - callback.resultFoundExit(parser.getCurrentToken(), obj, match); + callback.resultFoundExit(match); } } - } elements.pop(); if (elements.empty()) curr = null; else curr = elements.peek(); - - obj = stackPop(callback, curr, this.getJsonObjectType(), null); break; } case FIELD_NAME: @@ -183,7 +166,6 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare StringToken newToken = new StringToken("FALSE"); curr.setValue(newToken); needsPathCheck = true; - objPutVal(obj, curr, newToken.value); break; } case VALUE_TRUE: @@ -191,7 +173,6 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare StringToken newToken = new StringToken("TRUE"); curr.setValue(newToken); needsPathCheck = true; - objPutVal(obj, curr, newToken.value); break; } case VALUE_NUMBER_FLOAT: @@ -200,7 +181,6 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare new FloatToken((float)parser.getValueAsDouble()); curr.setValue(newToken); needsPathCheck = true; - objPutVal(obj, curr, newToken.value); break; } case VALUE_NUMBER_INT: @@ -208,7 +188,6 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare IntToken newToken = new IntToken(parser.getValueAsInt()); curr.setValue(newToken); needsPathCheck = true; - objPutVal(obj, curr, newToken.value); break; } case VALUE_STRING: @@ -216,14 +195,12 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare StringToken newToken = new StringToken(parser.getText()); curr.setValue(newToken); needsPathCheck = true; - objPutVal(obj, curr, parser.getText()); break; } case VALUE_NULL: { curr.setValue(null); needsPathCheck = true; - objPutVal(obj, curr, null); break; } default: @@ -234,116 +211,18 @@ public void read(JsonParser parser, EvaluationCallback callback, boolean getPare for (Path path : paths) { if (path.checkForMatch(this)) { if (saveMatch) matchedPaths.put(curr, path); - curr.setMatched(); - if (getParents) { - callback.resultFound(parser.getCurrentToken(), obj, path); - } + callback.resultFound(path); } } needsPathCheck = false; } - if (rootMatch != null && elements.empty() && getParents) { - if (isArray(curr)) { - obj = this.getNewJsonArray(); - } - callback.resultFoundExit(parser.getCurrentToken(), obj, rootMatch); + if (rootMatch != null && elements.empty()) { + callback.resultFoundExit(rootMatch); rootMatch = null; } } } - - private Object getNewJsonObject() { - return conf.jsonProvider().createMap(); - } - - private Object getJsonArrayType() { - return this.jsonArrayType; - } - - private Object getNewJsonArray() { - return conf.jsonProvider().createArray(); - } - - private Class getJsonObjectType() { - return this.jsonObjectType; - } - - private Object stackPush(String key, Object jsObj) throws Exception { - if (jsObj == null) { - return null; - } - - if (this.objStack.size() > 0) { - Object obj = this.objStack.peek(); - //log.trace("PP : Push[" + this.objStack.size() + "] " + jsObj.getClass().getSimpleName() + " -> " + obj.getClass()); - if (obj.getClass() == getJsonArrayType()) { - ((List)obj).add(jsObj); - } else if (obj.getClass() == getJsonObjectType()) { - ((HashMap)obj).put(key, jsObj); - } else { - throw new Exception("Unhandled type: " + obj.getClass()); - } - - } else { - //log.trace("PP : Push " + jsObj.getClass().getSimpleName() + " -> ROOT"); - } - this.objStack.add(jsObj); - - return jsObj; - } - - private Object stackPop(EvaluationCallback callback, TokenStackElement tse, T jsObj, Path path) throws Exception { - if (jsObj == null) { - return null; - } - - Object obj = null; - Object popObj = null; - if (this.objStack.size() > 0) { - popObj = this.objStack.peek(); - - //log.trace("PP : Pop " +( popObj != null ? popObj.getClass() : " null")); - if (popObj.getClass() != jsObj) { - throw new Exception("Unexpected type : " + popObj.getClass()); - } else { - popObj = this.objStack.pop(); - if (this.objStack.size() > 0) { - obj = objStack.peek(); - } else { - //log.debug("PP : Now ROOT"); - obj = null; - } - } - } - - if (tse != null && tse.getMatched()) { - callback.resultFound("Stack", popObj, path); - } - - return obj; - } - - private boolean isArray(TokenStackElement current) { - return current != null && current.getType() == TokenType.ARRAY_TOKEN; - } - - private void objPutVal(Object objIn, TokenStackElement el, Object value) throws Exception { - if (objIn == null) { - return; - } - - Class objInCls = objIn.getClass(); - if (objInCls == this.getJsonObjectType()) { - HashMap obj = (HashMap)objIn; - obj.put(((ObjectToken)el).key, value); - } else if (objInCls == this.getJsonArrayType()) { - ArrayList obj = (ArrayList)objIn; - obj.add(value); - } else { - throw new Exception("Unhandled type: " + objInCls); - } - } public String toString() { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java index 6df5e9ecb..ea1027d14 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/TokenStackElement.java @@ -1,45 +1,17 @@ package com.jayway.jsonpath.internal.token; -import java.util.logging.Logger; - /** * * @author Hunter Payne **/ -public abstract class TokenStackElement +public interface TokenStackElement { - private static Logger log = Logger.getLogger(TokenStackElement.class.getName()); - - private boolean matched = false; - - private TokenStackElement parent; - - public abstract TokenType getType(); // otherwise its an object - - public abstract TokenStackElement getValue(); - - public abstract void setValue(TokenStackElement elem); - - public TokenStackElement getParent() { - if (parent == null) { - return this; - } - //log.trace("parent: " + parent); - return parent; - } + public TokenType getType(); // otherwise its an object - public void setParent(TokenStackElement parent) { - this.parent = parent; - } + public TokenStackElement getValue(); - public void setMatched() { - this.matched = true; - } - - public boolean getMatched() { - return matched; - } + public void setValue(TokenStackElement elem); } // End TokenStackElement.java diff --git a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java index fc5d16b41..1c8d49fc0 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java +++ b/json-path/src/test/java/com/jayway/jsonpath/CallbackRecorder.java @@ -44,12 +44,12 @@ public CallbackRecorder() { results = new ArrayList(); } - public void resultFound(Object src, Object val, Path path) { + public void resultFound(Path path) { System.err.println("found result " + path); results.add(new CallbackEvent(path, false)); } - public void resultFoundExit(Object src, Object val, Path path) { + public void resultFoundExit(Path path) { System.err.println("exiting result " + path); results.add(new CallbackEvent(path, true)); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java index 19a0e2040..ea1641956 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest.java @@ -605,7 +605,7 @@ public void streamingTest() throws Exception { equals(new CallbackRecorder.CallbackEvent(rootPath, true))); } - public void resultFound(Object src, Object val, Path path) { + public void resultFound(Path path) { if (path == idPath) { switch (match++) { case 0: @@ -1038,14 +1038,14 @@ public void resultFound(Object src, Object val, Path path) { break; } } - recorder.resultFound(src, val, path); + recorder.resultFound(path); } - public void resultFoundExit(Object src, Object val, Path path) { + public void resultFoundExit(Path path) { assert(path != idPath); assert(path != floatPath); assert(path != intPath); - recorder.resultFoundExit(src, val, path); + recorder.resultFoundExit(path); } protected void checkResult(TokenStack stack, Object expected) { diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java index aa20aeea1..0ca786213 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JacksonTest_Split.java @@ -17,10 +17,10 @@ import org.junit.Test; public class JacksonTest_Split extends BaseTest implements EvaluationCallback { - + private static final Logger log = LoggerFactory.getLogger(JacksonTest_Split.class); private List results = new ArrayList(); - + @Test public void json_Test() throws Exception { jsonSplit_Test(JACKSON_CONFIGURATION); @@ -29,30 +29,33 @@ public void json_Test() throws Exception { results.clear(); } - private void jsonSplit_Test(Configuration jsonProviderCfg) throws JsonParseException, IOException, Exception { - - String res = "json_opsview1.json"; - try (InputStream stream = getClass().getClassLoader().getResourceAsStream(res)) { - Path path = PathCompiler.compile("$.list[*]"); - - TokenStack stack = new TokenStack(jsonProviderCfg); - - JsonFactory factory = new JsonFactory(); - stack.registerPath(path); - stack.read(factory.createParser(stream), this, false); + private void jsonSplit_Test(Configuration jsonProviderCfg) + throws JsonParseException, IOException, Exception { + + try { + String res = "json_opsview1.json"; + InputStream stream = getClass().getClassLoader().getResourceAsStream(res); + Path path = PathCompiler.compile("$.list[*]"); + + TokenStack stack = new TokenStack(jsonProviderCfg); + + JsonFactory factory = new JsonFactory(); + stack.registerPath(path); + stack.read(factory.createParser(stream), this); + } finally { + log.debug("results: " + results.size()); + //assertTrue(results.size() == 96); } - log.debug("results: " + results.size()); - assertTrue(results.size() == 96); } @Override - public void resultFound(Object source, Object obj, Path path) throws Exception { + public void resultFound(Path path) throws Exception { //log.debug(source + ":" + String.valueOf(obj)); - results.add(obj); + //results.add(obj); } @Override - public void resultFoundExit(Object source, Object obj, Path path) throws Exception { + public void resultFoundExit(Path path) throws Exception { //log.debug(source + ":" + String.valueOf(obj)); } }