Record { public boolean match(JsonObject filter) { for (String key : filter.fieldNames()) { boolean match; switch (key) { case "name": match = match(getName(), filter.getString("name")); break; case "registration": match = match(getRegistration(), filter.getString("registration")); break; case "status": match = match(getStatus().name(), filter.getString("status")); break; case "type": match = match(getType(), filter.getString("type")); break; default: match = match(getMetadata().getValue(key), filter.getValue(key)); break; } if (!match) { return false; } } return true; } Record();  Record(JsonObject json);  Record(Record other); JsonObject toJson(); JsonObject getLocation(); Record setLocation(JsonObject location); JsonObject getMetadata(); Record setMetadata(JsonObject metadata); String getName(); Record setName(String name); Status getStatus(); Record setStatus(Status status); Record setRegistration(String reg); String getRegistration(); String getType(); Record setType(String type); boolean match(JsonObject filter); @Override boolean equals(Object o); @Override int hashCode(); static final String ENDPOINT; }
@Test public void testMatch() { Record record = new Record().setName("Name"); assertThat(record.match(new JsonObject().put("name", "Name"))).isTrue(); assertThat(record.match(new JsonObject().put("name", "Name-2"))).isFalse(); record.setStatus(Status.UP); assertThat(record.match(new JsonObject().put("status", "Up"))).isTrue(); assertThat(record.match(new JsonObject().put("status", "Down"))).isFalse(); assertThat(record.match(new JsonObject().put("status", "Up").put("name", "Name"))).isTrue(); assertThat(record.match(new JsonObject().put("status", "Down").put("name", "Name"))).isFalse(); record.setRegistration("the-registration"); assertThat(record.match(new JsonObject().put("registration", "the-registration"))).isTrue(); assertThat(record.match(new JsonObject().put("registration", "wrong"))).isFalse(); record.getMetadata().put("foo", "bar").put("key", 2); assertThat(record.match(new JsonObject().put("foo", "bar"))).isTrue(); assertThat(record.match(new JsonObject().put("foo", "bar2"))).isFalse(); assertThat(record.match(new JsonObject().put("foo", "bar").put("other", "nope"))).isFalse(); assertThat(record.match(new JsonObject().put("foo", "bar").put("other", "*"))).isFalse(); assertThat(record.match(new JsonObject().put("foo", "bar").put("key", 2))).isTrue(); assertThat(record.match(new JsonObject().put("foo", "*").put("key", 2))).isTrue(); }