User user = compassTemplate.get(User.class, -2);
assertNotNull(user);
assertEquals("Matt", user.getFirstName());
compassTemplate.execute(new CompassCallbackWithoutResult() {
@Override
protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException {
CompassHits hits = compassSession.find("Matt");
assertEquals(1, hits.length());
assertEquals("Matt", ((User) hits.data(0)).getFirstName());
assertEquals("Matt", hits.resource(0).getValue("firstName"));
}
});
// test mirroring
user = dao.get(-2L);
user.setFirstName("MattX");
dao.saveUser(user);
// now verify it is reflected in the index
user = compassTemplate.get(User.class, -2);
assertNotNull(user);
assertEquals("MattX", user.getFirstName());
compassTemplate.execute(new CompassCallbackWithoutResult() {
@Override
protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException {
CompassHits hits = compassSession.find("MattX");
assertEquals(1, hits.length());
assertEquals("MattX", ((User) hits.data(0)).getFirstName());