Ejemplo n.º 1
0
  @Ignore("alias property not supported yet")
  public void testBwoValues() throws Exception {
    CompassSession session = openSession();

    A a = new A();
    a.id = 1;
    a.value = "value";
    B b = new B();
    b.value = "bvalue";
    b.value2 = "bvalue2";
    a.b = b;
    session.save(a);

    Resource resource = session.loadResource(A.class, 1);
    assertNotNull(resource);
    assertEquals(6, resource.getProperties().length);
    assertEquals("A", resource.getAlias());
    assertEquals(3, resource.getProperties("value").length);

    a = (A) session.load(A.class, 1);
    assertEquals(1, a.id.longValue());
    assertNull(a.value);
    assertNull(a.b);

    session.close();
  }
Ejemplo n.º 2
0
  @Test
  public void propertyReflectionAwareModelNoProperty() throws Exception {
    A a = new A();
    a.b = new B();

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

    assertNull(model.getPropertyField());
    assertNull(model.getPropertyGetter());
    assertNull(model.getPropertySetter());
  }
Ejemplo n.º 3
0
  @Test
  public void propertyReflectionAwareModel() throws Exception {
    A a = new A();
    a.b = new B();

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

    assertNull(model.getPropertyField());
    assertEquals(B.class.getMethod("getCharacter"), model.getPropertyGetter());
    assertEquals(B.class.getMethod("setCharacter", Character.TYPE), model.getPropertySetter());
  }
Ejemplo n.º 4
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());
  }
Ejemplo n.º 5
0
  @Test
  public void getGenericList() {
    A a = new A();
    a.b = new B();

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

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

    assertEquals(a.b.cs, model.getObject());
  }
Ejemplo n.º 6
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());
  }
Ejemplo n.º 7
0
  @Test
  public void getGenericMap() {
    A a = new A();

    a.b = new B();

    LazyModel<Map<String, String>> model = model(from(a).getB().getStrings());

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

    assertEquals(a.b.strings, model.getObject());
  }
Ejemplo n.º 8
0
  @Test
  public void getGenericListFromInterface() {
    A a = new A();

    a.b = new B();

    LazyModel<List<C>> model = model(from(a).getI().getTs());

    assertEquals(List.class, model.getObjectClass());
    assertEquals("i.ts", model.getPath());

    assertEquals(a.b.cs, model.getObject());
  }
Ejemplo n.º 9
0
  @Test
  public void getInterface() {
    A a = new A();

    a.b = new B();

    LazyModel<I<C>> model = model(from(a).getI());

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

    assertEquals(a.b, model.getObject());
  }
Ejemplo n.º 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());
  }
Ejemplo n.º 11
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"));
  }
Ejemplo n.º 12
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());
  }
Ejemplo n.º 13
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());
  }
Ejemplo n.º 14
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);
  }
Ejemplo n.º 15
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());
  }
Ejemplo n.º 16
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());
  }
	public static void changeA3(A sa,Map<Integer, A> map ){
		sa.b="aaaaaaaaaaaaaaa";
		System.out.println(map.get(1).b);
		
	}