Пример #1
0
  @Test
  public void testCopyFileOverwrite() throws Exception {
    String directoryPath = "/testCopyFile/directory/path" + System.currentTimeMillis();
    String sourcePath = directoryPath + "/source.txt";
    String destName = "destination.txt";
    String destPath = directoryPath + "/" + destName;
    createDirectory(directoryPath);
    createFile(sourcePath, "This is the contents");
    createFile(destPath, "Original file");

    // with no-overwrite, copy should fail
    JSONObject requestObject = new JSONObject();
    addSourceLocation(requestObject, sourcePath);
    WebRequest request =
        getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
    request.setHeaderField("X-Create-Options", "copy,no-overwrite");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode());

    // now omit no-overwrite and copy should succeed and return 200 instead of 201
    request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
    request.setHeaderField("X-Create-Options", "copy");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject responseObject = new JSONObject(response.getText());
    checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null);
    assertTrue(checkFileExists(sourcePath));
    assertTrue(checkFileExists(destPath));
  }
Пример #2
0
  @Test
  public void testCopyFileInvalidSource() throws Exception {
    String directoryPath = "/testCopyFile/directory/path" + System.currentTimeMillis();
    createDirectory(directoryPath);

    JSONObject requestObject = new JSONObject();
    requestObject.put("Location", "/this/does/not/exist/at/all");
    WebRequest request =
        getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
    request.setHeaderField("X-Create-Options", "copy");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
    JSONObject responseObject = new JSONObject(response.getText());
    assertEquals("Error", responseObject.get("Severity"));
  }
Пример #3
0
 @Test
 public void testCopyFileNoOverwrite() throws Exception {
   String directoryPath = "/testCopyFile/directory/path" + System.currentTimeMillis();
   String sourcePath = directoryPath + "/source.txt";
   String destName = "destination.txt";
   String destPath = directoryPath + "/" + destName;
   createDirectory(directoryPath);
   createFile(sourcePath, "This is the contents");
   JSONObject requestObject = new JSONObject();
   addSourceLocation(requestObject, sourcePath);
   WebRequest request =
       getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
   request.setHeaderField("X-Create-Options", "copy");
   WebResponse response = webConversation.getResponse(request);
   assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
   JSONObject responseObject = new JSONObject(response.getText());
   checkFileMetadata(responseObject, destName, null, null, null, null, null, null, null);
   assertTrue(checkFileExists(sourcePath));
   assertTrue(checkFileExists(destPath));
 }
Пример #4
0
  @Test
  public void testCreateFileOverwrite()
      throws CoreException, IOException, SAXException, JSONException {
    String directoryPath = "sample/directory/path" + System.currentTimeMillis();
    createDirectory(directoryPath);
    String fileName = "testfile.txt";

    WebRequest request =
        getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

    // creating again at the same location should succeed but return OK rather than CREATED
    request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    // creating with no-overwrite should fail if it already exists
    request = getPostFilesRequest(directoryPath, getNewFileJSON(fileName).toString(), fileName);
    request.setHeaderField("X-Create-Options", "no-overwrite");
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_PRECON_FAILED, response.getResponseCode());
  }