@Override public void setUp() throws Exception { super.setUp(); String name = getClass().getName(); VirtualFile uploadTestFolder = mountPoint.getRoot().createFolder(name); uploadTestFolderId = uploadTestFolder.getId(); uploadTestFolderPath = uploadTestFolder.getPath(); }
public void testUploadFileAlreadyExists() throws Exception { String fileName = "existedFile.txt"; VirtualFile folder = mountPoint.getVirtualFileById(uploadTestFolderId); folder.createFile(fileName, new ByteArrayInputStream(DEFAULT_CONTENT.getBytes())); ContainerResponse response = doUploadFile(fileName, DEFAULT_CONTENT, "", "", false); assertEquals(200, response.getStatus()); String entity = (String) response.getEntity(); assertTrue(entity.contains("Item with the same name exists")); log.info(entity); }
@Override public FileEntry copyTo(String newParent, String newName, boolean override) throws NotFoundException, ForbiddenException, ConflictException, ServerException { if (Path.fromString(newParent).isRoot()) { throw new ServerException( String.format("Invalid path %s. Can't create file outside of project.", newParent)); } final VirtualFile vf = getVirtualFile(); final MountPoint mp = vf.getMountPoint(); return new FileEntry( getWorkspace(), vf.copyTo(mp.getVirtualFile(newParent), newName, override)); }
public void testUploadFileAlreadyExistsOverwrite() throws Exception { String fileName = "existedFileOverwrite.txt"; VirtualFile folder = mountPoint.getVirtualFileById(uploadTestFolderId); folder.createFile(fileName, new ByteArrayInputStream(DEFAULT_CONTENT.getBytes())); String fileContent = "test upload and overwrite existed file"; ContainerResponse response = doUploadFile(fileName, fileContent, "", "", true); assertEquals(200, response.getStatus()); String expectedPath = uploadTestFolderPath + '/' + fileName; VirtualFile file = mountPoint.getVirtualFile(expectedPath); assertNotNull("File was not created in expected location. ", file); checkFileContext(fileContent, MediaType.TEXT_PLAIN, file); }
@Override public boolean accept(VirtualFile file) { try { TikaConfig tikaConfig = new TikaConfig(); MediaType mimeType = tikaConfig.getDetector().detect(file.getContent().getStream(), new Metadata()); return mediaTypes.contains(mimeType); } catch (TikaException | ForbiddenException | ServerException | IOException e) { return false; } }
public void testDeleteFileLockedNoLockToken() throws Exception { file.lock(0); ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter(); String path = SERVICE_URI + "delete/" + fileId; ContainerResponse response = launcher.service(HttpMethod.POST, path, BASE_URI, null, null, writer, null); assertEquals(403, response.getStatus()); log.info(new String(writer.getBody())); try { mountPoint.getVirtualFileById(fileId); } catch (NotFoundException e) { fail("File must not be removed since it is locked. "); } }
public void testDeleteFileLocked() throws Exception { String lockToken = file.lock(0); String path = SERVICE_URI + "delete/" + fileId + '?' + "lockToken=" + lockToken; ContainerResponse response = launcher.service(HttpMethod.POST, path, BASE_URI, null, null, null); assertEquals(204, response.getStatus()); try { mountPoint.getVirtualFileById(fileId); fail("File must be removed. "); } catch (NotFoundException e) { } try { mountPoint.getVirtualFile(filePath); fail("File must be removed. "); } catch (NotFoundException e) { } }
@Override protected void setUp() throws Exception { super.setUp(); String name = getClass().getName(); VirtualFile deleteTestFolder = mountPoint.getRoot().createFolder(name); VirtualFile folder = deleteTestFolder.createFolder("DeleteTest_FOLDER"); // add child in folder VirtualFile childFile = folder.createFile("file", new ByteArrayInputStream(DEFAULT_CONTENT.getBytes())); folderId = folder.getId(); folderChildId = childFile.getId(); folderPath = folder.getPath(); folderChildPath = childFile.getPath(); file = deleteTestFolder.createFile( "DeleteTest_FILE", new ByteArrayInputStream(DEFAULT_CONTENT.getBytes())); fileId = file.getId(); filePath = file.getPath(); }