@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(); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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")); }
@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()); }
@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()); }
@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); }
@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()); }
@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); }