@Test public void baseMetaDataIsSetBeforeExecutingTransformations() throws Exception { when(this.executor.execute(any(), any())).then(new Answer<Block>() { @Override public Block answer(InvocationOnMock invocation) throws Throwable { return invocation.<DocumentContentAsyncRenderer>getArgument(0).render(false, false).getBlock(); } }); ExecutionContext executionContext = new ExecutionContext(); executionContext.setProperty("xwikicontext", new HashMap<String, Object>()); when(this.execution.getContext()).thenReturn(executionContext); XDOM content = new XDOM(Collections.emptyList()); when(this.document.getXDOM()).thenReturn(content); DocumentReference currentDocRef = new DocumentReference("wiki", "Space", "Page"); when(this.documentAccessBridge.getCurrentDocumentReference()).thenReturn(currentDocRef); when(this.serializer.serialize(currentDocRef)).thenReturn("foo"); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { XDOM xdom = (XDOM) invocation.getArguments()[0]; assertEquals("foo", xdom.getMetaData().getMetaData(MetaData.BASE)); return null; } }).when(this.transformationManager).performTransformations(any(XDOM.class), any(TransformationContext.class)); DocumentDisplayerParameters parameters = new DocumentDisplayerParameters(); parameters.setTransformationContextIsolated(false); assertSame(content, this.documentDisplayer.display(document, parameters)); verify(this.transformationManager, times(1)).performTransformations(same(content), any(TransformationContext.class)); }
@Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { DocumentContentAsyncRenderer renderer = this.rendererProvider.get(); Set<String> contextEntries = renderer.initialize(document, parameters); AsyncRendererConfiguration configuration = new AsyncRendererConfiguration(); configuration.setContextEntries(contextEntries); try { Block block = this.executor.execute(renderer, configuration); return block instanceof XDOM ? (XDOM) block : new XDOM(Arrays.asList(block)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
DocumentContentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { DocumentContentAsyncRenderer renderer = this.rendererProvider.get(); Set<String> contextEntries = renderer.initialize(document, parameters); AsyncRendererConfiguration configuration = new AsyncRendererConfiguration(); configuration.setContextEntries(contextEntries); try { Block block = this.executor.execute(renderer, configuration); return block instanceof XDOM ? (XDOM) block : new XDOM(Arrays.asList(block)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } } }
DocumentContentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { DocumentContentAsyncRenderer renderer = this.rendererProvider.get(); Set<String> contextEntries = renderer.initialize(document, parameters); AsyncRendererConfiguration configuration = new AsyncRendererConfiguration(); configuration.setContextEntries(contextEntries); try { Block block = this.executor.execute(renderer, configuration); return block instanceof XDOM ? (XDOM) block : new XDOM(Arrays.asList(block)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  }
DocumentContentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { DocumentContentAsyncRenderer renderer = this.rendererProvider.get(); Set<String> contextEntries = renderer.initialize(document, parameters); AsyncRendererConfiguration configuration = new AsyncRendererConfiguration(); configuration.setContextEntries(contextEntries); try { Block block = this.executor.execute(renderer, configuration); return block instanceof XDOM ? (XDOM) block : new XDOM(Arrays.asList(block)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  @Override XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters); }
DocumentContentDisplayer implements DocumentDisplayer { @Override public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters) { DocumentContentAsyncRenderer renderer = this.rendererProvider.get(); Set<String> contextEntries = renderer.initialize(document, parameters); AsyncRendererConfiguration configuration = new AsyncRendererConfiguration(); configuration.setContextEntries(contextEntries); try { Block block = this.executor.execute(renderer, configuration); return block instanceof XDOM ? (XDOM) block : new XDOM(Arrays.asList(block)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }  @Override XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters);  }