Exemple #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]);
  }
Exemple #2
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);
  }
Exemple #3
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);
  }
Exemple #4
0
  @Test
  public void setObject() {
    A a = new A();

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

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

    B b = new B();
    model.setObject(b);

    assertEquals(b, a.b);
  }
Exemple #5
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"));
  }
Exemple #6
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) {
    }
  }
Exemple #7
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) {
    }
  }
Exemple #8
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) {
    }
  }
Exemple #9
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);
  }
Exemple #10
0
  @Test
  public void setWithNestedLazyModel() {
    A a = new A();
    a.integer = 0;

    B b = new B();

    C c = new C();

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

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

    model.setObject(c);

    assertEquals(c, b.cs.get(0));
  }
Exemple #11
0
  @Test
  public void setEntryToGenericList() {
    final List<C> cs = new ArrayList<C>();
    cs.add(new 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());

    C c = new C();
    model.setObject(c);

    assertEquals(c, cs.get(0));
  }