示例#1
0
  @Test
  public void setTargetInModel() {
    final A[] as = new A[] {new A()};

    IModel<A> target =
        new IModel<A>() {

          @Override
          public A getObject() {
            return as[0];
          }

          @Override
          public void setObject(A a) {
            as[0] = a;
          }

          @Override
          public void detach() {}
        };

    LazyModel<A> model = model(from(target));

    assertEquals(A.class, model.getObjectClass());
    assertEquals("", model.getPath());

    A a = new A();

    model.setObject(a);

    assertEquals(a, as[0]);
  }
示例#2
0
  @Test
  public void bindToObject() {
    final A a = new A();
    a.b = new B();

    LazyModel<B> model = model(from(A.class).getB()).bind(a);

    assertEquals(B.class, model.getObjectClass());
    assertEquals("b", model.getPath());
    assertEquals(a.b, model.getObject());
  }
示例#3
0
  @Test
  public void getTarget() {
    A a = new A();

    LazyModel<A> model = model(from(a));

    assertEquals(A.class, model.getObjectClass());
    assertEquals("", model.getPath());

    assertEquals(a, model.getObject());
  }
示例#4
0
  @Test
  public void getIntFromNull() {
    A a = new A();

    LazyModel<Character> model = model(from(a).getB().getCharacter());

    assertEquals(Character.TYPE, model.getObjectClass());
    assertEquals("b.character", model.getPath());

    assertEquals(null, model.getObject());
  }
示例#5
0
  @Test
  public void getOutOfBoundsFromGenericList() {
    B b = new B();

    LazyModel<C> model = model(from(b).getCs().get(0));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("cs.get(i)", model.getPath());

    assertEquals(null, model.getObject());
  }
示例#6
0
  @Test
  public void getFromPrivateConstructor() {
    final A a = new A();
    a.p = P.P1;

    LazyModel<String> model = model(from(a).getP().getString());

    assertEquals(String.class, model.getObjectClass());
    assertEquals("p.string", model.getPath());

    assertEquals(a.p.getString(), model.getObject());
  }
示例#7
0
  @Test
  public void getEnum() {
    final A a = new A();
    a.e = E.E1;

    LazyModel<E> model = model(from(a).getE());

    assertEquals(E.class, model.getObjectClass());
    assertEquals("e", model.getPath());

    assertEquals(a.e, model.getObject());
  }
示例#8
0
  @Test
  public void getFinal() {
    final A a = new A();
    a.f = new F();

    LazyModel<F> model = model(from(a).getF());

    assertEquals(F.class, model.getObjectClass());
    assertEquals("f", model.getPath());

    assertEquals(a.f, model.getObject());
  }
示例#9
0
  @Test
  public void getRawList() {
    B b = new B();
    b.cs.add(new C());

    LazyModel<Object> model = model(from(b).getRs().get(0));

    assertEquals(Object.class, model.getObjectClass());
    assertEquals("rs.get(i)", model.getPath());

    assertEquals(b.cs.get(0), model.getObject());
  }
示例#10
0
  @Test
  public void getObject() {
    A a = new A();

    a.b = new B();

    LazyModel<B> model = model(from(a).getB());

    assertEquals(B.class, model.getObjectClass());
    assertEquals("b", model.getPath());

    assertEquals(a.b, model.getObject());
  }
示例#11
0
  @Test
  public void setInt() {
    A a = new A();

    LazyModel<Integer> model = model(from(a).getInteger());

    assertEquals(Integer.TYPE, model.getObjectClass());
    assertEquals("integer", model.getPath());

    model.setObject(Integer.valueOf(42));

    assertEquals(42, a.integer);
  }
示例#12
0
  @Test
  public void setBoolean() {
    A a = new A();

    LazyModel<Boolean> model = model(from(a).isBool());

    assertEquals(Boolean.TYPE, model.getObjectClass());
    assertEquals("bool", model.getPath());

    model.setObject(Boolean.TRUE);

    assertEquals(true, a.bool);
  }
示例#13
0
  @Test
  public void getInherited() {
    final A a = new A();
    a.b = new B();
    a.b.d = new D();

    LazyModel<String> model = model(from(a).getB().getD().getString());

    assertEquals(String.class, model.getObjectClass());
    assertEquals("b.d.string", model.getPath());

    assertEquals(a.b.d.string, model.getObject());
  }
示例#14
0
  @Test
  public void bindToTypeErasedModelWithNull() {
    LazyModel<B> model = model(from(A.class).getB()).bind(new Model<A>(null));

    assertNull(model.getObjectType());
    assertNull(model.getObjectClass());

    try {
      model.getPath();

      fail();
    } catch (WicketRuntimeException ex) {
      assertEquals("cannot detect target type", ex.getMessage());
    }
  }
示例#15
0
  @Test
  public void setValueToGenericMap() {
    A a = new A();

    a.b = new B();

    LazyModel<String> model = model(from(a).getB().getStrings().get("key"));

    assertEquals(String.class, model.getObjectClass());
    assertEquals("b.strings.get(O)", model.getPath());

    model.setObject("value");

    assertEquals("value", a.b.strings.get("key"));
  }
示例#16
0
  @Test
  public void setCharacterOnNullFails() {
    A a = new A();

    LazyModel<Character> model = model(from(a).getB().getCharacter());

    assertEquals(Character.TYPE, model.getObjectClass());
    assertEquals("b.character", model.getPath());

    try {
      model.setObject('c');

      fail();
    } catch (NullPointerException expected) {
    }
  }
示例#17
0
  @Test
  public void setIntToNullFails() {
    A a = new A();

    LazyModel<Integer> model = model(from(a).getInteger());

    assertEquals(Integer.TYPE, model.getObjectClass());
    assertEquals("integer", model.getPath());

    try {
      model.setObject(null);

      fail();
    } catch (WicketRuntimeException expected) {
    }
  }
示例#18
0
  @Test
  public void setTargetFails() {
    A a = new A();

    LazyModel<A> model = model(from(a));

    assertEquals(A.class, model.getObjectClass());
    assertEquals("", model.getPath());

    try {
      model.setObject(new A());

      fail();
    } catch (UnsupportedOperationException expected) {
    }
  }
示例#19
0
  @Test
  public void getObjectFromGenericList() {
    A a = new A();
    a.b = new B();

    C c = new C();
    a.b.cs.add(c);

    c.string = "string";

    LazyModel<C> model = model(from(a).getB().getCs().get(0));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("b.cs.get(i)", model.getPath());

    assertEquals(c, model.getObject());
  }
示例#20
0
  @Test
  public void getWithNestedLazyModel() {
    A a = new A();
    a.integer = 0;

    B b = new B();

    C c = new C();
    b.cs.add(c);

    LazyModel<C> model = model(from(b).getC(from(a).getInteger()));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("getC(i)", model.getPath());

    assertEquals(c, model.getObject());
  }
示例#21
0
  @Test
  public void getObjectFromObjectClassAwareModel() {
    A a = new A();
    a.b = new B();

    C c = new C();
    a.b.cs.add(c);

    PropertyModel<B> target = new PropertyModel<B>(a, "b");

    LazyModel<C> model = model(from(target).getC(0));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("getC(i)", model.getPath());

    assertEquals(a.b.cs.get(0), model.getObject());
  }
示例#22
0
  @Test
  public void setObjectFromEntryFromGenericList() {
    A a = new A();
    a.b = new B();

    C c = new C();
    a.b.cs.add(c);

    LazyModel<String> model = model(from(a).getB().getC(0).getString());

    assertEquals(String.class, model.getObjectClass());
    assertEquals("b.getC(i).string", model.getPath());

    model.setObject("string");

    assertEquals("string", c.string);
  }
示例#23
0
  @Test
  public void bindToGenericModel() {
    final A a = new A();
    a.b = new B();

    LazyModel<B> model =
        model(from(A.class).getB())
            .bind(
                new AbstractReadOnlyModel<A>() {
                  @Override
                  public A getObject() {
                    return a;
                  }
                });

    assertEquals(B.class, model.getObjectClass());
    assertEquals("b", model.getPath());
    assertEquals(a.b, model.getObject());
  }
示例#24
0
  @Test
  public void getEntryFromGenericList() {
    final List<C> cs = new ArrayList<C>();

    C c = new C();
    cs.add(c);

    IModel<List<C>> target =
        new AbstractReadOnlyModel<List<C>>() {
          @Override
          public List<C> getObject() {
            return cs;
          }
        };

    LazyModel<C> model = model(from(target).get(0));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("get(i)", model.getPath());

    assertEquals(c, model.getObject());
  }
示例#25
0
  @Test
  public void getObjectFromGenericModel() {
    final A a = new A();
    a.b = new B();

    C c = new C();
    a.b.cs.add(c);

    IModel<A> target =
        new AbstractReadOnlyModel<A>() {
          @Override
          public A getObject() {
            return a;
          }
        };

    LazyModel<C> model = model(from(target).getB().getC(0));

    assertEquals(C.class, model.getObjectClass());
    assertEquals("b.getC(i)", model.getPath());

    assertEquals(a.b.cs.get(0), model.getObject());
  }