1   package org.weda.store;
2   
3   import org.weda.test.WedaTestCase;
4   import org.weda.property.PropertyValue;
5   import org.weda.store.impl.ObjectSet;
6   import org.weda.domain.Address;
7   import org.weda.domain.Company;
8   
9   /**
10   *
11   * @author tim
12   */
13  public class ObjectSetTest extends WedaTestCase {
14      PropertyValue propertyValue;
15      
16      
17      public ObjectSetTest(String name) throws Exception {
18          super(name);
19      }
20      
21      public void setUp(){
22          propertyValue=(PropertyValue)registry.getService(PropertyValue.class);
23      }
24      
25      public void test() throws Exception {
26          Company c1 = new Company();
27          ObjectSet objectSet = 
28                  new ObjectSet(Company.class, new Object[]{c1}, propertyValue);
29          assertTrue(objectSet.isValueUnique("id"));
30          objectSet.setValue("id", 10l);
31          assertTrue(objectSet.isValueUnique("id"));
32          assertEquals(10l, objectSet.getValue("id"));
33          assertEquals(10l, c1.getId().intValue());
34          objectSet.setValue("address", new Address());
35          assertNotNull(objectSet.getValue("address"));
36          //
37          Company c2 = new Company();
38          objectSet = 
39                  new ObjectSet(Company.class, new Object[]{c1, c2}, propertyValue);
40          assertFalse(objectSet.isValueUnique("id"));
41          assertTrue(objectSet.isValueUnique("comment"));
42          objectSet.setValue("id", 2l);
43          assertEquals(2l, objectSet.getValue("id"));
44          assertEquals(c1.getId(), c2.getId());
45          assertTrue(objectSet.isValueUnique("id"));
46      }
47      
48  }