DefaultEntityIndexDocumentPurveyor extends AbstractGenericEntityIndexDocumentPurveyor implements EntityIndexDocumentPurveyor { @Override public Map<String, Object> purveyDocument(Entity entity, Tenant tenant) { try { EntityIndexDocumentPurveyor indexHandler = this.componentManager.getInstance(indexDocumentPurveyorOf(entity.getClass()).getType()); if (indexHandler != null) { return indexHandler.purveyDocument(entity, tenant); } } catch (ComponentLookupException e) { } return super.purveyDocument(entity, tenant); }  @Override Map<String, Object> purveyDocument(Entity entity, Tenant tenant);  }
@Test public void testGetDocumentFromEntityThatHasAClassLevelIndexAnnotation() throws ComponentLookupException { EntityWithClassLevelIndexAnnotation entity = new EntityWithClassLevelIndexAnnotation(UUID.randomUUID(), "my-test-entity"); entity.setMyIndexedField("this is indexed"); entity.setMyNotIndexField("this is NOT indexed"); Map<String, Object> source = this.componentManager.getComponentUnderTest().purveyDocument(entity, tenant); Assert.assertEquals("this is indexed", ((Map<String, Object>) source.get("properties")).get("myIndexedField")); Assert.assertNull(((Map<String, Object>) source.get("properties")).get("id")); }
@Test public void testGetDocumentFromEntityThatHasFieldLevelIndexAnnotation() throws ComponentLookupException { EntityWithFieldLevelIndexAnnotations entity = new EntityWithFieldLevelIndexAnnotations(UUID.randomUUID(), "my-test-entity"); entity.setMyIndexedField("this is indexed"); entity.setMyNotIndexField("this is NOT indexed"); Map<String, Object> source = this.componentManager.getComponentUnderTest().purveyDocument(entity, tenant); Assert.assertEquals("this is indexed", ((Map<String, Object>) source.get("properties")).get("myIndexedField")); Assert.assertNull(((Map<String, Object>) source.get("properties")).get("id")); }
@Test public void testGetDocumentFromEntityWithFeaturedImage() throws ComponentLookupException { final AttachmentStore attachmentStore = this.componentManager.getInstance(AttachmentStore.class); LoadedAttachment sample = new LoadedAttachment(); sample.setSlug("sample-attachment"); sample.setExtension("jpg"); when(attachmentStore.findAndLoadById((UUID) anyObject())).thenReturn(sample); EntityWithFeaturedImage entity = new EntityWithFeaturedImage(UUID.randomUUID(), UUID.randomUUID(), "toto"); Map<String, Object> source = this.componentManager.getComponentUnderTest().purveyDocument(entity, tenant); Assert.assertNotNull(source.get("featuredImage")); }
@Test public void testGetDocumentFromEntityWhereExistsACustomHandlerForThatType() throws Exception { CustomEntity entity = new CustomEntity(); Map<String, Object> source = this.componentManager.getComponentUnderTest().purveyDocument(entity, tenant); Assert.assertEquals("world", source.get("hello")); }