use of de.tudarmstadt.ukp.clarin.webanno.api.type.CASMetadata in project webanno by webanno.
the class ImportExportServiceImplTest method thatExportContainsNoCasMetadata.
@Test
public void thatExportContainsNoCasMetadata() throws Exception {
SourceDocument sd = makeSourceDocument(1l, 1l);
// Create type system with built-in types, internal types, but without any project-specific
// types.
List<TypeSystemDescription> typeSystems = new ArrayList<>();
typeSystems.add(createTypeSystemDescription());
typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
TypeSystemDescription ts = mergeTypeSystems(typeSystems);
// Prepare a test CAS with a CASMetadata annotation (DocumentMetaData is added as well
// because the DKPro Core writers used by the ImportExportService expect it.
JCas jcas = JCasFactory.createJCas(ts);
casStorageSession.add("jcas", EXCLUSIVE_WRITE_ACCESS, jcas.getCas());
jcas.setDocumentText("This is a test .");
DocumentMetaData.create(jcas);
CASMetadata cmd = new CASMetadata(jcas);
cmd.addToIndexes(jcas);
// Pass the CAS through the export mechanism. Write as XMI because that is one of the
// formats which best retains the information from the CAS and is nicely human-readable
// if the test needs to be debugged.
File exportedXmi = sut.exportCasToFile(jcas.getCas(), sd, "testfile", sut.getFormatById(XmiFormatSupport.ID).get(), true);
// Read the XMI back from the ZIP that was created by the exporter. This is because XMI
// files are always serialized as XMI file + type system file.
JCas jcas2 = JCasFactory.createJCas(ts);
casStorageSession.add("jcas2", EXCLUSIVE_WRITE_ACCESS, jcas.getCas());
try (ZipArchiveInputStream zipInput = new ZipArchiveInputStream(new FileInputStream(exportedXmi))) {
ZipArchiveEntry entry;
while ((entry = zipInput.getNextZipEntry()) != null) {
if (entry.getName().endsWith(".xmi")) {
XmiCasDeserializer.deserialize(zipInput, jcas2.getCas());
break;
}
}
} finally {
exportedXmi.delete();
}
List<CASMetadata> result = new ArrayList<>(select(jcas2, CASMetadata.class));
assertThat(result).hasSize(0);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.type.CASMetadata in project webanno by webanno.
the class CasStorageServiceImplTest method testCasMetadataGetsCreated.
@Test
public void testCasMetadataGetsCreated() throws Exception {
try (CasStorageSession casStorageSession = openNested(true)) {
List<TypeSystemDescription> typeSystems = new ArrayList<>();
typeSystems.add(createTypeSystemDescription());
typeSystems.add(CasMetadataUtils.getInternalTypeSystem());
JCas cas = JCasFactory.createJCas(mergeTypeSystems(typeSystems));
casStorageSession.add("cas", EXCLUSIVE_WRITE_ACCESS, cas.getCas());
SourceDocument doc = makeSourceDocument(2l, 2l, "test");
String user = "test";
sut.writeCas(doc, cas.getCas(), user);
JCas cas2 = sut.readCas(doc, user).getJCas();
List<CASMetadata> cmds = new ArrayList<>(select(cas2, CASMetadata.class));
assertThat(cmds).hasSize(1);
assertThat(cmds.get(0).getProjectId()).isEqualTo(doc.getProject().getId());
assertThat(cmds.get(0).getSourceDocumentId()).isEqualTo(doc.getId());
assertThat(cmds.get(0).getLastChangedOnDisk()).isEqualTo(sut.getCasTimestamp(doc, user).get());
}
}
Aggregations