コード例 #1
0
ファイル: IndexOptimizeTest.java プロジェクト: fpapai/basex
 /**
  * Checks if specified query was rewritten for index access, and checks the query result.
  *
  * @param query query to be tested
  * @param result result or {@code null} for no comparison
  */
 private static void check(final String query, final String result) {
   check(
       query,
       result,
       "exists(/descendant-or-self::*"
           + "[self::"
           + Util.className(ValueAccess.class)
           + "|self::"
           + Util.className(FTIndexAccess.class)
           + "])");
 }
コード例 #2
0
  @Test
  public void testZSS595_Column() {
    Book book = Util.loadBook(this, "book/blank.xlsx");
    Sheet sheet = book.getSheet("Sheet1");

    String[] columns = {"A", "B", "C", "D", "E"};
    Ranges.range(sheet).setFreezePanel(0, 5);

    // === Insert
    for (int i = 1; i < 6; i++) {
      try {
        Ranges.range(sheet, columns[i - 1] + ":G")
            .toColumnRange()
            .insert(InsertShift.DEFAULT, InsertCopyOrigin.FORMAT_LEFT_ABOVE);
      } catch (InvalidModelOpException e) {
        continue;
      }
      fail(); // if doesn't continue, it fail!
    }

    // == Delete
    for (int i = 1; i < 6; i++) {
      try {
        Ranges.range(sheet, columns[i - 1] + ":G").toColumnRange().delete(DeleteShift.DEFAULT);
      } catch (InvalidModelOpException e) {
        continue;
      }
      fail(); // if doesn't continue, it fail!
    }
  }
コード例 #3
0
ファイル: PermissionTest.java プロジェクト: LukasK/basex
 /**
  * Assumes that this command is successful.
  *
  * @param cmd command reference
  * @param s session
  */
 private static void ok(final Command cmd, final Session s) {
   try {
     s.execute(cmd);
   } catch (final IOException ex) {
     fail(Util.message(ex));
   }
 }
コード例 #4
0
  @Test
  public void testZSS595_Row() {
    Book book = Util.loadBook(this, "book/blank.xlsx");
    Sheet sheet = book.getSheet("Sheet1");
    Ranges.range(sheet).setFreezePanel(5, 0);

    // === Insert
    for (int i = 1; i < 6; i++) {
      try {
        Ranges.range(sheet, i + ":6")
            .toRowRange()
            .insert(InsertShift.DEFAULT, InsertCopyOrigin.FORMAT_LEFT_ABOVE);
      } catch (InvalidModelOpException e) {
        continue;
      }
      fail(); // if doesn't continue, it fail!
    }

    // == Delete
    for (int i = 1; i < 6; i++) {
      try {
        Ranges.range(sheet, i + ":6").toRowRange().delete(DeleteShift.DEFAULT);
      } catch (InvalidModelOpException e) {
        continue;
      }
      fail(); // if doesn't continue, it fail!
    }
  }
コード例 #5
0
 @Test
 public void testZSS502_NonExistingSheet2007() {
   Book book = Util.loadBook(this, "book/blank.xlsx");
   Sheet sheet = book.getSheetAt(0);
   Range cell = Ranges.range(sheet, "A1");
   cell.setCellEditText("=nonExisted!B1");
   assertEquals("=nonExisted!B1", cell.getCellEditText());
   assertEquals(ErrorConstants.getText(ErrorConstants.ERROR_REF), cell.getCellFormatText());
 }
コード例 #6
0
ファイル: SessionTest.java プロジェクト: runeengh/basex
 /** Stops a session. */
 @After
 public final void stopSession() {
   try {
     if (cleanup) session.execute(new DropDB(NAME));
     session.close();
   } catch (final IOException ex) {
     fail(Util.message(ex));
   }
 }
コード例 #7
0
 @Test
 public void testZSS510() {
   Book book = Util.loadBook(this, "book/blank.xlsx");
   Sheet sheet = book.getSheetAt(0);
   Range r = Ranges.range(sheet, "A1");
   r.setCellEditText("Hello");
   CellOperationUtil.applyDataFormat(r, "");
   r.getCellFormatText(); // get text shouldn't cause IndexOutBoundaryException
   assertEquals(
       "General", r.getCellStyle().getDataFormat()); // should get General instead of empty string
 }
コード例 #8
0
ファイル: HofModuleTest.java プロジェクト: james-jw/basex
  /** Test method. */
  @Test
  public void foldLeft1Test() {
    query("hof:fold-left1(1 to 10, function($x, $y) { $x + $y })", "55");
    error("hof:fold-left1((), function($x, $y) { $x + $y })", EMPTYFOUND);

    // should be unrolled and evaluated at compile time
    final int limit = FnForEach.UNROLL_LIMIT;
    check(
        "hof:fold-left1(1 to " + limit + ", function($a,$b) {$a+$b})",
        "55",
        "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])",
        "exists(*/" + Util.className(Int.class) + ')');
    // should be unrolled but not evaluated at compile time
    check(
        "hof:fold-left1(1 to " + limit + ", function($a,$b) {0*random:integer($a)+$b})",
        "10",
        "empty(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])",
        "empty(*/" + Util.className(Int.class) + ')',
        "count(//" + Util.className(Arith.class) + "[@op = '+']) eq 9");
    // should not be unrolled
    check(
        "hof:fold-left1(1 to " + (limit + 1) + ", function($a,$b) {$a+$b})",
        "66",
        "exists(//" + Util.className(HofFoldLeft1.class) + "[contains(@name, 'fold-left1')])");
  }
コード例 #9
0
ファイル: PermissionTest.java プロジェクト: LukasK/basex
 /** Clean up method. */
 @After
 public void cleanUp() {
   try {
     testSession.close();
     adminSession.execute(new DropDB(RENAMED));
     adminSession.execute(new DropDB(NAME));
     adminSession.close();
     // give the server some time to clean up the sessions before next test
     Performance.sleep(100);
   } catch (final Exception ex) {
     fail(Util.message(ex));
   }
 }
コード例 #10
0
  @Test
  public void testZSS502_2007() {
    Book book = Util.loadBook(this, "book/502-crossSheetReference.xlsx");
    Sheet sheet = book.getSheet("cell-reference");
    Range referencingCell = Ranges.range(sheet, "C4");
    assertEquals("=row!A1", referencingCell.getCellEditText());
    assertEquals("The first row is freezed.", referencingCell.getCellFormatText());

    Ranges.range(book.getSheet("row")).deleteSheet();

    assertEquals("='#REF'!A1", referencingCell.getCellEditText());
    assertEquals(
        ErrorConstants.getText(ErrorConstants.ERROR_REF), referencingCell.getCellFormatText());
  }
コード例 #11
0
 @Override
 public void run() {
   try {
     for (int i = 0; i < runs; ++i) {
       Performance.sleep((long) (50 * RND.nextDouble()));
       // Return nth text of the database
       final int n = RND.nextInt() % MAX + 1;
       final String qu = Util.info(QUERY, n);
       new XQuery(qu).execute(context);
     }
   } catch (final BaseXException ex) {
     ex.printStackTrace();
   }
 }
コード例 #12
0
ファイル: ServerStressTest.java プロジェクト: jefferya/basex
    @Override
    public void run() {
      try {
        // Perform some queries
        for (int i = 0; i < runs; ++i) {
          Performance.sleep((long) (50 * RND.nextDouble()));

          // Return nth text of the database
          final int n = RND.nextInt() % MAX + 1;
          final String qu = Util.info(QUERY, n);
          session.execute("xquery " + qu);
        }
        session.close();
      } catch (final Exception ex) {
        ex.printStackTrace();
      }
    }
コード例 #13
0
  @Test
  public void testCoordinateListenerStolenCoordinate() throws Exception {

    final CountDownLatch connectedLatch1 = new CountDownLatch(1);
    final CountDownLatch connectedLatch2 = new CountDownLatch(2);
    TestCoordinateListener listener = setUpListenerEnvironment(connectedLatch1, connectedLatch2);
    assertTrue(connectedLatch1.await(20, TimeUnit.SECONDS));
    log.info("Killing zookeeper");
    assertTrue(zk.getState() == ZooKeeper.States.CONNECTED);

    log.info("Killing connection");
    forwarder.terminate();

    zk.delete("/cn/cell/user/service/1/status", -1);
    Util.mkdir(zk, "/cn/cell/user/service/1/status", ZooDefs.Ids.OPEN_ACL_UNSAFE);

    forwarder = new PortForwarder(forwarderPort, "127.0.0.1", zkport);

    assertTrue(connectedLatch2.await(6, TimeUnit.SECONDS));

    int i = 0;
    int q = -1;
    while (true) {
      if (q != listener.events.size()) {
        q = listener.events.size();
      }
      if (listener.events.get(listener.events.size() - 1) == CoordinateListener.Event.NOT_OWNER) {
        break;
      }

      Thread.sleep(10);
      ++i;
      if (i > 1000) {
        fail("Did not get NOT_OWNER");
      }
    }

    // cn2.close();
    // We use the same path for the new ezk, so it reads up the old state, and hence the coordinate
    // is ok.
    //        assertEquals(CoordinateListener.Event.COORDINATE_OK, listener.events.get(2));
    forwarder.terminate();
  }
コード例 #14
0
ファイル: PermissionTest.java プロジェクト: LukasK/basex
  /** Set up method. */
  @Before
  public void setUp() {
    try {
      adminSession = createClient();
      if (server.context.users.get(NAME) != null) {
        ok(new DropUser(NAME), adminSession);
      }

      ok(new CreateUser(NAME, NAME), adminSession);
      ok(new CreateDB(RENAMED), adminSession);
      server.context.soptions.set(StaticOptions.REPOPATH, REPO);
      testSession = createClient(NAME, NAME);

      ok(new CreateDB(NAME, "<xml/>"), adminSession);
      ok(new Close(), adminSession);
    } catch (final Exception ex) {
      fail(Util.message(ex));
    }
  }
コード例 #15
0
ファイル: FnHttpTest.java プロジェクト: james-jw/basex
  /**
   * Tests writing of request content when @src is set.
   *
   * @throws IOException I/O Exception
   */
  @Test
  public void writeFromResource() throws IOException {
    // Create a file form which will be read
    final IOFile file = new IOFile(Prop.TMP, Util.className(FnHttpTest.class));
    file.write(token("test"));

    // Request
    final HttpRequest req = new HttpRequest();
    req.payloadAttrs.put("src", file.url());
    req.payloadAttrs.put("method", "binary");
    // HTTP connection
    final FakeHttpConnection fakeConn = new FakeHttpConnection(new URL("http://www.test.com"));
    HttpClient.setRequestContent(fakeConn.getOutputStream(), req);

    // Delete file
    file.delete();

    assertEquals(fakeConn.out.toString(Strings.UTF8), "test");
  }
コード例 #16
0
  @Test
  public void testZSS511_LEFTB() {
    Book book = Util.loadBook(this, "book/511-REPLACEB-LEFTB.xlsx");
    Sheet sheet = book.getSheet("LEFTB");

    assertEquals("#VALUE!", Ranges.range(sheet, "A1").getCellFormatText());
    assertEquals("", Ranges.range(sheet, "A2").getCellFormatText());
    assertEquals(" ", Ranges.range(sheet, "A3").getCellFormatText());
    assertEquals("\u5E8A", Ranges.range(sheet, "A4").getCellFormatText());
    assertEquals("\u5E8A ", Ranges.range(sheet, "A5").getCellFormatText());
    assertEquals("\u5E8A\u524D", Ranges.range(sheet, "A6").getCellFormatText());
    assertEquals("\u5E8A\u524D ", Ranges.range(sheet, "A7").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E", Ranges.range(sheet, "A8").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E ", Ranges.range(sheet, "A9").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E\u6708", Ranges.range(sheet, "A10").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E\u6708 ", Ranges.range(sheet, "A11").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E\u6708\u5149", Ranges.range(sheet, "A12").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E\u6708\u5149", Ranges.range(sheet, "A13").getCellFormatText());
    assertEquals("\u5E8A\u524D\u660E\u6708\u5149", Ranges.range(sheet, "A14").getCellFormatText());

    assertEquals("#VALUE!", Ranges.range(sheet, "C1").getCellFormatText());
    assertEquals("", Ranges.range(sheet, "C2").getCellFormatText());
    assertEquals("A", Ranges.range(sheet, "C3").getCellFormatText());
    assertEquals("A ", Ranges.range(sheet, "C4").getCellFormatText());
    assertEquals("A\u5E8A", Ranges.range(sheet, "C5").getCellFormatText());
    assertEquals("A\u5E8A ", Ranges.range(sheet, "C6").getCellFormatText());
    assertEquals("A\u5E8A\u524D", Ranges.range(sheet, "C7").getCellFormatText());
    assertEquals("A\u5E8A\u524D ", Ranges.range(sheet, "C8").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E", Ranges.range(sheet, "C9").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E ", Ranges.range(sheet, "C10").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E\u6708", Ranges.range(sheet, "C11").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E\u6708 ", Ranges.range(sheet, "C12").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E\u6708\u5149", Ranges.range(sheet, "C13").getCellFormatText());
    assertEquals("A\u5E8A\u524D\u660E\u6708\u5149", Ranges.range(sheet, "C14").getCellFormatText());

    assertEquals("", Ranges.range(sheet, "E1").getCellFormatText());
  }
コード例 #17
0
 @Test
 public void testFilterSort() {
   // LONGITUDE and LATITUDE are null because of OPTIQ-194.
   Util.discard(Bug.OPTIQ_194_FIXED);
   OptiqAssert.that()
       .enable(enabled())
       .with(ZIPS)
       .query(
           "select * from zips\n"
               + "where city = 'SPRINGFIELD' and id between '20000' and '30000'\n"
               + "order by state")
       .returns(
           "CITY=SPRINGFIELD; LONGITUDE=null; LATITUDE=null; POP=2184; STATE=SC; ID=29146\n"
               + "CITY=SPRINGFIELD; LONGITUDE=null; LATITUDE=null; POP=16811; STATE=VA; ID=22150\n"
               + "CITY=SPRINGFIELD; LONGITUDE=null; LATITUDE=null; POP=32161; STATE=VA; ID=22153\n"
               + "CITY=SPRINGFIELD; LONGITUDE=null; LATITUDE=null; POP=1321; STATE=WV; ID=26763\n")
       .queryContains(
           mongoChecker(
               "{\n"
                   + "  $match: {\n"
                   + "    city: \"SPRINGFIELD\",\n"
                   + "    _id: {\n"
                   + "      $lte: \"30000\",\n"
                   + "      $gte: \"20000\"\n"
                   + "    }\n"
                   + "  }\n"
                   + "}",
               "{$project: {CITY: '$city', LONGITUDE: '$loc[0]', LATITUDE: '$loc[1]', POP: '$pop', STATE: '$state', ID: '$_id'}}",
               "{$sort: {STATE: 1}}"))
       .explainContains(
           "PLAN=MongoToEnumerableConverter\n"
               + "  MongoSortRel(sort0=[$4], dir0=[ASC])\n"
               + "    MongoProjectRel(CITY=[CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], LONGITUDE=[CAST(ITEM(ITEM($0, 'loc'), 0)):FLOAT NOT NULL], LATITUDE=[CAST(ITEM(ITEM($0, 'loc'), 1)):FLOAT NOT NULL], POP=[CAST(ITEM($0, 'pop')):INTEGER], STATE=[CAST(ITEM($0, 'state')):VARCHAR(2) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"], ID=[CAST(ITEM($0, '_id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\"])\n"
               + "      MongoFilterRel(condition=[AND(=(CAST(ITEM($0, 'city')):VARCHAR(20) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", 'SPRINGFIELD'), >=(CAST(ITEM($0, '_id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", '20000'), <=(CAST(ITEM($0, '_id')):VARCHAR(5) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\", '30000'))])\n"
               + "        MongoTableScan(table=[[mongo_raw, zips]])");
 }
コード例 #18
0
ファイル: RESTConcurrencyTest.java プロジェクト: dirkk/basex
 /** Start BaseX HTTP. */
 private void startBaseXHTTP() {
   Util.start(BaseXHTTP.class, "-U" + UserText.ADMIN, "-P" + UserText.ADMIN);
   Performance.sleep(TIMEOUT); // give the server some time to stop
 }
コード例 #19
0
ファイル: PermissionTest.java プロジェクト: LukasK/basex
/**
 * This class tests user permissions.
 *
 * @author BaseX Team 2005-15, BSD License
 * @author Andreas Weiler
 */
public final class PermissionTest extends SandboxTest {
  /** Name of the database to be renamed. */
  private static final String RENAMED = Util.className(PermissionTest.class) + 'r';
  /** Test folder. */
  private static final String FOLDER = "src/test/resources/";
  /** Test repository. * */
  private static final String REPO = FOLDER + "repo/";

  /** Server reference. */
  private static BaseXServer server;
  /** Admin session. */
  private Session adminSession;
  /** Test session. */
  private Session testSession;

  /**
   * Starts the server.
   *
   * @throws IOException I/O exception
   */
  @BeforeClass
  public static void start() throws IOException {
    server = createServer();
  }

  /**
   * Stops the server.
   *
   * @throws IOException I/O exception
   */
  @AfterClass
  public static void stop() throws IOException {
    stopServer(server);
  }

  /** Set up method. */
  @Before
  public void setUp() {
    try {
      adminSession = createClient();
      if (server.context.users.get(NAME) != null) {
        ok(new DropUser(NAME), adminSession);
      }

      ok(new CreateUser(NAME, NAME), adminSession);
      ok(new CreateDB(RENAMED), adminSession);
      server.context.soptions.set(StaticOptions.REPOPATH, REPO);
      testSession = createClient(NAME, NAME);

      ok(new CreateDB(NAME, "<xml/>"), adminSession);
      ok(new Close(), adminSession);
    } catch (final Exception ex) {
      fail(Util.message(ex));
    }
  }

  /** Clean up method. */
  @After
  public void cleanUp() {
    try {
      testSession.close();
      adminSession.execute(new DropDB(RENAMED));
      adminSession.execute(new DropDB(NAME));
      adminSession.close();
      // give the server some time to clean up the sessions before next test
      Performance.sleep(100);
    } catch (final Exception ex) {
      fail(Util.message(ex));
    }
  }

  /** Tests all commands where no permission is needed. */
  @Test
  public void noPermsNeeded() {
    ok(new Grant("none", NAME), adminSession);

    ok(new Password(NAME), testSession);
    ok(new Help("list"), testSession);
    ok(new Close(), testSession);
    no(new List(NAME), testSession);
    ok(new List(), testSession);
    no(new Open(NAME), testSession);
    no(new InfoDB(), testSession);
    no(new InfoIndex(), testSession);
    no(new InfoStorage(), testSession);
    no(new Get("DBPATH"), testSession);
    ok(new Get(MainOptions.QUERYINFO), testSession);
    ok(new Set(MainOptions.QUERYINFO, false), testSession);

    // repo stuff
    no(new RepoInstall(REPO + "/pkg3.xar", null), testSession);
    ok(new RepoList(), testSession);
    no(new RepoDelete("http://www.pkg3.com", null), testSession);

    // XQuery read
    no(new XQuery("//xml"), testSession);
    no(new Find(NAME), testSession);
    no(new Optimize(), testSession);
    // XQuery update
    no(
        new XQuery("for $item in doc('" + NAME + "')//xml " + "return rename node $item as 'null'"),
        testSession);
    no(new CreateDB(NAME, "<xml/>"), testSession);
    no(new Rename(RENAMED, RENAMED + '2'), testSession);
    no(new CreateIndex("SUMMARY"), testSession);
    no(new DropDB(NAME), testSession);
    no(new DropIndex("SUMMARY"), testSession);
    no(new CreateUser(NAME, NAME), testSession);
    no(new DropUser(NAME), testSession);
    no(new Kill("dada"), testSession);
    no(new ShowUsers("Users"), testSession);
    no(new Grant("read", NAME), testSession);
    no(new Grant("none", NAME), testSession);
    no(new AlterPassword(NAME, NAME), testSession);
    no(new AlterUser(NAME, "test2"), testSession);
    no(new Flush(), testSession);
  }

  /** Tests all commands where read permission is needed. */
  @Test
  public void readPermsNeeded() {
    ok(new Grant("read", NAME), adminSession);

    ok(new Open(NAME), testSession);
    ok(new List(NAME), testSession);
    ok(new InfoDB(), testSession);
    ok(new InfoStorage("1", "2"), testSession);
    no(new Get("DBPATH"), testSession);
    ok(new Get(MainOptions.QUERYINFO), testSession);
    ok(new Set(MainOptions.QUERYINFO, false), testSession);
    // XQuery read
    ok(new XQuery("//xml"), testSession);
    ok(new Find(NAME), testSession);

    // repo stuff
    no(new RepoInstall(REPO + "/pkg3.xar", null), testSession);
    ok(new RepoList(), testSession);
    no(new RepoDelete("http://www.pkg3.com", null), testSession);

    // XQuery update
    no(new XQuery("for $n in " + DOC.args(NAME) + "//xml return delete node $n"), testSession);
    no(new XQuery(_DB_CREATE.args(NAME)), testSession);
    no(new Optimize(), testSession);
    no(new CreateDB(NAME, "<xml/>"), testSession);
    no(new Replace(RENAMED, "<xml />"), testSession);
    no(new Rename(RENAMED, RENAMED + '2'), testSession);
    no(new CreateIndex("SUMMARY"), testSession);
    no(new DropDB(NAME), testSession);
    no(new DropIndex("SUMMARY"), testSession);
    no(new CreateUser(NAME, NAME), testSession);
    no(new DropUser(NAME), testSession);
    no(new Export(Prop.TMP + NAME), testSession);
    no(new Kill("dada"), testSession);
    no(new ShowUsers("Users"), testSession);
    no(new Grant("read", NAME), testSession);
    no(new Grant("none", NAME), testSession);
    no(new AlterPassword(NAME, NAME), testSession);
    no(new AlterUser(NAME, "test2"), testSession);
    no(new Flush(), testSession);
    ok(new Close(), testSession);
  }

  /** Tests all commands where write permission is needed. */
  @Test
  public void writePermsNeeded() {
    ok(new Grant("write", NAME), adminSession);
    ok(new Open(RENAMED), testSession);
    ok(new Rename(RENAMED, RENAMED + '2'), testSession);
    ok(new Rename(RENAMED + '2', RENAMED), testSession);

    // replace Test
    ok(new Close(), testSession);
    ok(new Open(RENAMED), testSession);
    ok(new Add(NAME + ".xml", "<xml>1</xml>"), testSession);
    ok(new Optimize(), testSession);
    ok(new Replace(NAME + ".xml", "<xmlr>2</xmlr>"), testSession);

    // repo stuff
    no(new RepoInstall(REPO + "/pkg3.xar", null), testSession);
    ok(new RepoList(), testSession);
    no(new RepoDelete("http://www.pkg3.com", null), testSession);

    // XQuery Update
    ok(
        new XQuery("for $item in doc('" + NAME + "')//xml " + "return rename node $item as 'null'"),
        testSession);
    no(new XQuery(_DB_CREATE.args(NAME)), testSession);

    ok(new Optimize(), testSession);
    for (final CmdIndex cmd : CmdIndex.values()) {
      ok(new CreateIndex(cmd), testSession);
    }
    ok(new InfoIndex(), testSession);
    for (final CmdIndex cmd : CmdIndex.values()) {
      ok(new DropIndex(cmd), testSession);
    }
    ok(new Flush(), testSession);
    ok(new Close(), testSession);
    no(new CreateDB(NAME, "<xml/>"), testSession);
    no(new DropDB(NAME), testSession);
    no(new CreateUser(NAME, NAME), testSession);
    no(new DropUser(NAME), testSession);
    no(new Export(Prop.TMP + NAME), testSession);
    no(new Kill("dada"), testSession);
    no(new ShowUsers("Users"), testSession);
    no(new Grant("read", NAME), testSession);
    no(new Grant("none", NAME), testSession);
    no(new AlterPassword(NAME, NAME), testSession);
    no(new AlterUser(NAME, "test2"), testSession);
  }

  /** Tests all commands where create permission is needed. */
  @Test
  public void createPermsNeeded() {
    ok(new Grant("create", NAME), adminSession);
    ok(new XQuery(_DB_CREATE.args(NAME)), testSession);

    ok(new Close(), testSession);
    ok(new CreateDB(NAME, "<xml/>"), testSession);
    for (final CmdIndex cmd : CmdIndex.values()) {
      ok(new CreateIndex(cmd), testSession);
    }
    ok(new Export(Prop.TMP + NAME), testSession);

    // repo stuff
    ok(new RepoInstall(REPO + "/pkg3.xar", null), testSession);
    ok(new RepoList(), testSession);
    ok(new RepoDelete("http://www.pkg3.com", null), testSession);

    no(new CreateUser(NAME, NAME), testSession);
    no(new DropUser(NAME), testSession);
    no(new Kill("dada"), testSession);
    no(new ShowUsers("Users"), testSession);
    no(new Grant("read", NAME), testSession);
    no(new Grant("none", NAME), testSession);
    no(new AlterPassword(NAME, NAME), testSession);
    no(new org.basex.core.cmd.Test(FOLDER + "tests-ok.xqm"), testSession);
  }

  /** Tests all commands where admin permission is needed. */
  @Test
  public void adminPermsNeeded() {
    ok(new Grant(ADMIN, NAME), adminSession);
    if (server.context.users.get("test2") != null) {
      ok(new DropUser("test2"), testSession);
    }
    ok(new CreateUser("test2", NAME), testSession);
    ok(new CreateDB(NAME, "<xml/>"), testSession);
    ok(new ShowUsers(), testSession);
    ok(new Grant(ADMIN, "test2"), testSession);
    ok(new Grant("create", "test2"), testSession);
    ok(new AlterPassword(NAME, NAME), testSession);
    ok(new AlterUser("test2", "test4"), testSession);
    ok(new DropUser("test3"), testSession);
    ok(new Close(), testSession);
    ok(new Close(), adminSession);
    ok(new DropDB(NAME), adminSession);

    // repo stuff
    ok(new RepoInstall(REPO + "/pkg3.xar", null), testSession);
    ok(new RepoList(), testSession);
    ok(new RepoDelete("http://www.pkg3.com", null), testSession);
    ok(new org.basex.core.cmd.Test(FOLDER + "tests-ok.xqm"), testSession);
  }

  /** Drops users. */
  @Test
  public void dropUsers() {
    no(new DropUser(NAME), testSession);
    no(new DropUser(NAME), adminSession);
    ok(new Exit(), testSession);
    // give the server some time to close the client session
    Performance.sleep(50);
    ok(new DropUser(NAME), adminSession);
  }

  /**
   * Assumes that this command is successful.
   *
   * @param cmd command reference
   * @param s session
   */
  private static void ok(final Command cmd, final Session s) {
    try {
      s.execute(cmd);
    } catch (final IOException ex) {
      fail(Util.message(ex));
    }
  }

  /**
   * Assumes that this command fails.
   *
   * @param cmd command reference
   * @param s session
   */
  private static void no(final Command cmd, final Session s) {
    try {
      s.execute(cmd);
      fail("\"" + cmd + "\" was supposed to fail.");
    } catch (final IOException ignored) {
    }
  }
}
コード例 #20
0
ファイル: RESTConcurrencyTest.java プロジェクト: dirkk/basex
 /** Stop BaseX HTTP. */
 private void stopBaseXHTTP() {
   Util.start(BaseXHTTP.class, "stop");
   Performance.sleep(TIMEOUT); // give the server some time to stop
 }
コード例 #21
0
  @Test
  public void testZSS511_REPLACEB() throws UnsupportedEncodingException {
    Book book = Util.loadBook(this, "book/511-REPLACEB-LEFTB.xlsx");
    Sheet sheet = book.getSheet("REPLACEB");
    assertEquals(
        "A\u6E2C\u660E\u6708\u5149\u662F\u5B57\u4E32",
        Ranges.range(sheet, "A1").getCellFormatText());
    assertEquals(
        "A\u6E2C\u660E\u6708\u5149 \u5B57\u4E32", Ranges.range(sheet, "A2").getCellFormatText());
    assertEquals(
        "A\u6E2C\u660E\u6708\u5149\u5B57\u4E32", Ranges.range(sheet, "A3").getCellFormatText());
    assertEquals("A\u6E2C\u660E\u6708\u5149 \u4E32", Ranges.range(sheet, "A4").getCellFormatText());
    assertEquals("A\u6E2C\u660E\u6708\u5149\u4E32", Ranges.range(sheet, "A5").getCellFormatText());
    assertEquals("A\u6E2C\u660E\u6708\u5149 ", Ranges.range(sheet, "A6").getCellFormatText());
    assertEquals("A\u6E2C\u660E\u6708\u5149", Ranges.range(sheet, "A7").getCellFormatText());
    assertEquals("A\u6E2C\u660E\u6708\u5149", Ranges.range(sheet, "A8").getCellFormatText());

    assertEquals("\u5E8A \u4F60\u597D\u55CE", Ranges.range(sheet, "C1").getCellFormatText());
    assertEquals(
        "\u5E8A \u4F60\u597D\u55CE\u660E\u6708\u5149",
        Ranges.range(sheet, "C2").getCellFormatText());
    assertEquals(
        "\u5E8A \u4F60\u597D\u55CE \u6708\u5149", Ranges.range(sheet, "C3").getCellFormatText());
    assertEquals(
        "\u5E8A \u4F60\u597D\u55CE\u6708\u5149", Ranges.range(sheet, "C4").getCellFormatText());
    assertEquals("\u5E8A \u4F60\u597D\u55CE \u5149", Ranges.range(sheet, "C5").getCellFormatText());
    assertEquals("\u5E8A \u4F60\u597D\u55CE\u5149", Ranges.range(sheet, "C6").getCellFormatText());
    assertEquals("\u5E8A \u4F60\u597D\u55CE ", Ranges.range(sheet, "C7").getCellFormatText());
    assertEquals("\u5E8A \u4F60\u597D\u55CE", Ranges.range(sheet, "C8").getCellFormatText());

    assertEquals("#VALUE!", Ranges.range(sheet, "E1").getCellFormatText());
    assertEquals("#VALUE!", Ranges.range(sheet, "E2").getCellFormatText());
    assertEquals("\u4F60\u597D\u55CE", Ranges.range(sheet, "E3").getCellFormatText());
    assertEquals(" ", Ranges.range(sheet, "E4").getCellFormatText());
    assertEquals("\u6E2C", Ranges.range(sheet, "E5").getCellFormatText());
    assertEquals("\u6E2C\u8A66", Ranges.range(sheet, "E6").getCellFormatText());

    assertEquals(
        "\u4F60\u597D\u55CE\u5E8A\u524D\u660E\u6708\u5149",
        Ranges.range(sheet, "G1").getCellFormatText());
    assertEquals(" \u4F60\u597D\u55CE", Ranges.range(sheet, "G2").getCellFormatText());
    assertEquals(
        "\u5E8A\u4F60\u597D\u55CE\u524D\u660E\u6708\u5149",
        Ranges.range(sheet, "G3").getCellFormatText());
    assertEquals("\u5E8A \u4F60\u597D\u55CE", Ranges.range(sheet, "G4").getCellFormatText());
    assertEquals(
        "\u5E8A\u524D\u4F60\u597D\u55CE\u660E\u6708\u5149",
        Ranges.range(sheet, "G5").getCellFormatText());
    assertEquals("\u5E8A\u524D \u4F60\u597D\u55CE", Ranges.range(sheet, "G6").getCellFormatText());
    assertEquals(
        "\u5E8A\u524D\u660E\u4F60\u597D\u55CE\u6708\u5149",
        Ranges.range(sheet, "G7").getCellFormatText());
    assertEquals(
        "\u5E8A\u524D\u660E \u4F60\u597D\u55CE", Ranges.range(sheet, "G8").getCellFormatText());
    assertEquals(
        "\u5E8A\u524D\u660E\u6708\u4F60\u597D\u55CE\u5149",
        Ranges.range(sheet, "G9").getCellFormatText());

    assertEquals("A \u660E\u6708\u5149", Ranges.range(sheet, "I1").getCellFormatText());
    assertEquals(
        "A \u660E\u6708\u5149\u662F\u5B57\u4E32", Ranges.range(sheet, "I2").getCellFormatText());
    assertEquals(
        "A \u660E\u6708\u5149 \u5B57\u4E32", Ranges.range(sheet, "I3").getCellFormatText());
    assertEquals("A \u660E\u6708\u5149\u5B57\u4E32", Ranges.range(sheet, "I4").getCellFormatText());
    assertEquals("A \u660E\u6708\u5149 \u4E32", Ranges.range(sheet, "I5").getCellFormatText());
    assertEquals("A \u660E\u6708\u5149\u4E32", Ranges.range(sheet, "I6").getCellFormatText());

    assertEquals("HelWhatlo World", Ranges.range(sheet, "K1").getCellFormatText());
    assertEquals("HelWhato World", Ranges.range(sheet, "K2").getCellFormatText());
    assertEquals("HelWhat World", Ranges.range(sheet, "K3").getCellFormatText());
    assertEquals("HelWhatWorld", Ranges.range(sheet, "K4").getCellFormatText());
    assertEquals("HelWhatorld", Ranges.range(sheet, "K5").getCellFormatText());
    assertEquals("HelWhatrld", Ranges.range(sheet, "K6").getCellFormatText());
    assertEquals("HelWhatld", Ranges.range(sheet, "K7").getCellFormatText());
    assertEquals("HelWhatd", Ranges.range(sheet, "K8").getCellFormatText());
  }
コード例 #22
0
 @Test
 public void testZSS547_DeleteSheet() {
   // there are Sheet1~4
   testZSS547_DeleteSheet(Util.loadBook(this, "book/547-sheet-index.xlsx"));
   testZSS547_DeleteSheet(Util.loadBook(this, "book/547-sheet-index.xls"));
 }