예제 #1
0
 public void testWriteBigDepartment() throws Exception {
   InterMineObject o = new BigDepartment();
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Department.class);
     if (!(o instanceof BigDepartment)) {
       fail("Expected a BigDepartment back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #2
0
 public void testWriteCleaner() throws Exception {
   InterMineObject o = new Cleaner();
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof Cleaner)) {
       fail("Expected a Cleaner back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #3
0
  public void testAddToCollection() throws Exception {
    Company c1 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    Contractor c2 = new Contractor();
    c1.setName("Michael");
    c2.setName("Albert");

    try {
      writer.store(c1);
      writer.store(c2);

      Company c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(0, c3.getContractors().size());

      writer.addToCollection(c1.getId(), Company.class, "contractors", c2.getId());

      c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(1, c3.getContractors().size());
      assertTrue(c3.getContractors().iterator().next() instanceof Contractor);
      assertEquals(c2.getId(), ((Contractor) c3.getContractors().iterator().next()).getId());
    } finally {
      writer.delete(c1);
      writer.delete(c2);
    }
  }
예제 #4
0
 public void testWriteCloneable() throws Exception {
   InterMineObject o =
       (InterMineObject)
           DynamicUtil.createObject(
               new HashSet(Arrays.asList(new Class[] {Employee.class, Cloneable.class})));
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof Cloneable)) {
       fail("Expected a Cloneable back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #5
0
  public void testWriteBatchingAndGetObject() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.beginTransaction();
      writer.store(address1);
      assertNotNull(writer.getObjectById(address1.getId(), Address.class));
    } finally {
      if (writer.isInTransaction()) {
        writer.abortTransaction();
      }
    }
  }
예제 #6
0
 public void testWriteDynamicObject2() throws Exception {
   InterMineObject o =
       (InterMineObject)
           DynamicUtil.createObject(
               new HashSet(Arrays.asList(new Class[] {ImportantPerson.class, Employee.class})));
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof ImportantPerson)) {
       fail("Expected an ImportantPerson back");
     }
     if (!(o instanceof Employee)) {
       fail("Expected an Employee back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #7
0
  public void testTransactionsAndCaches() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");
    Address address2 = new Address();
    address2.setAddress("Address 2");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.store(address1);
      Integer id = address1.getId();
      address2.setId(id);

      assertNull(realOs.pilferObjectById(id));
      assertNull(writer.pilferObjectById(id));

      assertNotNull("Looked for id " + id, realOs.getObjectById(id, Address.class));
      assertNull(writer.pilferObjectById(id));
      assertNotNull(realOs.pilferObjectById(id));
      realOs.flushObjectById();

      assertNotNull(writer.getObjectById(id, Address.class));
      assertNotNull(writer.pilferObjectById(id));
      assertNull(realOs.pilferObjectById(id));
      assertNotNull(realOs.getObjectById(id, Address.class));

      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.delete(address2);
      assertNull(writer.getObjectById(id, Address.class));
      assertNull(realOs.getObjectById(id, Address.class));

      writer.store(address1);
      writer.beginTransaction();
      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 1", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.commitTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.beginTransaction();
      writer.delete(address1);
      assertNull(writer.getObjectById(id, Address.class));
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.abortTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());
    } finally {
      writer.delete(address1);
    }
  }