DeleteFieldOperation implements EventOperation { @Override public InternalEvent perform(InternalEvent internalEvent) { try { deleteKeyFromEvent(internalEvent); } catch (Exception e) { throw new OperationException("JSON field deletion failed for this reason: " + e.getMessage()); } return internalEvent; } DeleteFieldOperation(String keyField); @Override InternalEvent perform(InternalEvent internalEvent);  }
@Test(expected = OperationException.class) public void testNullField() { InternalEvent ievent = new InternalEvent("foo", null, 1); DeleteFieldOperation operation = new DeleteFieldOperation(null); operation.perform(ievent); }
@Test public void testExistingField() { InternalEvent ievent = new InternalEvent("foo", null, 1); JsonObject actualJsonObject = new JsonObject(); actualJsonObject.addProperty("ex", "exists"); GenericJsonEvent jsonEvent = new GenericJsonEvent(actualJsonObject); ievent.setEventObj(jsonEvent); DeleteFieldOperation operation = new DeleteFieldOperation("ex"); operation.perform(ievent); JsonObject expectedJsonObject = new JsonObject(); assertEquals(expectedJsonObject, actualJsonObject); }
@Test public void testNonExistingField() { InternalEvent ievent = new InternalEvent("foo", null, 1); JsonObject actualJsonObject = new JsonObject(); actualJsonObject.addProperty("different", "exists"); GenericJsonEvent jsonEvent = new GenericJsonEvent(actualJsonObject); ievent.setEventObj(jsonEvent); DeleteFieldOperation operation = new DeleteFieldOperation("ex"); operation.perform(ievent); JsonObject expectedJsonObject = new JsonObject(); expectedJsonObject.addProperty("different", "exists"); assertEquals(expectedJsonObject, actualJsonObject); }