public void testRetrieveSingleton() { try { ObjectContentManager ocm = this.getObjectContentManager(); // --------------------------------------------------------------------------------------------------------- // Insert // --------------------------------------------------------------------------------------------------------- AnotherDescendant anotherDescendant = new AnotherDescendant(); anotherDescendant.setAnotherDescendantField("anotherDescendantValue"); anotherDescendant.setAncestorField("ancestorValue"); anotherDescendant.setPath("/test"); ocm.insert(anotherDescendant); ocm.save(); // --------------------------------------------------------------------------------------------------------- // Retrieve // --------------------------------------------------------------------------------------------------------- Interface result = (Interface) ocm.getObject("/test"); assertNotNull("Object is null", result); anotherDescendant = (AnotherDescendant) result; assertEquals("Descendant path is invalid", anotherDescendant.getPath(), "/test"); assertEquals( "Descendant ancestorField is invalid", anotherDescendant.getAncestorField(), "ancestorValue"); assertEquals( "Descendant descendantField is invalid", anotherDescendant.getAnotherDescendantField(), "anotherDescendantValue"); } catch (Exception e) { e.printStackTrace(); fail(); } }
public void testRetrieveCollection() { ObjectContentManager ocm = this.getObjectContentManager(); // --------------------------------------------------------------------------------------------------------- // Insert descendant objects // --------------------------------------------------------------------------------------------------------- Descendant descendant = new Descendant(); descendant.setDescendantField("descendantValue"); descendant.setAncestorField("ancestorValue"); descendant.setPath("/descendant1"); ocm.insert(descendant); descendant = new Descendant(); descendant.setDescendantField("descendantValue2"); descendant.setAncestorField("ancestorValue2"); descendant.setPath("/descendant2"); ocm.insert(descendant); SubDescendant subDescendant = new SubDescendant(); subDescendant.setDescendantField("descendantValue2"); subDescendant.setAncestorField("ancestorValue2"); subDescendant.setPath("/subdescendant"); subDescendant.setSubDescendantField("subdescendantvalue"); ocm.insert(subDescendant); subDescendant = new SubDescendant(); subDescendant.setDescendantField("descendantValue3"); subDescendant.setAncestorField("ancestorValue2"); subDescendant.setPath("/subdescendant2"); subDescendant.setSubDescendantField("subdescendantvalue1"); ocm.insert(subDescendant); AnotherDescendant anotherDescendant = new AnotherDescendant(); anotherDescendant.setAnotherDescendantField("anotherDescendantValue"); anotherDescendant.setAncestorField("ancestorValue3"); anotherDescendant.setPath("/anotherdescendant1"); ocm.insert(anotherDescendant); anotherDescendant = new AnotherDescendant(); anotherDescendant.setAnotherDescendantField("anotherDescendantValue"); anotherDescendant.setAncestorField("ancestorValue4"); anotherDescendant.setPath("/anotherdescendant2"); ocm.insert(anotherDescendant); anotherDescendant = new AnotherDescendant(); anotherDescendant.setAnotherDescendantField("anotherDescendantValue2"); anotherDescendant.setAncestorField("ancestorValue5"); anotherDescendant.setPath("/anotherdescendant3"); ocm.insert(anotherDescendant); Atomic a = new Atomic(); a.setPath("/atomic"); a.setBooleanPrimitive(true); ocm.insert(a); ocm.save(); // --------------------------------------------------------------------------------------------------------- // Retrieve Descendant class (implements Interface.class) // --------------------------------------------------------------------------------------------------------- QueryManager queryManager = ocm.getQueryManager(); Filter filter = queryManager.createFilter(Interface.class); Query query = queryManager.createQuery(filter); Collection result = ocm.getObjects(query); assertEquals("Invalid number of interface found", result.size(), 3); assertTrue( "Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class)); assertTrue( "Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class)); assertTrue( "Invalid item in the collection", this.contains(result, "/anotherdescendant3", AnotherDescendant.class)); // --------------------------------------------------------------------------------------------------------- // Retrieve Descendant class and its children (implements AnotherInterface.class) // --------------------------------------------------------------------------------------------------------- queryManager = ocm.getQueryManager(); filter = queryManager.createFilter(AnotherInterface.class); query = queryManager.createQuery(filter); result = ocm.getObjects(query); assertEquals("Invalid number of interface found", result.size(), 4); assertTrue( "Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class)); assertTrue( "Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class)); assertTrue( "Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class)); assertTrue( "Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class)); }