@Override public File getCasFile(SourceDocument aDocument, String aUser) throws IOException { return casStorageService.getCasFile(aDocument, aUser); }
@Override public File getCasFile(SourceDocument aDocument, String aUser) throws IOException { return casStorageService.getCasFile(aDocument, aUser); }
@Test public void thatCreatingOrReadingInitialCasForNewDocumentCreatesNewCas() throws Exception { when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); SourceDocument doc = makeSourceDocument(1l, 1l, "test"); JCas cas = sut.createOrReadInitialCas(doc); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(doc, WebAnnoConst.INITIAL_CAS_PSEUDO_USER)).exists(); }
@Test public void thatReadingNonExistentAnnotationCasCreatesNewCas() throws Exception { SourceDocument sourceDocument = makeSourceDocument(1l, 1l, "test"); User user = makeUser(); when(userRepository.get(user.getUsername())).thenReturn(user); when(entityManager.createQuery(anyString(), any())).thenThrow(NoResultException.class); when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); JCas cas = sut.readAnnotationCas(sourceDocument, user.getUsername()); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(sourceDocument, user.getUsername())).exists(); }
@Test public void testWriteReadExistsDeleteCas() throws Exception { SourceDocument doc = makeSourceDocument(1l, 1l); JCas cas = JCasFactory.createText("This is a test"); String user = "test"; sut.writeCas(doc, cas, user); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas cas2 = sut.readCas(doc, user); assertThat(cas2.getDocumentText()).isEqualTo(cas.getDocumentText()); sut.deleteCas(doc, user); assertThat(sut.getCasFile(doc, user)).doesNotExist(); assertThat(sut.existsCas(doc, user)).isFalse(); }
@Test public void testReadOrCreateCas() throws Exception { SourceDocument doc = makeSourceDocument(2l, 2l); String user = "test"; JCas cas = sut.readOrCreateCas(doc, user, () -> { try { return JCasFactory.createText("This is a test"); } catch (UIMAException e) { throw new IOException(e); } }); assertThat(sut.getCasFile(doc, user)).exists(); assertThat(sut.existsCas(doc, user)).isTrue(); JCas cas2 = sut.readCas(doc, user); assertThat(cas2.getDocumentText()).isEqualTo(cas.getDocumentText()); sut.deleteCas(doc, user); assertThat(sut.getCasFile(doc, user)).doesNotExist(); assertThat(sut.existsCas(doc, user)).isFalse(); }