ForEachNode extends ContainerMappingNode { @Override public void collectIndexUpdate(final IndexUpdateBuilder indexUpdateBuilder) throws InterruptedException, IOException, RepositoryException { RecordContext ctx = indexUpdateBuilder.getRecordContext(); if (fieldType != null && !systemFields.isSystemField(fieldType.getName())) { indexUpdateBuilder.addDependency(fieldType.getId()); if (ctx.record != null && !ctx.record.hasField(fieldType.getName())) { return; } } follow.follow(indexUpdateBuilder, new FollowCallback() { @Override public void call() throws RepositoryException, InterruptedException, IOException { ForEachNode.super.collectIndexUpdate(indexUpdateBuilder); } }); } ForEachNode(SystemFields systemFields, Follow follow); Follow getFollow(); @Override boolean isIndexAffectedByUpdate(VTaggedRecord vtRecord, Scope scope); @Override void collectIndexUpdate(final IndexUpdateBuilder indexUpdateBuilder);  }
@Test public void testCollectIndexUpdate_LinkedRecordFieldType() throws InterruptedException, RepositoryException, IOException { when(recordContextRecord.hasField(USERDEFINED_FIELDTYPE_NAME)).thenReturn(true); LinkFieldFollow linkFieldFollow = mock(LinkFieldFollow.class); when(linkFieldFollow.getFieldType()).thenReturn(userDefinedFieldType); ForEachNode forEachNode = new ForEachNode(systemFields, linkFieldFollow); forEachNode.collectIndexUpdate(indexUpdateBuilder); verify(indexUpdateBuilder).addDependency(USERDEFINED_FIELDTYPE_ID); verify(linkFieldFollow).follow(eq(indexUpdateBuilder), any(FollowCallback.class)); }
@Test public void testCollectIndexUpdate_LinkedRecordFieldType_FieldIsNotWithinRecordContextRecord() throws InterruptedException, RepositoryException, IOException { when(recordContextRecord.hasField(USERDEFINED_FIELDTYPE_NAME)).thenReturn(false); LinkFieldFollow linkFieldFollow = mock(LinkFieldFollow.class); when(linkFieldFollow.getFieldType()).thenReturn(userDefinedFieldType); ForEachNode forEachNode = new ForEachNode(systemFields, linkFieldFollow); forEachNode.collectIndexUpdate(indexUpdateBuilder); verify(indexUpdateBuilder).addDependency(USERDEFINED_FIELDTYPE_ID); verify(linkFieldFollow, never()).follow(eq(indexUpdateBuilder), any(FollowCallback.class)); }
@Test public void testCollectIndexUpdate_EmbeddedRecordFieldType() throws InterruptedException, RepositoryException, IOException { when(recordContextRecord.hasField(USERDEFINED_FIELDTYPE_NAME)).thenReturn(true); RecordFieldFollow recordFieldFollow = mock(RecordFieldFollow.class); when(recordFieldFollow.getFieldType()).thenReturn(userDefinedFieldType); ForEachNode forEachNode = new ForEachNode(systemFields, recordFieldFollow); forEachNode.collectIndexUpdate(indexUpdateBuilder); verify(indexUpdateBuilder).addDependency(USERDEFINED_FIELDTYPE_ID); verify(recordFieldFollow).follow(eq(indexUpdateBuilder), any(FollowCallback.class)); }
@Test public void testCollectIndexUpdate_EmbeddedRecordFieldType_FieldIsNotWithinRecordContextRecord() throws InterruptedException, RepositoryException, IOException { when(recordContextRecord.hasField(USERDEFINED_FIELDTYPE_NAME)).thenReturn(false); RecordFieldFollow recordFieldFollow = mock(RecordFieldFollow.class); when(recordFieldFollow.getFieldType()).thenReturn(userDefinedFieldType); ForEachNode forEachNode = new ForEachNode(systemFields, recordFieldFollow); forEachNode.collectIndexUpdate(indexUpdateBuilder); verify(indexUpdateBuilder).addDependency(USERDEFINED_FIELDTYPE_ID); verify(recordFieldFollow, never()).follow(eq(indexUpdateBuilder), any(FollowCallback.class)); }