public void testAddNewHierarchy() throws Exception { final String currentSupplierName = "supplier" + System.currentTimeMillis(); final Date orderDate = new Date(); final Float orderDetailPrice = 10.5F; { msg("Open session & local transaction"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction); file = pushTransaction.getFile(); CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath)); msg("Create a new element"); Supplier supplier = getModel1Factory().createSupplier(); supplier.setName(currentSupplierName); resource.getContents().add(supplier); msg("Create a new child"); PurchaseOrder order = getModel1Factory().createPurchaseOrder(); order.setDate(orderDate); supplier.getPurchaseOrders().add(order); resource.getContents().add(order); OrderDetail detail = getModel1Factory().createOrderDetail(); detail.setPrice(orderDetailPrice); order.getOrderDetails().add(detail); msg("Commit"); pushTransaction.commit(); session.close(); } { msg("Reload previous local session"); CDOSession session = openSession(); CDOTransaction transaction = session.openTransaction(); CDOPushTransaction pushTransaction = openPushTransaction(transaction, file); assertEquals(true, transaction.isDirty()); assertEquals(1, transaction.getRevisionDeltas().size()); CDOResource resource = transaction.getOrCreateResource(getResourcePath(resourcePath)); assertEquals(4, resource.getContents().size()); push(transaction, pushTransaction); session.close(); } CDOSession session = openSession(); CDOView view = session.openView(); CDOResource resource = view.getResource(getResourcePath(resourcePath)); assertEquals(4, resource.getContents().size()); Supplier supplier = (Supplier) resource.getContents().get(2); assertEquals(currentSupplierName, supplier.getName()); assertEquals(1, supplier.getPurchaseOrders().size()); PurchaseOrder order = supplier.getPurchaseOrders().get(0); assertNotNull(order); assertEquals(orderDate, order.getDate()); assertEquals(1, order.getOrderDetails().size()); OrderDetail detail = order.getOrderDetails().get(0); assertNotNull(detail); assertEquals(orderDetailPrice, detail.getPrice()); }
public void testNullReference() throws Exception { { msg("Opening session"); CDOSession session = openSession(); msg("Opening transaction"); CDOTransaction transaction = session.openTransaction(); msg("Creating resource"); CDOResource resource = transaction.createResource(getResourcePath("/test1")); msg("Creating orderDetail"); OrderDetail orderDetail = getModel1Factory().createOrderDetail(); msg("Setting price"); orderDetail.setPrice(4.75f); msg("Adding orderDetail"); resource.getContents().add(orderDetail); msg("Committing"); transaction.commit(); session.close(); } msg("Opening session"); CDOSession session = openSession(); msg("Opening transaction"); CDOTransaction transaction = session.openTransaction(); msg("Getting resource"); CDOResource resource = transaction.getResource(getResourcePath("/test1")); msg("Getting contents"); EList<EObject> contents = resource.getContents(); msg("Getting supplier"); OrderDetail orderDetail = (OrderDetail) contents.get(0); assertNotNull(orderDetail); msg("Verifying price"); assertEquals(4.75f, orderDetail.getPrice()); msg("Verifying product"); assertEquals(null, orderDetail.getProduct()); }