/** * Checks whether lhs is equal to rhs * * @param lhs Lhs expression * @param rhs Rhs expression * @return True if lhs is equal to rhs; * False otherwise */ @Override public boolean matches(JsonNode lhs, JsonNode rhs) { return lhs.equals(rhs); }
/** * Checks whether lhs is not equal to rhs * * @param lhs Lhs expression * @param rhs Rhs expression * @return True if lhs is not equal to rhs; * False otherwise */ @Override public boolean matches(JsonNode lhs, JsonNode rhs) { return !lhs.equals(rhs); } }
/** * Path matcher that checks if the final result * matches the expected result * * @param expectedResult Expected result given by the waiter definition * @param finalResult Final result of the resource got by the execution * of the JmesPath expression given by the waiter * definition * @return True if the final result matches the expected result, * False otherwise */ public static boolean path(JsonNode expectedResult, JsonNode finalResult) { return finalResult.equals(expectedResult); } }
@Override public boolean equals(Comparator<JsonNode> comparator, JsonNode o) { if (!(o instanceof ArrayNode)) { return false; } ArrayNode other = (ArrayNode) o; final int len = _children.size(); if (other.size() != len) { return false; } List<JsonNode> l1 = _children; List<JsonNode> l2 = other._children; for (int i = 0; i < len; ++i) { if (!l1.get(i).equals(comparator, l2.get(i))) { return false; } } return true; }
@Override public boolean equals(Comparator<JsonNode> comparator, JsonNode o) { if (!(o instanceof ObjectNode)) { return false; } ObjectNode other = (ObjectNode) o; Map<String, JsonNode> m1 = _children; Map<String, JsonNode> m2 = other._children; final int len = m1.size(); if (m2.size() != len) { return false; } for (Map.Entry<String, JsonNode> entry : m1.entrySet()) { JsonNode v2 = m2.get(entry.getKey()); if ((v2 == null) || !entry.getValue().equals(comparator, v2)) { return false; } } return true; }
/** * If subject is an array, this function returns true if * one of the elements in the array is equal to the provided search * value. * * @param subject Array * @param search JmesPath expression * @return True array contains search; * False otherwise */ private static BooleanNode doesArrayContain(JsonNode subject, JsonNode search) { Iterator<JsonNode> elements = subject.elements(); while (elements.hasNext()) { if (elements.next().equals(search)) { return BooleanNode.TRUE; } } return BooleanNode.FALSE; }
/** * PathAll matcher that checks if each element of the final * result matches the expected result * * @param expectedResult Expected result given by the waiter definition * @param finalResult Final result of the resource got by the execution * of the JmesPath expression given by the waiter * definition * @return True if all elements of the final result matches * the expected result, False otherwise */ public static boolean pathAll(JsonNode expectedResult, JsonNode finalResult) { if (finalResult.isNull()) { return false; } if (!finalResult.isArray()) { throw new RuntimeException("Expected an array"); } for (JsonNode element : finalResult) { if (!element.equals(expectedResult)) { return false; } } return true; }
/** * PathAny matcher that checks if any element of the final * result matches the expected result * * @param expectedResult Expected result given by the waiter definition * @param finalResult Final result of the resource got by the execution * of the JmesPath expression given by the waiter * definition * @return True if any single element of the final result matches * the expected result, False if none matched */ public static boolean pathAny(JsonNode expectedResult, JsonNode finalResult) { if (finalResult.isNull()) { return false; } if (!finalResult.isArray()) { throw new RuntimeException("Expected an array"); } for (JsonNode element : finalResult) { if (element.equals(expectedResult)) { return true; } } return false; }
/** * Adds a property with the given name <tt>name</tt> and * value <tt>value</tt>. Neither <tt>name</tt> nor <tt>value</tt> can be * <tt>null</tt>. It is illegal to add a property if another with * the same name but different value already exists in this schema. * * @param name The name of the property to add * @param value The value for the property to add */ private void addProp(String name, JsonNode value) { if (reserved.contains(name)) throw new AvroRuntimeException("Can't set reserved property: " + name); if (value == null) throw new AvroRuntimeException("Can't set a property to null: " + name); JsonNode old = props.putIfAbsent(name, value); if (old != null && !old.equals(value)) { throw new AvroRuntimeException("Can't overwrite property: " + name); } }
@Override public ExposedPort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); return ExposedPort.parse(field.getKey()); } else { return null; } } }
private boolean defaultValueEquals(JsonNode thatDefaultValue) { if (defaultValue == null) return thatDefaultValue == null; if (thatDefaultValue == null) return false; if (Double.isNaN(defaultValue.doubleValue())) return Double.isNaN(thatDefaultValue.doubleValue()); return defaultValue.equals(thatDefaultValue); }
public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) { return false; } ObjectNode other = (ObjectNode) o; if (other.size() != size()) { return false; } if (_children != null) { for (Map.Entry<String, JsonNode> en : _children.entrySet()) { String key = en.getKey(); JsonNode value = en.getValue(); JsonNode otherValue = other.get(key); if (otherValue == null || !otherValue.equals(value)) { return false; } } } return true; }
@Override public ExposedPorts deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); if (!field.getValue().equals(NullNode.getInstance())) { exposedPorts.add(ExposedPort.parse(field.getKey())); } } return new ExposedPorts(exposedPorts.toArray(new ExposedPort[0])); } }
@Override public Links deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final List<Link> binds = new ArrayList<Link>(); final ObjectCodec oc = jsonParser.getCodec(); final JsonNode node = oc.readTree(jsonParser); for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) { final JsonNode element = it.next(); if (!element.equals(NullNode.getInstance())) { binds.add(Link.parse(element.asText())); } } return new Links(binds.toArray(new Link[0])); } }
@Override public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Volume> volumes = new ArrayList<Volume>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); if (!field.getValue().equals(NullNode.getInstance())) { String path = field.getKey(); Volume volume = new Volume(path); volumes.add(volume); } } return new Volumes(volumes.toArray(new Volume[0])); } }
private boolean doMatch(final Request request, final MessageContent content) { try { JsonNode requestNode = mapper.readTree(content.toString()); JsonNode resourceNode = mapper.readTree(expected.readFor(of(request)).toString()); return requestNode.equals(resourceNode); } catch (JsonProcessingException jpe) { return false; } catch (IOException e) { throw new MocoException(e); } }
@Override public VolumeBinds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeBind> binds = new ArrayList<VolumeBind>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); JsonNode value = field.getValue(); if (!value.equals(NullNode.getInstance())) { if (!value.isTextual()) { throw deserializationContext.mappingException("Expected path for '" + field.getKey() + "'in host but got '" + value + "'."); } VolumeBind bind = new VolumeBind(value.asText(), field.getKey()); binds.add(bind); } } return new VolumeBinds(binds.toArray(new VolumeBind[binds.size()])); } }
@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
@Override public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeRW> volumesRW = new ArrayList<VolumeRW>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); JsonNode value = field.getValue(); if (!value.equals(NullNode.getInstance())) { if (!value.isBoolean()) { throw deserializationContext.mappingException("Expected access mode for '" + field.getKey() + "' in host but got '" + value + "'."); } VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean())); volumesRW.add(bind); } } return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()])); } }
@Override public int compare(JsonNode o1, JsonNode o2) { if (o1.equals(o2)) { return 0; } if ((o1 instanceof NumericNode) && (o2 instanceof NumericNode)) { double d1 = ((NumericNode) o1).asDouble(); double d2 = ((NumericNode) o2).asDouble(); return Double.compare(d1, d2); } int comp = o1.asText().compareTo(o2.asText()); if (comp == 0) { return Integer.compare(o1.hashCode(), o2.hashCode()); } return comp; } }