You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2013/11/10 23:26:08 UTC

git commit: updated refs/heads/master to f629d40

Updated Branches:
  refs/heads/master a35425eec -> f629d405e


Test for DbUtil

test cases for
- isPersistable
- getColumnName

Signed-off-by: Laszlo Hornyak <la...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f629d405
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f629d405
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f629d405

Branch: refs/heads/master
Commit: f629d405eb26087d79894e8b443809eb706b7941
Parents: a35425e
Author: Laszlo Hornyak <la...@gmail.com>
Authored: Sun Nov 10 23:24:01 2013 +0100
Committer: Laszlo Hornyak <la...@gmail.com>
Committed: Sun Nov 10 23:24:01 2013 +0100

----------------------------------------------------------------------
 .../db/test/com/cloud/utils/DbUtilTest.java     | 65 ++++++++++++++++++++
 1 file changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f629d405/framework/db/test/com/cloud/utils/DbUtilTest.java
----------------------------------------------------------------------
diff --git a/framework/db/test/com/cloud/utils/DbUtilTest.java b/framework/db/test/com/cloud/utils/DbUtilTest.java
new file mode 100644
index 0000000..1eab769
--- /dev/null
+++ b/framework/db/test/com/cloud/utils/DbUtilTest.java
@@ -0,0 +1,65 @@
+package com.cloud.utils;
+
+import javax.persistence.Column;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.cloud.utils.db.DbUtil;
+
+public class DbUtilTest {
+
+    static class Testbean {
+        String noAnnotation;
+        @Column()
+        String withAnnotation;
+        @Column(name = "surprise")
+        String withAnnotationAndName;
+    }
+
+    @Test
+    public void getColumnName() throws SecurityException, NoSuchFieldException {
+        // if no annotation, then the field name
+        Assert.assertEquals("noAnnotation", DbUtil.getColumnName(Testbean.class
+                .getDeclaredField("noAnnotation")));
+        // there is annotation with name, take the name
+        Assert.assertEquals("surprise", DbUtil.getColumnName(Testbean.class
+                .getDeclaredField("withAnnotationAndName")));
+    }
+
+    @Test
+    @Ignore
+    public void getColumnNameWithAnnotationButWithoutNameAttribute()
+            throws SecurityException, NoSuchFieldException {
+        // there is annotation, but no name defined, fallback to field name
+        // this does not work this way, it probably should
+        Assert.assertEquals("withAnnotation", DbUtil
+                .getColumnName(Testbean.class
+                        .getDeclaredField("withAnnotation")));
+
+    }
+
+    static class IsPersistableTestBean {
+        static final String staticFinal = "no";
+        final String justFinal = "no";
+        transient String transientField;
+        transient static String strange = "";
+        String instanceField;
+    }
+
+    @Test
+    public void isPersistable() throws SecurityException, NoSuchFieldException {
+        Assert.assertFalse(DbUtil.isPersistable(IsPersistableTestBean.class
+                .getDeclaredField("staticFinal")));
+        Assert.assertFalse(DbUtil.isPersistable(IsPersistableTestBean.class
+                .getDeclaredField("justFinal")));
+        Assert.assertFalse(DbUtil.isPersistable(IsPersistableTestBean.class
+                .getDeclaredField("transientField")));
+        Assert.assertFalse(DbUtil.isPersistable(IsPersistableTestBean.class
+                .getDeclaredField("strange")));
+        Assert.assertTrue(DbUtil.isPersistable(IsPersistableTestBean.class
+                .getDeclaredField("instanceField")));
+    }
+
+}