@Test public void testFromJson() throws IOException { ObjectNode node = (ObjectNode) JsonUtils.json("{ \"$append\" : { \"path\" : \"rvalue_expression\" } } "); ArrayUpdateExpression expResult = ArrayAddExpression.fromJson(node); ArrayUpdateExpression result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); node = (ObjectNode) JsonUtils.json("{ \"$insert\" : { \"path\" : \"$all\"} } "); expResult = ArrayAddExpression.fromJson(node); result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); node = (ObjectNode) JsonUtils.json("{ \"$foreach\" : { \"path\" : \"$all\" ,\"$update\" : \"$remove\"} } "); expResult = ForEachExpression.fromJson(node); result = ArrayUpdateExpression.fromJson(node); assertEquals(expResult, result); boolean error = false; try { node = (ObjectNode) JsonUtils.json("{ \"$missing\" : { \"path\" : { \"path\" : \"rvalue_expression\" } }}"); result = ArrayUpdateExpression.fromJson(node); } catch (Error e) { error = true; assertEquals(Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()).toString(), e.toString()); } assertTrue("It didn't thrown an expection as it was expected", error); }
public static ArrayUpdateExpression fromJson(ObjectNode node) { if (node.has(UpdateOperator._append.toString()) || node.has(UpdateOperator._insert.toString())) { return ArrayAddExpression.fromJson(node); } else if (node.has(UpdateOperator._foreach.toString())) { return ForEachExpression.fromJson(node); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } }
ArrayUpdateExpression extends PartialUpdateExpression { public static ArrayUpdateExpression fromJson(ObjectNode node) { if (node.has(UpdateOperator._append.toString()) || node.has(UpdateOperator._insert.toString())) { return ArrayAddExpression.fromJson(node); } else if (node.has(UpdateOperator._foreach.toString())) { return ForEachExpression.fromJson(node); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } } }
ArrayUpdateExpression extends PartialUpdateExpression { public static ArrayUpdateExpression fromJson(ObjectNode node) { if (node.has(UpdateOperator._append.toString()) || node.has(UpdateOperator._insert.toString())) { return ArrayAddExpression.fromJson(node); } else if (node.has(UpdateOperator._foreach.toString())) { return ForEachExpression.fromJson(node); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } }  }
ArrayUpdateExpression extends PartialUpdateExpression { public static ArrayUpdateExpression fromJson(ObjectNode node) { if (node.has(UpdateOperator._append.toString()) || node.has(UpdateOperator._insert.toString())) { return ArrayAddExpression.fromJson(node); } else if (node.has(UpdateOperator._foreach.toString())) { return ForEachExpression.fromJson(node); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } }  static ArrayUpdateExpression fromJson(ObjectNode node); }
ArrayUpdateExpression extends PartialUpdateExpression { public static ArrayUpdateExpression fromJson(ObjectNode node) { if (node.has(UpdateOperator._append.toString()) || node.has(UpdateOperator._insert.toString())) { return ArrayAddExpression.fromJson(node); } else if (node.has(UpdateOperator._foreach.toString())) { return ForEachExpression.fromJson(node); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } }  static ArrayUpdateExpression fromJson(ObjectNode node);  }