@Override protected void registerComponents() throws Exception { super.registerComponents(); // register the IO mockups setup = new AnnotationsMockSetup(getComponentManager(), new TestDocumentFactory()); setup.setupExpectations(docName); // mock the document name serializer to return the document name as the reference to be able to // get the // documents from the factory serializerMock = setup.getMockery().mock(EntityReferenceSerializer.class); // register DefaultComponentDescriptor<EntityReferenceSerializer> ersDesc = new DefaultComponentDescriptor<EntityReferenceSerializer>(); ersDesc.setRoleType(EntityReferenceSerializer.TYPE_STRING); getComponentManager().registerComponent(ersDesc, serializerMock); // and setup the mock setup .getMockery() .checking( new Expectations() { { allowing(serializerMock) .serialize(with(any(EntityReference.class)), with(any(Object.class))); will( new Action() { public void describeTo(Description description) { description.appendText("Gets the serialization of a reference"); } public Object invoke(Invocation invocation) throws Throwable { EntityReference documentRef = (org.xwiki.model.reference.EntityReference) invocation.getParameter(0); // extract the document part and return it if (documentRef.getType() != EntityType.DOCUMENT) { throw new Exception("Expected document reference but got " + documentRef); } return documentRef.getName(); } }); } }); }
/** * Tests the update of a document. * * @throws IOException if anything goes wrong mocking the documents * @throws MaintainerServiceException if anything goes wrong maintaining the the document * annotations */ @Test public void testUpdate() throws IOException, MaintainerServiceException { // ignore the docName ftm, just test the marvelous setup MockDocument doc = ((TestDocumentFactory) setup.getDocFactory()).getDocument(docName); // TODO: this is not the place to put this code, but it's the most comfortable copyOriginalSelections(doc); annotationMaintainer.updateAnnotations(docName, doc.getSource(), doc.getModifiedSource()); // test the result assertSameAnnotations(doc.getUpdatedAnnotations(), doc.getAnnotations()); }