Exemple #1
0
 private void testTransfer() throws Exception {
   Server server = new Server();
   server.setOut(new PrintStream(new ByteArrayOutputStream()));
   server.runTool("-web", "-webPort", "8182", "-properties", "null");
   File transfer = new File("transfer");
   transfer.mkdirs();
   try {
     FileOutputStream f = new FileOutputStream("transfer/test.txt");
     f.write("Hello World".getBytes());
     f.close();
     WebClient client = new WebClient();
     String url = "http://localhost:8182";
     String result = client.get(url);
     client.readSessionId(result);
     String test = client.get(url, "transfer/test.txt");
     assertEquals("Hello World", test);
     new File("transfer/testUpload.txt").delete();
     client.upload(
         url + "/transfer/testUpload.txt",
         "testUpload.txt",
         new ByteArrayInputStream("Hallo Welt".getBytes()));
     byte[] d = IOUtils.readBytesAndClose(new FileInputStream("transfer/testUpload.txt"), -1);
     assertEquals("Hallo Welt", new String(d));
     new File("transfer/testUpload.txt").delete();
   } finally {
     server.shutdown();
     FileUtils.deleteRecursive("transfer", true);
   }
 }
Exemple #2
0
 private void testServer() throws Exception {
   Server server = new Server();
   server.setOut(new PrintStream(new ByteArrayOutputStream()));
   server.runTool("-web", "-webPort", "8182", "-properties", "null", "-tcp", "-tcpPort", "9101");
   try {
     String url = "http://localhost:8182";
     WebClient client;
     String result;
     client = new WebClient();
     client.setAcceptLanguage("de-de,de;q=0.5");
     result = client.get(url);
     client.readSessionId(result);
     result = client.get(url, "login.jsp");
     assertEquals("text/html", client.getContentType());
     assertContains(result, "Einstellung");
     client.get(url, "favicon.ico");
     assertEquals("image/x-icon", client.getContentType());
     client.get(url, "ico_ok.gif");
     assertEquals("image/gif", client.getContentType());
     client.get(url, "tree.js");
     assertEquals("text/javascript", client.getContentType());
     client.get(url, "stylesheet.css");
     assertEquals("text/css", client.getContentType());
     client.get(url, "admin.do");
     try {
       client.get(url, "adminShutdown.do");
     } catch (IOException e) {
       // expected
       Thread.sleep(1000);
     }
   } finally {
     server.shutdown();
   }
   // it should be stopped now
   server = Server.createTcpServer("-tcpPort", "9101");
   server.start();
   server.stop();
 }
Exemple #3
0
 private void testTools() throws Exception {
   if (config.memory) {
     return;
   }
   deleteDb("web");
   Connection conn = getConnection("web");
   conn.createStatement().execute("create table test(id int) as select 1");
   conn.close();
   Server server = new Server();
   server.setOut(new PrintStream(new ByteArrayOutputStream()));
   server.runTool("-web", "-webPort", "8182", "-properties", "null", "-tcp", "-tcpPort", "9101");
   try {
     String url = "http://localhost:8182";
     WebClient client;
     String result;
     client = new WebClient();
     result = client.get(url);
     client.readSessionId(result);
     result = client.get(url, "tools.jsp");
     FileUtils.delete(getBaseDir() + "/backup.zip");
     result =
         client.get(
             url,
             "tools.do?tool=Backup&args=-dir,"
                 + getBaseDir()
                 + ",-db,web,-file,"
                 + getBaseDir()
                 + "/backup.zip");
     deleteDb("web");
     assertTrue(FileUtils.exists(getBaseDir() + "/backup.zip"));
     result =
         client.get(url, "tools.do?tool=DeleteDbFiles&args=-dir," + getBaseDir() + ",-db,web");
     assertFalse(FileUtils.exists(getBaseDir() + "/web.h2.db"));
     result =
         client.get(
             url,
             "tools.do?tool=Restore&args=-dir,"
                 + getBaseDir()
                 + ",-db,web,-file,"
                 + getBaseDir()
                 + "/backup.zip");
     assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.db"));
     FileUtils.delete(getBaseDir() + "/web.h2.sql");
     FileUtils.delete(getBaseDir() + "/backup.zip");
     result = client.get(url, "tools.do?tool=Recover&args=-dir," + getBaseDir() + ",-db,web");
     assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.sql"));
     FileUtils.delete(getBaseDir() + "/web.h2.sql");
     result =
         client.get(
             url,
             "tools.do?tool=RunScript&args=-script,"
                 + getBaseDir()
                 + "/web.h2.sql,-url,"
                 + getURL("web", true)
                 + ",-user,"
                 + getUser()
                 + ",-password,"
                 + getPassword());
     FileUtils.delete(getBaseDir() + "/web.h2.sql");
     assertTrue(FileUtils.exists(getBaseDir() + "/web.h2.db"));
     deleteDb("web");
   } finally {
     server.shutdown();
   }
 }
Exemple #4
0
  private void testWebApp() throws Exception {
    Server server = new Server();
    server.setOut(new PrintStream(new ByteArrayOutputStream()));
    server.runTool("-web", "-webPort", "8182", "-properties", "null", "-tcp", "-tcpPort", "9101");
    try {
      String url = "http://*****:*****@META select * from test");
      assertContains(result, "typeName");
      result = client.get(url, "query.do?sql=delete from test");
      result =
          client.get(
              url, "query.do?sql=@LOOP 1000 insert into test values(?, 'Hello ' || ?/*RND*/)");
      assertContains(result, "1000 * (Prepared)");
      result = client.get(url, "query.do?sql=select * from test");
      result = client.get(url, "query.do?sql=@list select * from test");
      assertContains(result, "Row #");
      result = client.get(url, "query.do?sql=@parameter_meta select * from test where id = ?");
      assertContains(result, "INTEGER");
      result = client.get(url, "query.do?sql=@edit select * from test");
      assertContains(result, "editResult.do");
      result =
          client.get(url, "query.do?sql=" + StringUtils.urlEncode("select space(100001) a, 1 b"));
      assertContains(result, "...");
      result = client.get(url, "query.do?sql=" + StringUtils.urlEncode("call '<&>'"));
      assertContains(result, "&lt;&amp;&gt;");
      result = client.get(url, "query.do?sql=@HISTORY");
      result = client.get(url, "getHistory.do?id=4");
      assertContains(result, "select * from test");
      result = client.get(url, "query.do?sql=delete from test");
      // op 1 (row -1: insert, otherwise update): ok, 2: delete  3: cancel,
      result =
          client.get(
              url, "editResult.do?sql=@edit select * from test&op=1&row=-1&r-1c1=1&r-1c2=Hello");
      assertContains(result, "1");
      assertContains(result, "Hello");
      result =
          client.get(
              url, "editResult.do?sql=@edit select * from test&op=1&row=1&r1c1=1&r1c2=Hallo");
      assertContains(result, "1");
      assertContains(result, "Hallo");
      result = client.get(url, "query.do?sql=select * from test");
      assertContains(result, "1");
      assertContains(result, "Hallo");
      result = client.get(url, "editResult.do?sql=@edit select * from test&op=2&row=1");
      result = client.get(url, "query.do?sql=select * from test");
      assertContains(result, "no rows");

      // autoComplete
      result = client.get(url, "autoCompleteList.do?query=select 'abc");
      assertContains(StringUtils.urlDecode(result), "'");
      result = client.get(url, "autoCompleteList.do?query=select 'abc''");
      assertContains(StringUtils.urlDecode(result), "'");
      result = client.get(url, "autoCompleteList.do?query=select 'abc' ");
      assertContains(StringUtils.urlDecode(result), "||");
      result = client.get(url, "autoCompleteList.do?query=select 'abc' |");
      assertContains(StringUtils.urlDecode(result), "|");
      result = client.get(url, "autoCompleteList.do?query=select 'abc' || ");
      assertContains(StringUtils.urlDecode(result), "'");
      result = client.get(url, "autoCompleteList.do?query=call timestamp '2");
      assertContains(result, "20");
      result = client.get(url, "autoCompleteList.do?query=call time '1");
      assertContains(StringUtils.urlDecode(result), "12:00:00");
      result = client.get(url, "autoCompleteList.do?query=call timestamp '2001-01-01 12:00:00.");
      assertContains(result, "nanoseconds");
      result = client.get(url, "autoCompleteList.do?query=call timestamp '2001-01-01 12:00:00.00");
      assertContains(result, "nanoseconds");
      result = client.get(url, "autoCompleteList.do?query=call $$ hello world");
      assertContains(StringUtils.urlDecode(result), "$$");
      result = client.get(url, "autoCompleteList.do?query=alter index ");
      assertContains(StringUtils.urlDecode(result), "character");
      result = client.get(url, "autoCompleteList.do?query=alter index idx");
      assertContains(StringUtils.urlDecode(result), "character");
      result = client.get(url, "autoCompleteList.do?query=alter index \"IDX_");
      assertContains(StringUtils.urlDecode(result), "\"");
      result = client.get(url, "autoCompleteList.do?query=alter index \"IDX_\"\"");
      assertContains(StringUtils.urlDecode(result), "\"");
      result = client.get(url, "autoCompleteList.do?query=help ");
      assertContains(result, "anything");
      result = client.get(url, "autoCompleteList.do?query=help select");
      assertContains(result, "anything");
      result = client.get(url, "autoCompleteList.do?query=call ");
      assertContains(result, "0x");
      result = client.get(url, "autoCompleteList.do?query=call 0");
      assertContains(result, ".");
      result = client.get(url, "autoCompleteList.do?query=se");
      assertContains(result, "select");
      assertContains(result, "set");
      result = client.get(url, "tables.do");
      assertContains(result, "TEST");
      result = client.get(url, "autoCompleteList.do?query=select * from ");
      assertContains(result, "test");
      result = client.get(url, "autoCompleteList.do?query=select * from test t where t.");
      assertContains(result, "id");
      result = client.get(url, "autoCompleteList.do?query=select id x from test te where t");
      assertContains(result, "te");
      result = client.get(url, "autoCompleteList.do?query=select * from test where name = '");
      assertContains(StringUtils.urlDecode(result), "'");
      result =
          client.get(
              url,
              "autoCompleteList.do?query=select * from information_schema.columns where columns.");
      assertContains(result, "column_name");

      result = client.get(url, "query.do?sql=delete from test");

      // special commands
      result = client.get(url, "query.do?sql=@autocommit_true");
      assertContains(result, "Auto commit is now ON");
      result = client.get(url, "query.do?sql=@autocommit_false");
      assertContains(result, "Auto commit is now OFF");
      result = client.get(url, "query.do?sql=@cancel");
      assertContains(result, "There is currently no running statement");
      result =
          client.get(
              url, "query.do?sql=@generated insert into test(id) values(test_sequence.nextval)");
      assertContains(result, "SCOPE_IDENTITY()");
      result = client.get(url, "query.do?sql=@maxrows 2000");
      assertContains(result, "Max rowcount is set");
      result = client.get(url, "query.do?sql=@password_hash user password");
      assertContains(result, "501cf5c163c184c26e62e76d25d441979f8f25dfd7a683484995b4a43a112fdf");
      result = client.get(url, "query.do?sql=@sleep 1");
      assertContains(result, "Ok");
      result = client.get(url, "query.do?sql=@catalogs");
      assertContains(result, "PUBLIC");
      result = client.get(url, "query.do?sql=@column_privileges null null null TEST null");
      assertContains(result, "PRIVILEGE");
      result = client.get(url, "query.do?sql=@cross_references null null null TEST");
      assertContains(result, "PKTABLE_NAME");
      result = client.get(url, "query.do?sql=@exported_keys null null null TEST");
      assertContains(result, "PKTABLE_NAME");
      result = client.get(url, "query.do?sql=@imported_keys null null null TEST");
      assertContains(result, "PKTABLE_NAME");
      result = client.get(url, "query.do?sql=@primary_keys null null null TEST");
      assertContains(result, "PK_NAME");
      result = client.get(url, "query.do?sql=@procedures null null null");
      assertContains(result, "PROCEDURE_NAME");
      result = client.get(url, "query.do?sql=@procedure_columns");
      assertContains(result, "PROCEDURE_NAME");
      result = client.get(url, "query.do?sql=@schemas");
      assertContains(result, "PUBLIC");
      result = client.get(url, "query.do?sql=@table_privileges");
      assertContains(result, "PRIVILEGE");
      result = client.get(url, "query.do?sql=@table_types");
      assertContains(result, "SYSTEM TABLE");
      result = client.get(url, "query.do?sql=@type_info");
      assertContains(result, "CLOB");
      result = client.get(url, "query.do?sql=@version_columns");
      assertContains(result, "PSEUDO_COLUMN");
      result = client.get(url, "query.do?sql=@attributes");
      assertContains(result, "Feature not supported: &quot;attributes&quot;");
      result = client.get(url, "query.do?sql=@super_tables");
      assertContains(result, "SUPERTABLE_NAME");
      result = client.get(url, "query.do?sql=@super_types");
      assertContains(result, "Feature not supported: &quot;superTypes&quot;");
      result = client.get(url, "query.do?sql=@prof_start");
      assertContains(result, "Ok");
      result = client.get(url, "query.do?sql=@prof_stop");
      assertContains(result, "Top Stack Trace(s)");
      result = client.get(url, "query.do?sql=@best_row_identifier null null TEST");
      assertContains(result, "SCOPE");
      assertContains(result, "COLUMN_NAME");
      assertContains(result, "ID");
      result = client.get(url, "query.do?sql=@udts");
      assertContains(result, "CLASS_NAME");
      result = client.get(url, "query.do?sql=@udts null null null 1,2,3");
      assertContains(result, "CLASS_NAME");
      result =
          client.get(url, "query.do?sql=@LOOP 10 @STATEMENT insert into test values(?, 'Hello')");
      result = client.get(url, "query.do?sql=select * from test");
      assertContains(result, "8");
      result = client.get(url, "query.do?sql=@EDIT select * from test");
      assertContains(result, "editRow");

      result = client.get(url, "query.do?sql=@AUTOCOMMIT TRUE");
      result = client.get(url, "query.do?sql=@AUTOCOMMIT FALSE");
      result = client.get(url, "query.do?sql=@TRANSACTION_ISOLATION");
      result = client.get(url, "query.do?sql=@SET MAXROWS 1");
      result = client.get(url, "query.do?sql=select * from test order by id");
      result = client.get(url, "query.do?sql=@SET MAXROWS 1000");
      result = client.get(url, "query.do?sql=@TABLES");
      assertContains(result, "TEST");
      result = client.get(url, "query.do?sql=@COLUMNS null null TEST");
      assertContains(result, "ID");
      result = client.get(url, "query.do?sql=@INDEX_INFO null null TEST");
      assertContains(result, "PRIMARY");
      result = client.get(url, "query.do?sql=@CATALOG");
      assertContains(result, "PUBLIC");
      result = client.get(url, "query.do?sql=@MEMORY");
      assertContains(result, "Used");

      result = client.get(url, "query.do?sql=@INFO");
      assertContains(result, "getCatalog");

      result = client.get(url, "logout.do");
      result =
          client.get(
              url,
              "login.do?driver=org.h2.Driver&url=jdbc:h2:mem:web&user=sa&password=sa&name=_test_");

      result = client.get(url, "logout.do");
      result = client.get(url, "settingRemove.do?name=_test_");

      client.get(url, "admin.do");
    } finally {
      server.shutdown();
    }
  }