You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2014/02/20 20:17:15 UTC

[09/50] [abbrv] git commit: updated refs/heads/ui-restyle to c64bfa5

findbugs: check for system template id == -> equals()


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

Branch: refs/heads/ui-restyle
Commit: 15fa2ef8df10234ddaad81a3f164e45e64ebe7c0
Parents: 0d7a965
Author: Daan Hoogland <da...@onecht.net>
Authored: Tue Feb 11 12:22:53 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Fri Feb 14 18:37:47 2014 +0100

----------------------------------------------------------------------
 .../com/cloud/template/TemplateManagerImpl.java  | 16 ++++++++++------
 .../cloud/template/TemplateManagerImplTest.java  | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15fa2ef8/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 6d7eece..7466670 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1753,12 +1753,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             throw ex;
         }
 
-        // Don't allow to modify system template
-        if (id == Long.valueOf(1)) {
-            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
-            ex.addProxyObject(String.valueOf(id), "templateId");
-            throw ex;
-        }
+        verifyTemplateId(id);
 
         // do a permission check
         _accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template);
@@ -1835,6 +1830,15 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         return _tmpltDao.findById(id);
     }
 
+    void verifyTemplateId(Long id) {
+        // Don't allow to modify system template
+        if (id.equals(Long.valueOf(1))) {
+            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
+            ex.addProxyObject(String.valueOf(id), "templateId");
+            throw ex;
+        }
+    }
+
     @Override
     public String getConfigComponentName() {
         return TemplateManager.class.getSimpleName();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/15fa2ef8/server/test/com/cloud/template/TemplateManagerImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/template/TemplateManagerImplTest.java b/server/test/com/cloud/template/TemplateManagerImplTest.java
new file mode 100644
index 0000000..3788393
--- /dev/null
+++ b/server/test/com/cloud/template/TemplateManagerImplTest.java
@@ -0,0 +1,19 @@
+package com.cloud.template;
+
+import org.junit.Test;
+
+import com.cloud.exception.InvalidParameterValueException;
+
+public class TemplateManagerImplTest {
+
+    TemplateManagerImpl tmgr = new TemplateManagerImpl();
+
+    @Test(expected = InvalidParameterValueException.class)
+    public void testVerifyTemplateIdOfSystemTemplate() {
+        tmgr.verifyTemplateId(1L);
+    }
+
+    public void testVerifyTemplateIdOfNonSystemTemplate() {
+        tmgr.verifyTemplateId(1L);
+    }
+}