Package com.orientechnologies.orient.test.domain.base

Examples of com.orientechnologies.orient.test.domain.base.JavaAttachDetachTestClass


    }
  }

  @Test(dependsOnMethods = "clean")
  public void testAttachDetach() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    attach.testTransient = "11";
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertTrue(!doc.containsField("testStatic"));
    Assert.assertTrue(!doc.containsField("testTransient"));
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    database.detach(loadedJavaObj);
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
    Assert.assertEquals(loadedJavaObj.floatSimple, 123.45f);
View Full Code Here


    Assert.assertEquals(loadedJavaObj.enumMap.get("2"), EnumTest.ENUM3);
  }

  @Test(dependsOnMethods = "testAttachDetach")
  public void testDetachAll() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    database.detachAll(loadedJavaObj, false);
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
    Assert.assertEquals(loadedJavaObj.floatSimple, 123.45f);
View Full Code Here

    Assert.assertEquals(loadedJavaObj.enumMap.get("2"), EnumTest.ENUM3);
  }

  @Test(dependsOnMethods = "testDetachAll")
  public void testNonProxiedAttachDetach() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    loadedJavaObj = database.detach(loadedJavaObj, true);
    Assert.assertTrue(!(loadedJavaObj instanceof Proxy));
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
View Full Code Here

    Assert.assertTrue(serializedDoc.hasSameContentOf(doc));
  }

  @Test(dependsOnMethods = "testNonProxiedAttachDetach")
  public void testDetachAllNonProxied() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    loadedJavaObj = database.detachAll(loadedJavaObj, true);
    Assert.assertTrue(!(loadedJavaObj instanceof Proxy));
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
View Full Code Here

      database.close();
    }
  }

  public void testAttachDetach() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    attach.testTransient = "11";
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertTrue(!doc.containsField("testStatic"));
    Assert.assertTrue(!doc.containsField("testTransient"));
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    database.detach(loadedJavaObj);
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
    Assert.assertEquals(loadedJavaObj.floatSimple, 123.45f);
View Full Code Here

    Assert.assertEquals(loadedJavaObj.enumMap.get("1"), EnumTest.ENUM2);
    Assert.assertEquals(loadedJavaObj.enumMap.get("2"), EnumTest.ENUM3);
  }

  public void testAttachDetachJavaInstances() {
    JavaAttachDetachTestClass attach = new JavaAttachDetachTestClass();
    attach.setText("xxx");
    attach = database.save(attach);
    attach = database.detach(attach, true);
    Assert.assertEquals(attach.getText(), "xxx");

    JavaAttachDetachTestClass second = new JavaAttachDetachTestClass();
    second.setText("xxx");
    second = database.save(second);
    Assert.assertEquals(second.getText(), "xxx");
    second.setText("yyy");
    second = database.save(second);
    second = database.detach(second, true);
    Assert.assertEquals(second.getText(), "yyy"); // this line throws an NPE, because getValue()
  }
View Full Code Here

    second = database.detach(second, true);
    Assert.assertEquals(second.getText(), "yyy"); // this line throws an NPE, because getValue()
  }

  public void testDetachAll() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    database.detachAll(loadedJavaObj, false);
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
    Assert.assertEquals(loadedJavaObj.floatSimple, 123.45f);
View Full Code Here

    Assert.assertEquals(loadedJavaObj.enumMap.get("1"), EnumTest.ENUM2);
    Assert.assertEquals(loadedJavaObj.enumMap.get("2"), EnumTest.ENUM3);
  }

  public void testNonProxiedAttachDetach() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    loadedJavaObj = database.detach(loadedJavaObj, true);
    Assert.assertTrue(!(loadedJavaObj instanceof Proxy));
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
View Full Code Here

    Assert.assertTrue(serializedDoc.equals(doc));
    Assert.assertTrue(serializedDoc.hasSameContentOf(doc));
  }

  public void testDetachAllNonProxied() {
    JavaAttachDetachTestClass attach = database.newInstance(JavaAttachDetachTestClass.class);
    attach.text = "test";
    attach.numberSimple = 12345;
    attach.doubleSimple = 12.34d;
    attach.floatSimple = 123.45f;
    attach.longSimple = 12345678l;
    attach.byteSimple = (byte) 1;
    attach.flagSimple = true;
    attach.enumeration = EnumTest.ENUM1;
    Child c = database.newInstance(Child.class);
    c.setName("Jesus");

    attach.children = new HashMap<String, Child>();
    attach.children.put("first", c);

    attach.enumList = new ArrayList<EnumTest>();
    attach.enumList.add(EnumTest.ENUM1);
    attach.enumList.add(EnumTest.ENUM2);

    attach.enumSet = new HashSet<EnumTest>();
    attach.enumSet.add(EnumTest.ENUM1);
    attach.enumSet.add(EnumTest.ENUM3);

    attach.enumMap = new HashMap<String, EnumTest>();
    attach.enumMap.put("1", EnumTest.ENUM2);
    attach.enumMap.put("2", EnumTest.ENUM3);
    database.attach(attach);
    ODocument doc = database.getRecordByUserObject(attach, false);
    Assert.assertEquals(doc.field("text"), "test");
    Assert.assertEquals(doc.field("numberSimple"), 12345);
    Assert.assertEquals(doc.field("doubleSimple"), 12.34d);
    Assert.assertEquals(doc.field("floatSimple"), 123.45f);
    Assert.assertEquals(doc.field("longSimple"), 12345678l);
    Assert.assertEquals(doc.field("byteSimple"), (byte) 1);
    Assert.assertEquals(doc.field("flagSimple"), true);
    Assert.assertEquals(doc.field("enumeration"), EnumTest.ENUM1.toString());
    Assert.assertTrue(doc.field("children") instanceof Map<?, ?>);
    Assert.assertTrue(((Map<?, ?>) doc.field("children")).get("first") instanceof ODocument);
    Assert.assertEquals(((ODocument) ((Map<?, ?>) doc.field("children")).get("first")).field("name"), "Jesus");
    Assert.assertEquals(((List<?>) doc.field("enumList")).size(), 2);
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(0), EnumTest.ENUM1.toString());
    Assert.assertEquals(((List<?>) doc.field("enumList")).get(1), EnumTest.ENUM2.toString());

    Assert.assertEquals(((Set<?>) doc.field("enumSet")).size(), 2);
    Iterator<?> it = ((Set<?>) doc.field("enumSet")).iterator();
    Assert.assertEquals(it.next(), EnumTest.ENUM1.toString());
    Assert.assertEquals(it.next(), EnumTest.ENUM3.toString());

    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).size(), 2);
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("1"), EnumTest.ENUM2.toString());
    Assert.assertEquals(((Map<?, ?>) doc.field("enumMap")).get("2"), EnumTest.ENUM3.toString());

    JavaAttachDetachTestClass savedJavaObj = database.save(attach);

    ORecordId id = (ORecordId) database.getRecordByUserObject(savedJavaObj, false).getIdentity();
    database.close();

    database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    JavaAttachDetachTestClass loadedJavaObj = (JavaAttachDetachTestClass) database.load(id);
    loadedJavaObj = database.detachAll(loadedJavaObj, true);
    Assert.assertTrue(!(loadedJavaObj instanceof Proxy));
    Assert.assertEquals(loadedJavaObj.text, "test");
    Assert.assertEquals(loadedJavaObj.numberSimple, 12345);
    Assert.assertEquals(loadedJavaObj.doubleSimple, 12.34d);
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.test.domain.base.JavaAttachDetachTestClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.