Exemplo n.º 1
0
  /**
   * Returns an exception string for a wrong key.
   *
   * @param key property key
   * @param found found value
   * @param allowed allowed values
   * @return exception
   * @throws SerializerException serializer exception
   */
  public static SerializerException error(
      final Object key, final String found, final String... allowed) throws SerializerException {

    final TokenBuilder tb = new TokenBuilder();
    tb.addExt(SERVAL, key, allowed[0]);
    for (int a = 1; a < allowed.length; ++a) tb.addExt(SERVAL2, allowed[a]);
    tb.addExt(SERVAL3, found);
    throw SERANY.thrwSerial(tb);
  }
Exemplo n.º 2
0
  /**
   * Compares results.
   *
   * @param expected expected result
   * @param returned returned result
   * @throws Exception exception
   */
  private static void compare(final ItemList expected, final ItemList returned) throws Exception {

    // Compare response with expected result
    assertEquals("Different number of results", expected.size(), returned.size());

    final long es = expected.size();
    for (int e = 0; e < es; e++) {
      final Item exp = expected.get(e), ret = returned.get(e);
      if (!new DeepEqual().equal(exp, ret)) {
        final TokenBuilder tb = new TokenBuilder("Result ").addLong(e).add(" differs:\nReturned: ");
        tb.addExt(ret.serialize()).add("\nExpected: ").addExt(exp.serialize());
        fail(tb.toString());
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Returns a string representation of the index structure.
  *
  * @param all include database contents in the representation. During updates, database lookups
  *     must be avoided, as the data structures will be inconsistent.
  * @return string
  */
 public String toString(final boolean all) {
   final TokenBuilder tb = new TokenBuilder();
   tb.addExt(type).add(" INDEX, '").add(data.meta.name).add("':\n");
   final int s = lenList.size();
   for (int m = 1; m < s; m++) {
     final int len = lenList.get(m);
     if (len == 0) continue;
     final int[] ids = idsList.get(m);
     tb.add("  ").addInt(m);
     if (all)
       tb.add(", key: \"").add(data.text(data.pre(ids[0]), type == IndexType.TEXT)).add('"');
     tb.add(", ids");
     if (all) tb.add("/pres");
     tb.add(": ");
     for (int n = 0; n < len; n++) {
       if (n != 0) tb.add(",");
       tb.addInt(ids[n]);
       if (all) tb.add('/').addInt(data.pre(ids[n]));
     }
     tb.add("\n");
   }
   return tb.toString();
 }
Exemplo n.º 4
0
 /**
  * Throws a runtime exception for an unimplemented method.
  *
  * @param ext optional extension
  * @return runtime exception (indicates that an error is raised)
  */
 public static RuntimeException notimplemented(final Object... ext) {
   final TokenBuilder tb = new TokenBuilder("Not Implemented");
   if (ext.length != 0) tb.addExt(" (%)", ext);
   throw new UnsupportedOperationException(tb.add('.').toString());
 }
Exemplo n.º 5
0
 /**
  * Throws a runtime exception for an unexpected exception.
  *
  * @param ext optional extension
  * @return runtime exception (indicates that an error is raised)
  */
 public static RuntimeException notexpected(final Object... ext) {
   final TokenBuilder tb = new TokenBuilder();
   tb.addExt("%", ext.length == 0 ? "Not Expected." : ext[0]);
   throw new RuntimeException(tb.toString());
 }