use of org.jpox.samples.one_many.unidir.DesktopComputer in project tests by datanucleus.
the class ReplicationTest method testReplicateCleanToODF.
/**
* Test that creates an Office+Computer(x2) in PMF1, replicates this to PMF2.
*/
public void testReplicateCleanToODF() {
try {
// Create RDBMS data
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object office1Id;
try {
tx.begin();
Office office1 = new Office("Head Office");
LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
office1.addComputer(laptop1);
DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
office1.addComputer(desktop1);
pm.makePersistent(office1);
office1Id = pm.getObjectId(office1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
JDOReplicationManager replicator = new JDOReplicationManager(pmf, pmf2);
replicator.replicate(office1Id);
pm = pmf2.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office office1 = (Office) pm.getObjectById(office1Id);
assertNotNull(office1);
assertEquals("Office name is incorrect", "Head Office", office1.getName());
assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(pmf, Office.class);
clean(pmf, LaptopComputer.class);
clean(pmf, DesktopComputer.class);
clean(pmf2, Office.class);
clean(pmf2, LaptopComputer.class);
clean(pmf2, DesktopComputer.class);
}
}
use of org.jpox.samples.one_many.unidir.DesktopComputer in project tests by datanucleus.
the class ReplicationTest method testReplicateCleanAllToODF.
/**
* Test that creates an Office+Computer(x2) in PMF1, replicates using all registered classes this to PMF2.
*/
public void testReplicateCleanAllToODF() {
try {
// Create RDBMS data
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object office1Id;
try {
tx.begin();
Office office1 = new Office("Head Office");
LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
office1.addComputer(laptop1);
DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
office1.addComputer(desktop1);
pm.makePersistent(office1);
office1Id = pm.getObjectId(office1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
JDOReplicationManager replicator = new JDOReplicationManager(pmf, pmf2);
replicator.replicateRegisteredClasses();
pm = pmf2.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office office1 = (Office) pm.getObjectById(office1Id);
assertNotNull(office1);
assertEquals("Office name is incorrect", "Head Office", office1.getName());
assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(pmf, Office.class);
clean(pmf, LaptopComputer.class);
clean(pmf, DesktopComputer.class);
clean(pmf2, Office.class);
clean(pmf2, LaptopComputer.class);
clean(pmf2, DesktopComputer.class);
}
}
use of org.jpox.samples.one_many.unidir.DesktopComputer in project tests by datanucleus.
the class ReplicationTest method testReplicatePartialFromODF.
/**
* Test that creates an Office+Computer in PMF1, and Office+Computer(x2) in PMF2.
* Then replicates from PMF2 to PMF1 and checks that the other Computer is replicated.
*/
public void testReplicatePartialFromODF() throws IOException {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object office1Id;
try {
tx.begin();
Office office1 = new Office("Head Office");
LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
office1.addComputer(laptop1);
pm.makePersistent(office1);
office1Id = pm.getObjectId(office1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf2.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office office1 = new Office("Head Office");
LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
office1.addComputer(laptop1);
DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
office1.addComputer(desktop1);
pm.makePersistent(office1);
office1Id = pm.getObjectId(office1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
JDOReplicationManager replicator = new JDOReplicationManager(pmf2, pmf);
replicator.replicate(office1Id);
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office office1 = (Office) pm.getObjectById(office1Id);
assertNotNull(office1);
assertEquals("Office name is incorrect", "Head Office", office1.getName());
assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(pmf, Office.class);
clean(pmf, LaptopComputer.class);
clean(pmf, DesktopComputer.class);
clean(pmf2, Office.class);
clean(pmf2, LaptopComputer.class);
clean(pmf2, DesktopComputer.class);
}
}
use of org.jpox.samples.one_many.unidir.DesktopComputer in project tests by datanucleus.
the class ReplicationTest method testReplicateCleanFromODF.
/**
* Test that creates an Office+Computer(x2) in PMF2, replicates this to PMF1.
*/
public void testReplicateCleanFromODF() throws IOException {
try {
PersistenceManager pm = pmf2.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object office1Id;
try {
tx.begin();
Office office1 = new Office("Head Office");
LaptopComputer laptop1 = new LaptopComputer("192.168.0.2", "Linux", 4, 0);
office1.addComputer(laptop1);
DesktopComputer desktop1 = new DesktopComputer("192.168.0.3", "Windows XP", 1);
office1.addComputer(desktop1);
pm.makePersistent(office1);
office1Id = pm.getObjectId(office1);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
JDOReplicationManager replicator = new JDOReplicationManager(pmf2, pmf);
replicator.replicate(office1Id);
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office office1 = (Office) pm.getObjectById(office1Id);
assertNotNull(office1);
assertEquals("Office name is incorrect", "Head Office", office1.getName());
assertEquals("Number of computers is incorrect", 2, office1.getNumberOfComputers());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(pmf, Office.class);
clean(pmf, LaptopComputer.class);
clean(pmf, DesktopComputer.class);
clean(pmf2, Office.class);
clean(pmf2, LaptopComputer.class);
clean(pmf2, DesktopComputer.class);
}
}
use of org.jpox.samples.one_many.unidir.DesktopComputer in project tests by datanucleus.
the class ApplicationIdPersistenceTest method testPersistOneToManyUni.
/**
* Test of persist of 1-N UNIDIR relation (PC field).
*/
public void testPersistOneToManyUni() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object officeId = null;
try {
tx.begin();
Office office = new Office("theOffice");
LaptopComputer macBook = new LaptopComputer("192.168.1.1", "MACOSX", 4, 0);
macBook.setId(1);
office.addComputer(macBook);
DesktopComputer dell = new DesktopComputer("192.168.1.2", "Windows", 2);
dell.setId(2);
office.addComputer(dell);
pm.makePersistent(office);
tx.commit();
officeId = pm.getObjectId(office);
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown persisting data " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Check data
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Office theOffice = (Office) pm.getObjectById(officeId);
assertEquals("Office name retrieved is incorrect", "theOffice", theOffice.getName());
assertEquals("Office computers size retrieved is incorrect", 2, theOffice.getNumberOfComputers());
Iterator iterator = theOffice.getComputers().iterator();
while (iterator.hasNext()) {
Computer computer = (Computer) iterator.next();
if (computer instanceof LaptopComputer) {
LaptopComputer laptop = (LaptopComputer) computer;
assertEquals("Laptop id retrieved is incorrect", 1, laptop.getId());
assertEquals("Laptop ip retrieved is incorrect", "192.168.1.1", laptop.getIpAddress());
assertEquals("Laptop OperatingSystem retrieved is incorrect", "MACOSX", laptop.getOperatingSystem());
assertEquals("Laptop BatteryLife retrieved is incorrect", 4, laptop.getBatteryLife());
assertEquals("Laptop NumberOfPcmcia retrieved is incorrect", 0, laptop.getNumberOfPcmcia());
} else if (computer instanceof DesktopComputer) {
DesktopComputer desktop = (DesktopComputer) computer;
assertEquals("Desktop id retrieved is incorrect", 2, desktop.getId());
assertEquals("Desktop ip retrieved is incorrect", "192.168.1.2", desktop.getIpAddress());
assertEquals("Desktop Operating System retrieved is incorrect", "Windows", desktop.getOperatingSystem());
assertEquals("Desktop NumberOfProcessors retrieved is incorrect", 2, desktop.getNumberOfProcessors());
}
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown retrieving data " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out data
clean(Office.class);
clean(Computer.class);
}
}
Aggregations