Exemplo n.º 1
0
  /**
   * FIXME Skipped for Postgres Test method for {@link org.melati.poem.dbms.Dbms#
   * getConnection(java.lang.String, java.lang.String, java.lang.String)}.
   *
   * @throws Exception
   */
  public void testGetConnection() throws Exception {
    Connection c = PoemThread.transaction().getDatabase().getCommittedConnection();

    if (c.getClass().getName().indexOf("postgresql") == -1) {
      // System.err.println(c.getTransactionIsolation() + ">=" +
      // Connection.TRANSACTION_READ_COMMITTED);
      assertTrue(
          c.getTransactionIsolation()
              + " is not >= "
              + Connection.TRANSACTION_READ_COMMITTED
              + " for database "
              + PoemThread.transaction().getDatabase()
              + " using "
              + PoemThread.transaction().getDatabase().getDbms()
              + " for connection "
              + c.getClass().getName(),
          c.getTransactionIsolation() >= Connection.TRANSACTION_READ_COMMITTED);
    }
  }
Exemplo n.º 2
0
  protected void doPoemRequest(Melati melati) throws ServletException, IOException {
    String method = melati.getMethod();
    if (method != null && method.equals("Upload")) {
      doUpload(melati);
      return;
    }

    melati.getResponse().setContentType("text/html");
    MelatiWriter output = melati.getWriter();

    output.write("<html><head><title>PoemServlet Test</title></head>\n");
    output.write("<body>\n");
    output.write("<h2>PoemServlet " + "Test</h2>\n");
    output.write("<p>This servlet tests your melati/poem configuration. " + "</p>\n");
    output.write(
        "<p>If you can read this message, it means that you have "
            + "successfully created a  POEM session, \n");
    output.write(
        "using the configurations given in " + "org.melati.LogicalDatabase.properties. </p>\n");
    output.write(
        "<p><b>Note</b> that this " + "servlet does not initialise a template engine.</p>\n");
    output.write("<h4>The PoemContext</h4>\n");
    output.write(
        "<h4>The PoemContext enables access to a database, a table, a record and a method.</h4>\n");
    output.write(
        "<p>Your <b>PoemContext</b> is set up as: " + melati.getPoemContext() + ".</p> \n");
    output.write("<p>Method:" + method + "</p>\n");

    output.write("<p>\nThe PoemContext can be setup using the servlet's PathInfo.</p>\n");
    output.write("<ul>\n");
    output.write("<li>\n");
    output.write(
        "<a href="
            + melati.getZoneURL()
            + "/org.melati.test.PoemServletTest/"
            + melati.getPoemContext().getLogicalDatabase()
            + "/tableinfo/0/View>"
            + "tableinfo/0/View"
            + "</a>)\n");
    output.write("</li>\n");
    output.write("<li>\n");
    output.write(
        "<a href="
            + melati.getZoneURL()
            + "/org.melati.test.PoemServletTest/"
            + melati.getPoemContext().getLogicalDatabase()
            + "/columninfo/0/View>"
            + "columninfo/0/View"
            + "</a>)\n");
    output.write("</li>\n");
    output.write("<li>\n");
    output.write(
        "<a href="
            + melati.getZoneURL()
            + "/org.melati.test.PoemServletTest/"
            + melati.getPoemContext().getLogicalDatabase()
            + "/user/1/View>user/1/View"
            + "</a>)\n");
    output.write("</li>\n");
    output.write("</ul>\n");
    output.write("");
    output.write("<table>");
    output.write(
        "<tr><th colspan=2>Tables in the Database " + melati.getDatabaseName() + "</th></tr>\n");

    for (Table t : melati.getDatabase().getDisplayTables()) {
      output.write("<tr>\n <td>");
      output.write(t.getDisplayName());
      output.write("</td>\n <td>");
      output.write(t.getDescription());
      output.write("</td>\n</tr>\n");
    }
    output.write("</table>\n");

    output.write("<h4>File upload</h4>\n");
    output.write("<p>\n");
    output.write("A <b>PoemFileDataAdaptor</b> ");
    output.write("obtains the name of the file upload directory from ");
    output.write("a setting in the settings table.\n");
    output.write("</p>\n");

    output.write(
        "<form method=\"post\" action=\"Upload"
            + "\" enctype=\"multipart/form-data\" target='Upload'>"
            + p("You can upload a file here:")
            + "<input type=hidden name='upload' value='yes'>\n"
            + "<input type=\"file\" name=\"file\" enctype=\"multipart/form-data\">\n"
            + "<input type=\"submit\" name=\"Submit\" value=\"Upload file\">\n"
            + getUploadMessage(melati)
            + "</form>\n");

    output.write("<h4>Melati Exception handling</h4\n>");
    output.write("<p>An exception is rendered to the output.</p>\n");
    output.write("<p>An access violation provokes a login challenge.</p>\n");
    output.write("<p>You curently have the access token " + melati.getUser() + ".</p>\n<");
    output.write("<ul>\n");
    output.write("<li>\n");
    output.write("<a href='" + melati.getSameURL() + "/Exception'>Exception</a>\n");
    output.write("</li>\n");
    output.write("<li>\n");
    output.write(
        "<a href='"
            + melati.getSameURL()
            + "/AccessPoemException'>Access Poem "
            + "Exception</a> (requiring you to log-in as an administrator)\n");
    output.write("</li>\n");
    output.write("</ul>\n");

    if (method != null) {
      if (method.equals("Exception")) throw new MelatiBugMelatiException("It got caught!");
      if (method.equals("AccessPoemException")) {
        Capability admin = PoemThread.database().administerCapability();
        AccessToken token = PoemThread.accessToken();
        output.write(
            "<p>You are logged in as " + token + " and have " + admin + " capability.</p>\n");
        if (!token.givesCapability(admin)) throw new AccessPoemException(token, admin);
      }
    }

    output.write("<h3>Further Testing</h3>\n");
    output.write("<h4>Template Engine Testing</h4>\n");
    output.write(
        p(
            "You are currently using: <b>"
                + melati.getConfig().getTemplateEngine().getClass().getName()
                + "</b>."));
    output.write(
        p(
            "You can test your WebMacro installation by clicking <a href="
                + melati.getZoneURL()
                + "/org.melati.test.WebmacroStandalone/>WebmacroStandalone</a>"));
    output.write(
        p(
            "You can test your Template Engine working with "
                + "Melati by clicking <a href="
                + melati.getZoneURL()
                + "/org.melati.test.TemplateServletTest/"
                + melati.getPoemContext().getLogicalDatabase()
                + ">"
                + "org.melati.test.TemplateServletTest/"
                + melati.getPoemContext().getLogicalDatabase()
                + "</a>"));

    output.write(
        p(
            "Make sure the <a href='"
                + melati.getZoneURL()
                + "/org.melati.admin.Admin/"
                + melati.getPoemContext().getLogicalDatabase()
                + "/Main'>Admin System</a> is working."
                + "\n"));

    output.write("</body></html>");
  }