@Test
  public void Serialization() throws IOException, ClassNotFoundException {
    StringPath expr = Expressions.stringPath("str");
    metadata.addJoin(JoinType.DEFAULT, expr);
    metadata.addFlag(new QueryFlag(Position.AFTER_FILTERS, ""));
    metadata.addGroupBy(expr);
    metadata.addHaving(expr.isEmpty());
    //        metadata.getJoins().get(0).addFlag(new JoinFlag(""));
    metadata.addJoinCondition(expr.isEmpty());
    metadata.addOrderBy(expr.asc());
    metadata.setProjection(expr);
    metadata.addWhere(expr.isEmpty());

    QueryMetadata metadata2 = Serialization.serialize(metadata);

    assertEquals(metadata.getFlags(), metadata2.getFlags());
    assertEquals(metadata.getGroupBy().get(0), metadata2.getGroupBy().get(0));
    assertEquals(metadata.getGroupBy(), metadata2.getGroupBy());
    assertEquals(metadata.getHaving(), metadata2.getHaving());
    assertEquals(metadata.getJoins(), metadata2.getJoins());
    assertEquals(metadata.getModifiers(), metadata2.getModifiers());
    assertEquals(metadata.getOrderBy(), metadata2.getOrderBy());
    assertEquals(metadata.getParams(), metadata2.getParams());
    assertEquals(metadata.getProjection(), metadata2.getProjection());
    assertEquals(metadata.getWhere(), metadata2.getWhere());
  }
Пример #2
0
  @Test
  public void expressions() throws Exception {
    Map<Class<?>, Object> args = Maps.newHashMap();
    args.put(Object.class, "obj");
    args.put(BeanPath.class, new EntityPathBase<Object>(Object.class, "obj"));
    args.put(Class.class, Integer.class);
    args.put(Class[].class, new Class<?>[] {Object.class, Object.class});
    args.put(java.util.Date.class, new java.util.Date(0));
    args.put(java.sql.Date.class, new java.sql.Date(0));
    args.put(java.sql.Time.class, new java.sql.Time(0));
    args.put(java.sql.Timestamp.class, new java.sql.Timestamp(0));
    args.put(Expression.class, Expressions.enumPath(Gender.class, "e"));
    args.put(
        Expression[].class,
        new Expression<?>[] {Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s")});
    args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str")));
    args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num")));
    args.put(Number.class, 1);
    args.put(Operator.class, Ops.AND);
    args.put(Path.class, Expressions.stringPath("str"));
    args.put(PathBuilderValidator.class, PathBuilderValidator.DEFAULT);
    args.put(PathMetadata.class, PathMetadataFactory.forVariable("obj"));
    args.put(PathInits.class, PathInits.DEFAULT);
    args.put(Predicate.class, Expressions.path(Object.class, "obj").isNull());
    args.put(QueryMetadata.class, new DefaultQueryMetadata());
    args.put(String.class, "obj");

    Reflections reflections = new Reflections();
    Set<Class<? extends Expression>> types = reflections.getSubTypesOf(Expression.class);
    for (Class<?> type : types) {
      if (!type.isInterface()
          && !type.isMemberClass()
          && !Modifier.isAbstract(type.getModifiers())) {
        for (Constructor<?> c : type.getConstructors()) {
          Object[] parameters = new Object[c.getParameterTypes().length];
          for (int i = 0; i < c.getParameterTypes().length; i++) {
            parameters[i] =
                Objects.requireNonNull(
                    args.get(c.getParameterTypes()[i]), c.getParameterTypes()[i].getName());
          }
          c.setAccessible(true);
          Object o = c.newInstance(parameters);
          assertEquals(o, Serialization.serialize(o));
        }
      }
    }
  }
Пример #3
0
 @Test
 public void StringPathPathOfQString() {
   assertEquals(
       "variable.property",
       Expressions.stringPath(Expressions.path(Object.class, "variable"), "property").toString());
 }
Пример #4
0
 @Test
 public void StringPathString() {
   assertEquals("variable", Expressions.stringPath("variable").toString());
 }
Пример #5
0
 /**
  * Create a new variable path
  *
  * @param arg alias
  * @return expression
  */
 public static StringPath var(String arg) {
   return Expressions.stringPath(arg.replace(' ', '_'));
 }
Пример #6
0
 @Test
 public void order() {
   OrderSpecifier<?> order = new OrderSpecifier<String>(Order.ASC, Expressions.stringPath("str"));
   assertEquals(order, Serialization.serialize(order));
 }