Esempio n. 1
0
  @Test
  public void testCreateTopLevelFile()
      throws CoreException, IOException, SAXException, JSONException {
    String directoryPath = "sample" + 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());
    assertTrue(
        "Create file response was OK, but the file does not exist",
        checkFileExists(directoryPath + "/" + fileName));
    assertEquals(
        "Response should contain file metadata in JSON, but was " + response.getText(),
        "application/json",
        response.getContentType());
    JSONObject responseObject = new JSONObject(response.getText());
    assertNotNull("No file information in responce", responseObject);
    checkFileMetadata(responseObject, fileName, null, null, null, null, null, null, null);

    // should be able to perform GET on location header to obtain metadata
    String location = response.getHeaderField("Location");
    request = getGetFilesRequest(location + "?parts=meta");
    response = webConversation.getResource(request);
    assertNotNull(location);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    responseObject = new JSONObject(response.getText());
    assertNotNull("No direcory information in responce", responseObject);
    checkFileMetadata(responseObject, fileName, null, null, null, null, null, null, null);
  }
Esempio n. 2
0
  @Test
  public void testCreateDirectory() throws CoreException, IOException, SAXException, JSONException {
    String directoryPath = "sample/directory/path" + System.currentTimeMillis();
    createDirectory(directoryPath);

    String dirName = "testdir";
    webConversation.setExceptionsThrownOnErrorStatus(false);

    WebRequest request =
        getPostFilesRequest(directoryPath, getNewDirJSON(dirName).toString(), dirName);
    WebResponse response = webConversation.getResponse(request);

    assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
    assertTrue(
        "Create directory response was OK, but the directory does not exist",
        checkDirectoryExists(directoryPath + "/" + dirName));
    assertEquals(
        "Response should contain directory metadata in JSON, but was " + response.getText(),
        "application/json",
        response.getContentType());
    JSONObject responseObject = new JSONObject(response.getText());
    assertNotNull("No directory information in response", responseObject);
    checkDirectoryMetadata(responseObject, dirName, null, null, null, null, null);

    // should be able to perform GET on location header to obtain metadata
    String location = response.getHeaderField(ProtocolConstants.HEADER_LOCATION);
    request = getGetFilesRequest(location);
    response = webConversation.getResource(request);
    assertNotNull(location);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    responseObject = new JSONObject(response.getText());
    assertNotNull("No direcory information in responce", responseObject);
    checkDirectoryMetadata(responseObject, dirName, null, null, null, null, null);
  }
 /** Verifies that the HTTP header of a diagram incites the browser to cache it. */
 public void testInvalidUrl() throws Exception {
   WebConversation conversation = new WebConversation();
   // Try to proxify an invalid address
   WebRequest request = new GetMethodWebRequest(getServerUrl() + "proxy/invalidURL");
   WebResponse response = conversation.getResource(request);
   // Analyze response, it must be the empty form
   // Verifies the Content-Type header
   assertEquals("Response content type is not HTML", "text/html", response.getContentType());
   WebForm[] forms = response.getForms();
   assertEquals(2, forms.length);
 }
 public void testProxyWithFormat() throws Exception {
   WebConversation conversation = new WebConversation();
   WebRequest request =
       new GetMethodWebRequest(
           getServerUrl() + "proxy/svg/" + getServerUrl() + "resource/test2diagrams.txt");
   WebResponse response = conversation.getResource(request);
   // Analyze response
   // Verifies the Content-Type header
   // TODO assertEquals( "Response content type is not SVG", "image/svg+xml",
   // response.getContentType());
   // Get the content and verify its size
   String diagram = response.getText();
   int diagramLen = diagram.length();
   assertTrue(diagramLen > 1000);
   assertTrue(diagramLen < 3000);
 }
 /** Verifies the proxified reception of the default Bob and Alice diagram */
 public void testDefaultProxy() throws Exception {
   WebConversation conversation = new WebConversation();
   WebRequest request =
       new GetMethodWebRequest(
           getServerUrl() + "proxy/" + getServerUrl() + "resource/test2diagrams.txt");
   WebResponse response = conversation.getResource(request);
   // Analyze response
   // Verifies the Content-Type header
   // assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
   // Get the image and verify its size (~2000 bytes)
   InputStream responseStream = response.getInputStream();
   ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
   byte[] buf = new byte[1024];
   int n = 0;
   while ((n = responseStream.read(buf)) != -1) {
     imageStream.write(buf, 0, n);
   }
   imageStream.close();
   responseStream.close();
   byte[] inMemoryImage = imageStream.toByteArray();
   int diagramLen = inMemoryImage.length;
   assertTrue(diagramLen > 1500);
   assertTrue(diagramLen < 2500);
 }