private User createUser1() { User user = new User(); user.setId(1); user.setName("Tom"); user.setSurname("Cat"); user.setGender(User.Gender.MALE); user.setAccountIds(Collections.singletonList(12)); Address address = new Address(); address.setStreet("Dark Alley"); address.setPostCode("1234"); user.setAddresses(Collections.singletonList(address)); return user; }
private User createUser2() { User user = new User(); user.setId(1); user.setName("Adrian"); user.setSurname("Nistor"); user.setGender(User.Gender.MALE); Address address = new Address(); address.setStreet("Old Street"); address.setPostCode("XYZ"); user.setAddresses(Collections.singletonList(address)); return user; }
private byte[] createMarshalledUser(String name, String surname) throws IOException { User user = new User(); user.setId(1); user.setName(name); user.setSurname(surname); user.setGender(User.Gender.MALE); user.setAccountIds(Collections.singleton(12)); Address address = new Address(); address.setStreet("Dark Alley"); address.setPostCode("1234"); user.setAddresses(Collections.singletonList(address)); return ProtobufUtil.toWrappedByteArray( ProtobufMetadataManagerImpl.getSerializationContextInternal(cacheManager), user); }
private void assertUser(User user) { assertEquals(1, user.getId()); assertEquals("Tom", user.getName()); assertEquals("Cat", user.getSurname()); assertEquals(User.Gender.MALE, user.getGender()); assertNotNull(user.getAccountIds()); assertEquals(1, user.getAccountIds().size()); assertEquals(12, user.getAccountIds().get(0).intValue()); assertNotNull(user.getAddresses()); assertEquals(1, user.getAddresses().size()); assertEquals("Dark Alley", user.getAddresses().get(0).getStreet()); assertEquals("1234", user.getAddresses().get(0).getPostCode()); }
public void testIndexingWithWrapper() throws Exception { MarshallerRegistration.registerMarshallers( ProtobufMetadataManagerImpl.getSerializationContext(cacheManager)); // Store some test data: ProtobufValueWrapper wrapper1 = new ProtobufValueWrapper(createMarshalledUser("Adrian", "Nistor")); ProtobufValueWrapper wrapper2 = new ProtobufValueWrapper(createMarshalledUser("John", "Batman")); cache.put(1, wrapper1); // todo how do we index if the key is a byte array? cache.put(2, wrapper2); SearchManager sm = Search.getSearchManager(cache); SearchIntegrator searchFactory = sm.unwrap(SearchIntegrator.class); assertNotNull(searchFactory.getIndexManager(ProtobufValueWrapper.class.getName())); Query luceneQuery = sm.buildQueryBuilderForClass(ProtobufValueWrapper.class) .get() .keyword() .onField("name") .ignoreFieldBridge() .ignoreAnalyzer() .matching("Adrian") .createQuery(); List<ProtobufValueWrapper> list = sm.<ProtobufValueWrapper>getQuery(luceneQuery).list(); assertEquals(1, list.size()); ProtobufValueWrapper pvw = list.get(0); User unwrapped = (User) ProtobufUtil.fromWrappedByteArray( ProtobufMetadataManagerImpl.getSerializationContextInternal(cacheManager), pvw.getBinary()); assertEquals("Adrian", unwrapped.getName()); // an alternative approach ... Query luceneQuery2 = searchFactory .buildQueryBuilder() .forEntity(ProtobufValueWrapper.class) .get() .keyword() .onField("name") .ignoreFieldBridge() .ignoreAnalyzer() .matching("Adrian") .createQuery(); List<EntityInfo> queryEntityInfos = searchFactory .createHSQuery(luceneQuery2, ProtobufValueWrapper.class) .projection("surname") .queryEntityInfos(); assertEquals(1, queryEntityInfos.size()); EntityInfo entityInfo = queryEntityInfos.get(0); assertEquals("Nistor", entityInfo.getProjection()[0]); }