コード例 #1
0
  public void testImageInsideCollection() throws Exception {
    execute("CRUD.new");
    execute("Collection.new", "viewObject=xava_view_section0_ingredients");
    execute("ImageEditor.changeImage", "newImageProperty=image");
    assertNoErrors();
    assertAction("LoadImage.loadImage");
    String imageUrl = System.getProperty("user.dir") + "/test-images/cake.gif";
    setFileValue("newImage", imageUrl);
    execute("LoadImage.loadImage");
    assertNoErrors();

    HtmlPage page = (HtmlPage) getWebClient().getCurrentWindow().getEnclosedPage();
    URL url = page.getWebResponse().getRequestSettings().getUrl();

    String urlPrefix = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();

    HtmlImage image = (HtmlImage) page.getElementsByName(decorateId("image")).get(0);
    String imageURL = null;
    if (image.getSrcAttribute().startsWith("/")) {
      imageURL = urlPrefix + image.getSrcAttribute();
    } else {
      String urlBase = Strings.noLastToken(url.getPath(), "/");
      imageURL = urlPrefix + urlBase + image.getSrcAttribute();
    }
    WebResponse response = getWebClient().getPage(imageURL).getWebResponse();
    assertTrue("Image not obtained", response.getContentAsString().length() > 0);
    assertEquals("Result is not an image", "image", response.getContentType());
  }
コード例 #2
0
  @Test
  public void testDeleteNonEmptyDirectory() throws CoreException, IOException, SAXException {
    String dirPath1 = "sample/directory/path/sample1" + System.currentTimeMillis();
    String dirPath2 = "sample/directory/path/sample2" + System.currentTimeMillis();
    String fileName = "subfile.txt";
    String subDirectory = "subdirectory";

    createDirectory(dirPath1);
    createFile(dirPath1 + "/" + fileName, "Sample file content");
    createDirectory(dirPath2 + "/" + subDirectory);

    WebRequest request = getDeleteFilesRequest(dirPath1);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(
        "Could not delete directory with file",
        HttpURLConnection.HTTP_OK,
        response.getResponseCode());

    assertFalse(
        "Delete directory with file request returned OK, but the file still exists",
        checkDirectoryExists(dirPath1));

    request = getDeleteFilesRequest(dirPath2);
    response = webConversation.getResponse(request);
    assertEquals(
        "Could not delete directory with subdirectory",
        HttpURLConnection.HTTP_OK,
        response.getResponseCode());

    assertFalse(
        "Delete directory with subdirectory request returned OK, but the file still exists",
        checkDirectoryExists(dirPath2));
  }
コード例 #3
0
  @Test
  public void testReadDirectoryChildren()
      throws CoreException, IOException, SAXException, JSONException {
    String dirName = "path" + System.currentTimeMillis();
    String directoryPath = "sample/directory/" + dirName;
    createDirectory(directoryPath);

    String subDirectory = "subdirectory";
    createDirectory(directoryPath + "/" + subDirectory);

    String subFile = "subfile.txt";
    createFile(directoryPath + "/" + subFile, "Sample file");

    WebRequest request = getGetFilesRequest(directoryPath + "?depth=1");
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    List<JSONObject> children = getDirectoryChildren(new JSONObject(response.getText()));

    assertEquals("Wrong number of directory children", 2, children.size());

    for (JSONObject child : children) {
      if (child.getBoolean("Directory")) {
        checkDirectoryMetadata(child, subDirectory, null, null, null, null, null);
      } else {
        checkFileMetadata(child, subFile, null, null, null, null, null, null, null);
      }
    }
  }
コード例 #4
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));
  }
コード例 #5
0
  @Test
  public void testDirectoryWithSpaces() throws CoreException, IOException, SAXException {
    String basePath = "sampe/dir with spaces/long" + System.currentTimeMillis();
    createDirectory(basePath);

    WebRequest request = getGetFilesRequest(basePath);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
  }
コード例 #6
0
  // test null value in rows doesn't throw
  public void testTextNull() throws Exception {
    MockStatusAccessor statusAccessor =
        MockStatusAccessor.generateStatusAccessor(colArray1, rowArrayWithNulls);
    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    log.debug(resp.getText());

    List lines = getLines(resp);
    assertEqualTables(tableWithNulls, lines);
  }
コード例 #7
0
ファイル: StatefulTest.java プロジェクト: Lorena25/TFG-Lorena
  public void testStateCookies() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());

    WebRequest request = new PostMethodWebRequest("http://localhost/" + resourceName);
    request.setParameter("color", "red");
    WebResponse response = sr.getResponse(request);
    assertNotNull("No response received", response);
    assertEquals("Returned cookie count", 1, response.getNewCookieNames().length);
  }
コード例 #8
0
  // test special (non-string) key in row doesn't throw
  public void testTextNonStringKey() throws Exception {
    MockStatusAccessor statusAccessor = new MockStatusAccessor();
    List cols = ListUtil.list("foo", StatusTable.ROW_SEPARATOR);
    statusAccessor.setRows(MockStatusAccessor.makeRowsFrom(cols, rowArray1), null);
    statusAccessor.setColumnDescriptors(
        MockStatusAccessor.makeColumnDescriptorsFrom(colArray1), null);

    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    log.debug(resp.getText());
  }
コード例 #9
0
  @Test
  public void testDeleteEmptyDir() throws CoreException, IOException, SAXException {
    String dirPath = "sample/directory/path/sample" + System.currentTimeMillis();
    createDirectory(dirPath);

    WebRequest request = getDeleteFilesRequest(dirPath);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertFalse(
        "Delete request returned OK, but the directory still exists",
        checkDirectoryExists(dirPath));
  }
コード例 #10
0
ファイル: StatefulTest.java プロジェクト: Lorena25/TFG-Lorena
  public void testNoInitialState() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());

    WebRequest request = new GetMethodWebRequest("http://localhost/" + resourceName);
    WebResponse response = sr.getResponse(request);
    assertNotNull("No response received", response);
    assertEquals("content type", "text/plain", response.getContentType());
    assertEquals("requested resource", "No session found", response.getText());
    assertEquals("Returned cookie count", 0, response.getNewCookieNames().length);
  }
コード例 #11
0
  @Test
  public void testReadDirectory() throws CoreException, IOException, SAXException, JSONException {
    String dirName = "path" + System.currentTimeMillis();
    String directoryPath = "sample/directory/" + dirName;
    createDirectory(directoryPath);

    WebRequest request = getGetFilesRequest(directoryPath);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    JSONObject dirObject = new JSONObject(response.getText());
    checkDirectoryMetadata(dirObject, dirName, null, null, null, null, null);
  }
コード例 #12
0
ファイル: DefaultPageCreator.java プロジェクト: enenuki/phd
 /*  19:    */ public Page createPage(WebResponse webResponse, WebWindow webWindow)
     /*  20:    */ throws IOException
       /*  21:    */ {
   /*  22:100 */ String contentType =
       determineContentType(
           webResponse.getContentType().toLowerCase(), webResponse.getContentAsStream());
   /*  23:    */
   /*  24:    */
   /*  25:    */
   /*  26:104 */ String pageType = determinePageType(contentType);
   /*  27:    */ Page newPage;
   /*  28:    */ Page newPage;
   /*  29:105 */ if ("html".equals(pageType))
   /*  30:    */ {
     /*  31:106 */ newPage = createHtmlPage(webResponse, webWindow);
     /*  32:    */ }
   /*  33:    */ else
   /*  34:    */ {
     /*  35:    */ Page newPage;
     /*  36:108 */ if ("javascript".equals(pageType))
     /*  37:    */ {
       /*  38:109 */ newPage = createJavaScriptPage(webResponse, webWindow);
       /*  39:    */ }
     /*  40:    */ else
     /*  41:    */ {
       /*  42:    */ Page newPage;
       /*  43:111 */ if ("xml".equals(pageType))
       /*  44:    */ {
         /*  45:112 */ XmlPage xml = createXmlPage(webResponse, webWindow);
         /*  46:113 */ DomElement doc = xml.getDocumentElement();
         /*  47:    */ Page newPage;
         /*  48:114 */ if ((doc != null)
             && ("http://www.w3.org/1999/xhtml".equals(doc.getNamespaceURI()))) {
           /*  49:115 */ newPage = createXHtmlPage(webResponse, webWindow);
           /*  50:    */ } else {
           /*  51:118 */ newPage = xml;
           /*  52:    */ }
         /*  53:    */ }
       /*  54:    */ else
       /*  55:    */ {
         /*  56:    */ Page newPage;
         /*  57:121 */ if ("text".equals(pageType)) {
           /*  58:122 */ newPage = createTextPage(webResponse, webWindow);
           /*  59:    */ } else {
           /*  60:125 */ newPage = createUnexpectedPage(webResponse, webWindow);
           /*  61:    */ }
         /*  62:    */ }
       /*  63:    */ }
     /*  64:    */ }
   /*  65:127 */ return newPage;
   /*  66:    */ }
コード例 #13
0
ファイル: HelperClass.java プロジェクト: arpavan/LeaveApp
  public WebResponse loginForm(String username, String password) throws Exception {
    WebConversation conversation = new WebConversation();
    HttpUnitOptions.setScriptingEnabled(false);
    HttpUnitOptions.setExceptionsThrownOnScriptError(false);
    WebRequest request = new GetMethodWebRequest("http://localhost:8084/LeaveApp/index.jsp");
    WebResponse response = conversation.getResponse(request);
    WebForm loginform = response.getForms()[0];
    loginform.setParameter("username", username);
    loginform.setParameter("password", password);
    request = loginform.getRequest("submitbutton");
    response = conversation.getResponse(request);

    return response;
  }
コード例 #14
0
  @WebPost("/das-delete-{entity}")
  public WebResponse deleteEntity(
      @WebUser User user, @PathVar("entity") String entityType, @MaybeJson("id") Object idObj) {
    IDao dao = daoRegistry.getDao(entityType);
    Object id = getIdValue(dao.getIdClass(), idObj);

    int numDeleted = dao.delete(user, id);

    if (numDeleted > 0) {
      return WebResponse.success(id);
    } else {
      return WebResponse.fail(new AppException("Cannot delete " + entityType + " with id " + id));
    }
  }
コード例 #15
0
  @Test
  public void testReadFileContents() throws CoreException, IOException, SAXException {
    String directoryPath = "sample/directory/path" + System.currentTimeMillis();
    createDirectory(directoryPath);
    String fileName = "sampleFile" + System.currentTimeMillis() + ".txt";
    String fileContent = "Sample File Cotnent " + System.currentTimeMillis();
    createFile(directoryPath + "/" + fileName, fileContent);

    WebRequest request = getGetFilesRequest(directoryPath + "/" + fileName);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertEquals("Invalid file content", fileContent, response.getText());
  }
コード例 #16
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);
  }
コード例 #17
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);
  }
コード例 #18
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"));
  }
コード例 #19
0
ファイル: MyTest.java プロジェクト: bflavius/nb-soa
  public void testWSDL() throws Exception {
    WebConversation conversation = new WebConversation();
    String destination = testProps.getProperty("destination");
    if (destination != null && destination.length() > 0) {
      WebRequest request = new GetMethodWebRequest(destination + "?WSDL");

      WebResponse response = conversation.getResponse(request);

      int i = response.getContentLength();
      InputSource is = new InputSource(response.getInputStream());

      Document doc = builder.parse(is);

      doc.getDocumentElement();
      System.out.println("My test");
    }
  }
コード例 #20
0
ファイル: StatefulTest.java プロジェクト: Lorena25/TFG-Lorena
  public void testSessionPreloading() throws Exception {
    final String resourceName1 = "something/interesting/start";
    final String resourceName2 = "something/continue";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName1, StatefulServlet.class.getName());
    sr.registerServlet(resourceName2, StatefulServlet.class.getName());
    ServletUnitClient wc = sr.newClient();

    wc.getSession(true).setAttribute("color", "green");
    WebRequest request = new GetMethodWebRequest("http://localhost/" + resourceName2);
    WebResponse response = wc.getResponse(request);
    assertNotNull("No response received", response);
    assertEquals("content type", "text/plain", response.getContentType());
    assertEquals("requested resource", "You posted green", response.getText());
    assertEquals("Returned cookie count", 0, response.getNewCookieNames().length);
  }
コード例 #21
0
  /** @throws Exception if the test fails */
  @Test
  public void testConstructorWithWebResponse() throws Exception {
    final List<NameValuePair> emptyList = Collections.emptyList();
    final WebResponseData webResponseData =
        new WebResponseData(
            ArrayUtils.EMPTY_BYTE_ARRAY, HttpStatus.SC_NOT_FOUND, "not found", emptyList);
    final WebResponse webResponse =
        new WebResponseImpl(webResponseData, URL_FIRST, HttpMethod.GET, 10);
    final FailingHttpStatusCodeException e = new FailingHttpStatusCodeException(webResponse);

    assertEquals(webResponse, e.getResponse());
    assertEquals(webResponse.getStatusMessage(), e.getStatusMessage());
    assertEquals(webResponse.getStatusCode(), e.getStatusCode());
    assertTrue(
        "message doesn't contain failing url",
        e.getMessage().indexOf(URL_FIRST.toExternalForm()) > -1);
  }
コード例 #22
0
  /** Tests that we are not allowed to get metadata files */
  @Test
  public void testGetForbiddenFiles() throws IOException, SAXException, BackingStoreException {
    // enable global anonymous read
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE);
    String oldValue = prefs.get(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, null);
    prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, "true");
    prefs.flush();
    try {
      // should not be allowed to get at file root
      WebRequest request = new GetMethodWebRequest(SERVER_LOCATION + FILE_SERVLET_LOCATION);
      setAuthentication(request);
      WebResponse response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get the root",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());

      // should not be allowed to access the metadata directory
      request = new GetMethodWebRequest(SERVER_LOCATION + FILE_SERVLET_LOCATION + ".metadata");
      setAuthentication(request);
      response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get metadata",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());

      // should not be allowed to read specific metadata files
      request =
          new GetMethodWebRequest(
              SERVER_LOCATION
                  + FILE_SERVLET_LOCATION
                  + ".metadata/.plugins/org.eclipse.orion.server.user.securestorage/user_store");
      setAuthentication(request);
      response = webConversation.getResponse(request);
      assertEquals(
          "Should not be able to get metadata",
          HttpURLConnection.HTTP_FORBIDDEN,
          response.getResponseCode());
    } finally {
      // reset the preference we messed with for the test
      if (oldValue == null) prefs.remove(ServerConstants.CONFIG_FILE_ANONYMOUS_READ);
      else prefs.put(ServerConstants.CONFIG_FILE_ANONYMOUS_READ, oldValue);
      prefs.flush();
    }
  }
コード例 #23
0
ファイル: StatefulTest.java プロジェクト: Lorena25/TFG-Lorena
  public void testInvocationCompletion() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());
    ServletUnitClient suc = sr.newClient();

    WebRequest request = new PostMethodWebRequest("http://localhost/" + resourceName);
    request.setParameter("color", "red");

    InvocationContext ic = suc.newInvocation(request);
    StatefulServlet ss = (StatefulServlet) ic.getServlet();
    ss.setColor(ic.getRequest(), "blue");
    ss.writeSelectMessage("blue", ic.getResponse().getWriter());

    WebResponse response = ic.getServletResponse();
    assertEquals("requested resource", "You selected blue", response.getText());
    assertEquals("Returned cookie count", 1, response.getNewCookieNames().length);
  }
コード例 #24
0
  @Test
  public void testDeleteFile() throws CoreException, IOException, SAXException {
    String dirPath = "sample/directory/path";
    String fileName = System.currentTimeMillis() + ".txt";
    String filePath = dirPath + "/" + fileName;

    createDirectory(dirPath);
    createFile(filePath, "Sample file content");

    WebRequest request = getDeleteFilesRequest(filePath);
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

    assertFalse("Delete request returned OK, but the file still exists", checkFileExists(filePath));

    assertTrue(
        "File was deleted but the above directory was deleted as well",
        checkDirectoryExists(dirPath));
  }
コード例 #25
0
  @WebPost("/das-create-{entity}")
  public WebResponse createEntity(
      @WebUser User user, @PathVar("entity") String entityType, @JsonParam("props") Map props) {
    IDao dao = daoRegistry.getDao(entityType);

    // TODO: probably need to have a createWithReturn
    Object id = dao.create(user, props);
    Object entity = dao.get(user, id).orElse(null);
    return WebResponse.success(entity);
  }
コード例 #26
0
  @WebGet("/das-get-{entity}")
  public WebResponse getEntity(
      @WebUser User user, @PathVar("entity") String entityType, @MaybeJson("id") Object idObj) {
    IDao dao = daoRegistry.getDao(entityType);
    Object id = getIdValue(dao.getIdClass(), idObj);

    Object entity = dao.get(user, id).orElse(null);

    return WebResponse.success(entity);
  }
コード例 #27
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));
 }
コード例 #28
0
  public void testText() throws Exception {
    MockStatusAccessor statusAccessor =
        MockStatusAccessor.generateStatusAccessor(colArray1, rowArray1);
    statusAccessor.setTitle("testtbl", null);
    statSvc.registerStatusAccessor("testtbl", statusAccessor);

    WebResponse resp = getTable("testtbl", true);
    assertResponseOk(resp);
    assertEquals("Content type", "text/plain", resp.getContentType());
    log.debug(resp.getText());
    List lines = getLines(resp);
    assertEquals(rowArray1.length + 3, lines.size());
    Map row0 = getRow((String) lines.get(0));
    assertEquals("2.4.6.8", row0.get("host"));

    Map row2 = getRow((String) lines.get(2));
    assertEquals("testtbl", row2.get("table"));

    assertEqualTables(table1, lines);
  }
コード例 #29
0
ファイル: StatefulTest.java プロジェクト: Lorena25/TFG-Lorena
  public void testInvocationContextUpdate() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());
    ServletUnitClient suc = sr.newClient();

    WebRequest request = new PostMethodWebRequest("http://localhost/" + resourceName);
    request.setParameter("color", "red");

    InvocationContext ic = suc.newInvocation(request);
    StatefulServlet ss = (StatefulServlet) ic.getServlet();
    ss.setColor(ic.getRequest(), "blue");
    suc.getResponse(ic);

    WebResponse response = suc.getResponse("http://localhost/" + resourceName);
    assertNotNull("No response received", response);
    assertEquals("content type", "text/plain", response.getContentType());
    assertEquals("requested resource", "You posted blue", response.getText());
    assertEquals("Returned cookie count", 0, response.getNewCookieNames().length);
  }
コード例 #30
0
  @WebPost("/das-update-{entity}")
  public WebResponse updateEntity(
      @WebUser User user,
      @PathVar("entity") String entityType,
      @MaybeJson("id") Object idObj,
      @JsonParam("props") Map props) {
    IDao dao = daoRegistry.getDao(entityType);
    Object id = getIdValue(dao.getIdClass(), idObj);

    int r = dao.update(user, props, id);
    return WebResponse.success(r);
  }