}
public void testCopyFs() throws Exception {
// create a source CAS by deserializing from XCAS
CAS srcCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
InputStream serCasStream = new FileInputStream(JUnitExtension.getFile("ExampleCas/cas.xml"));
XCASDeserializer.deserialize(serCasStream, srcCas);
serCasStream.close();
// create a destination CAS and the CasCopier instance
CAS destCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
CasCopier copier = new CasCopier(srcCas, destCas);
// set sofa data in destination CAS (this is not copied automtically)
destCas.setDocumentText(srcCas.getDocumentText());
// copy an Annotation
Iterator<AnnotationFS> annotIter = srcCas.getAnnotationIndex().iterator();
FeatureStructure annot = (FeatureStructure) annotIter.next();
FeatureStructure copy = copier.copyFs(annot);
// verify copy
CasComparer.assertEquals(annot, copy);
// copy a Relation (which will have references)
Iterator<FeatureStructure> relationIter = srcCas.getIndexRepository().getIndex("testRelationIndex").iterator();
FeatureStructure relFS = (FeatureStructure) relationIter.next();
FeatureStructure relCopy = copier.copyFs(relFS);
// verify copy
CasComparer.assertEquals(relFS, relCopy);
// test null array element
ArrayFS arrFS = srcCas.createArrayFS(3);
arrFS.set(0, annot);
arrFS.set(1, null);
arrFS.set(2, relFS);
FeatureStructure copyArrFS = copier.copyFs(arrFS);
CasComparer.assertEquals(arrFS, copyArrFS);
// test with using base cas
destCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes);
destCas.setDocumentText(srcCas.getDocumentText());
copier = new CasCopier(((CASImpl)srcCas).getBaseCAS(), ((CASImpl)destCas).getBaseCAS());
annotIter = srcCas.getAnnotationIndex().iterator();
annot = (FeatureStructure) annotIter.next();