Tal Nisan has uploaded a new change for review.

Change subject: core: Consolidated common test of add/update storage connection
......................................................................

core: Consolidated common test of add/update storage connection

AddStorageServerConnection and UpdateStorageServerConnection command tests
contained simiar tests, those common tests were extracted to a parent test
class for better readability and easier maintenance

Change-Id: Iad571ca0c5788c375200847e8872706a8dfd7f3e
Bug-Url: https://bugzilla.redhat.com/1129597
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommandTest.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageServerConnectionTestCommon.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommandTest.java
3 files changed, 148 insertions(+), 195 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/88/32488/1

diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommandTest.java
index 36eacf0..a188fb0 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/AddStorageServerConnectionCommandTest.java
@@ -30,13 +30,11 @@
 import org.ovirt.engine.core.utils.MockEJBStrategyRule;
 
 @RunWith(MockitoJUnitRunner.class)
-public class AddStorageServerConnectionCommandTest {
+public class AddStorageServerConnectionCommandTest extends 
StorageServerConnectionTestCommon {
     @ClassRule
     public static MockEJBStrategyRule ejbRule = new MockEJBStrategyRule();
 
     private 
AddStorageServerConnectionCommand<StorageServerConnectionParametersBase> 
command = null;
-
-    private StorageServerConnectionParametersBase parameters;
 
     @Mock
     StorageServerConnectionDAO storageConnDao;
@@ -53,49 +51,6 @@
         doReturn(storageDomainDao).when(command).getStorageDomainDao();
     }
 
-    private StorageServerConnections createPosixConnection(String connection,
-            StorageType type,
-            String vfsType,
-            String mountOptions) {
-        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(connection, type);
-        connectionDetails.setVfsType(vfsType);
-        connectionDetails.setMountOptions(mountOptions);
-        return connectionDetails;
-    }
-
-    private StorageServerConnections createISCSIConnection(String connection,
-            StorageType type,
-            String iqn,
-            String port,
-            String user,
-            String password) {
-        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(connection, type);
-        connectionDetails.setiqn(iqn);
-        connectionDetails.setport(port);
-        connectionDetails.setuser_name(user);
-        connectionDetails.setpassword(password);
-        return connectionDetails;
-    }
-
-    private StorageServerConnections populateBasicConnectionDetails(String 
connection, StorageType type) {
-        StorageServerConnections connectionDetails = new 
StorageServerConnections();
-        connectionDetails.setconnection(connection);
-        connectionDetails.setstorage_type(type);
-        return connectionDetails;
-    }
-
-    @Test
-    public void addPosixEmptyVFSType() {
-        StorageServerConnections newPosixConnection =
-                
createPosixConnection("multipass.my.domain.tlv.company.com:/export/allstorage/data1",
-                        StorageType.POSIXFS,
-                        null,
-                        "timeo=30");
-        parameters.setStorageServerConnection(newPosixConnection);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE);
-    }
-
     @Test
     public void addPosixNonEmptyVFSType() {
         StorageServerConnections newPosixConnection =
@@ -107,46 +62,6 @@
         parameters.setVdsId(Guid.Empty);
         
doReturn(false).when(command).isConnWithSameDetailsExists(newPosixConnection, 
null);
         CanDoActionTestUtils.runAndAssertCanDoActionSuccess(command);
-    }
-
-    @Test
-    public void addISCSIEmptyIqn() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, "", 
"3650", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN);
-    }
-
-    @Test
-    public void addISCSIEmptyPort() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
-    }
-
-    @Test
-    public void addISCSIInvalidPort() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "-3650", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
-    }
-
-    @Test
-    public void addISCSIInvalidPortWithCharacters() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "abc", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
     }
 
     @Test
@@ -289,8 +204,8 @@
 
     @Test
     public void isLocalDomainConnWithSamePathAndPoolExist() {
-        StorageServerConnections newLocalConnection = 
populateBasicConnectionDetails("/localSD", StorageType.LOCALFS);
-        StorageServerConnections existingConn = 
populateBasicConnectionDetails("/localSD", StorageType.LOCALFS);
+        StorageServerConnections newLocalConnection = 
populateBasicConnectionDetails(null, "/localSD", StorageType.LOCALFS);
+        StorageServerConnections existingConn = 
populateBasicConnectionDetails(null, "/localSD", StorageType.LOCALFS);
         existingConn.setid(Guid.newGuid().toString());
 
         Guid storagePoolId = Guid.newGuid();
@@ -305,8 +220,8 @@
 
     @Test
     public void isLocalDomainConnWithSamePathAndPoolNotExist() {
-        StorageServerConnections newLocalConnection = 
populateBasicConnectionDetails("/localSD", StorageType.LOCALFS);
-        StorageServerConnections existingConn = 
populateBasicConnectionDetails("/localSD", StorageType.LOCALFS);
+        StorageServerConnections newLocalConnection = 
populateBasicConnectionDetails(null, "/localSD", StorageType.LOCALFS);
+        StorageServerConnections existingConn = 
populateBasicConnectionDetails(null, "/localSD", StorageType.LOCALFS);
 
         Guid newLocalConnectionStoragePoolId = Guid.newGuid();
         Guid existingLocalConnectionStoragePoolId = Guid.newGuid();
@@ -319,4 +234,12 @@
         boolean isExists = 
command.isConnWithSameDetailsExists(newLocalConnection, 
newLocalConnectionStoragePoolId);
         assertFalse(isExists);
     }
+
+    protected ConnectStorageToVdsCommand getCommand() {
+        return command;
+    }
+
+    protected boolean createConnectionWithId() {
+        return false;
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageServerConnectionTestCommon.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageServerConnectionTestCommon.java
new file mode 100644
index 0000000..9db6865
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/StorageServerConnectionTestCommon.java
@@ -0,0 +1,123 @@
+package org.ovirt.engine.core.bll.storage;
+
+import org.junit.Test;
+import org.ovirt.engine.core.bll.CanDoActionTestUtils;
+import 
org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase;
+import org.ovirt.engine.core.common.businessentities.NfsVersion;
+import org.ovirt.engine.core.common.businessentities.StorageServerConnections;
+import org.ovirt.engine.core.common.businessentities.StorageType;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.compat.Guid;
+
+public abstract class StorageServerConnectionTestCommon {
+
+    protected StorageServerConnectionParametersBase parameters;
+
+    private Guid getConnectionId() {
+        return createConnectionWithId() ? Guid.newGuid() : null;
+    }
+
+    protected StorageServerConnections createNFSConnection(String connection,
+                                                         StorageType type,
+                                                         NfsVersion version,
+                                                         int timeout,
+                                                         int retrans) {
+        Guid id = getConnectionId();
+        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
+        connectionDetails.setNfsVersion(version);
+        connectionDetails.setNfsTimeo((short) timeout);
+        connectionDetails.setNfsRetrans((short) retrans);
+        return connectionDetails;
+    }
+
+    protected StorageServerConnections createPosixConnection(String connection,
+                                                           StorageType type,
+                                                           String vfsType,
+                                                           String 
mountOptions) {
+        Guid id = getConnectionId();
+        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
+        connectionDetails.setVfsType(vfsType);
+        connectionDetails.setMountOptions(mountOptions);
+        return connectionDetails;
+    }
+
+    protected StorageServerConnections populateBasicConnectionDetails(Guid id, 
String connection, StorageType type) {
+        StorageServerConnections connectionDetails = new 
StorageServerConnections();
+        if (id != null) {
+            connectionDetails.setid(id.toString());
+        }
+        connectionDetails.setconnection(connection);
+        connectionDetails.setstorage_type(type);
+        return connectionDetails;
+    }
+
+    protected StorageServerConnections createISCSIConnection(String connection,
+                                                           StorageType type,
+                                                           String iqn,
+                                                           String port,
+                                                           String user,
+                                                           String password) {
+        Guid id = getConnectionId();
+        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
+        connectionDetails.setiqn(iqn);
+        connectionDetails.setport(port);
+        connectionDetails.setuser_name(user);
+        connectionDetails.setpassword(password);
+        return connectionDetails;
+    }
+
+    @Test
+    public void testISCSIEmptyIqn() {
+        StorageServerConnections newISCSIConnection =
+                createISCSIConnection("10.35.16.25", StorageType.ISCSI, "", 
"3650", "user1", "mypassword123");
+        parameters.setStorageServerConnection(newISCSIConnection);
+        parameters.setVdsId(Guid.Empty);
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(getCommand(),
+                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN);
+    }
+
+    @Test
+    public void testISCSIEmptyPort() {
+        StorageServerConnections newISCSIConnection =
+                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "", "user1", "mypassword123");
+        parameters.setStorageServerConnection(newISCSIConnection);
+        parameters.setVdsId(Guid.Empty);
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(getCommand(),
+                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
+    }
+
+    @Test
+    public void testISCSIInvalidPort() {
+        StorageServerConnections newISCSIConnection =
+                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "-3650", "user1", "mypassword123");
+        parameters.setStorageServerConnection(newISCSIConnection);
+        parameters.setVdsId(Guid.Empty);
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(getCommand(),
+                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
+    }
+
+    @Test
+    public void testISCSIInvalidPortWithCharacters() {
+        StorageServerConnections newISCSIConnection =
+                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "abc", "user1", "mypassword123");
+        parameters.setStorageServerConnection(newISCSIConnection);
+        parameters.setVdsId(Guid.Empty);
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(getCommand(),
+                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
+    }
+
+    @Test
+    public void testPosixEmptyVFSType() {
+        StorageServerConnections newPosixConnection =
+                
createPosixConnection("multipass.my.domain.tlv.company.com:/export/allstorage/data1",
+                        StorageType.POSIXFS,
+                        null,
+                        "timeo=30");
+        parameters.setStorageServerConnection(newPosixConnection);
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(getCommand(),
+                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE);
+    }
+
+    protected abstract ConnectStorageToVdsCommand getCommand();
+    protected abstract boolean createConnectionWithId();
+}
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommandTest.java
index 4eaf0a7..03a4985 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/storage/UpdateStorageServerConnectionCommandTest.java
@@ -47,7 +47,7 @@
 import org.ovirt.engine.core.utils.MockEJBStrategyRule;
 
 @RunWith(MockitoJUnitRunner.class)
-public class UpdateStorageServerConnectionCommandTest {
+public class UpdateStorageServerConnectionCommandTest extends 
StorageServerConnectionTestCommon {
 
     @ClassRule
     public static MockEJBStrategyRule ejbRule = new MockEJBStrategyRule();
@@ -75,7 +75,6 @@
     @Mock
     private StorageDomainDAO storageDomainDAO;
 
-    private StorageServerConnectionParametersBase parameters;
 
     @Before
     public void prepareParams() {
@@ -104,61 +103,14 @@
 
         command = spy(new 
UpdateStorageServerConnectionCommand<StorageServerConnectionParametersBase>(parameters));
         doReturn(storageConnDao).when(command).getStorageConnDao();
-        
doReturn(storageDomainDynamicDao).when(command).getStorageDomainDynamicDao();
-        doReturn(storagePoolIsoMapDAO).when(command).getStoragePoolIsoMapDao();
+        
doReturn(storageDomainDynamicDao).when((UpdateStorageServerConnectionCommand) 
command).getStorageDomainDynamicDao();
+        
doReturn(storagePoolIsoMapDAO).when((UpdateStorageServerConnectionCommand) 
command).getStoragePoolIsoMapDao();
         doReturn(lunDAO).when(command).getLunDao();
         doReturn(vmDAO).when(command).getVmDAO();
         doReturn(storageDomainDAO).when(command).getStorageDomainDao();
     }
 
-    private StorageServerConnections createNFSConnection(String connection,
-            StorageType type,
-            NfsVersion version,
-            int timeout,
-            int retrans) {
-        Guid id = Guid.newGuid();
-        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
-        connectionDetails.setNfsVersion(version);
-        connectionDetails.setNfsTimeo((short) timeout);
-        connectionDetails.setNfsRetrans((short) retrans);
-        return connectionDetails;
-    }
-
-    private StorageServerConnections createPosixConnection(String connection,
-            StorageType type,
-            String vfsType,
-            String mountOptions) {
-        Guid id = Guid.newGuid();
-        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
-        connectionDetails.setVfsType(vfsType);
-        connectionDetails.setMountOptions(mountOptions);
-        return connectionDetails;
-    }
-
-    private StorageServerConnections createISCSIConnection(String connection,
-            StorageType type,
-            String iqn,
-            String port,
-            String user,
-            String password) {
-        Guid id = Guid.newGuid();
-        StorageServerConnections connectionDetails = 
populateBasicConnectionDetails(id, connection, type);
-        connectionDetails.setiqn(iqn);
-        connectionDetails.setport(port);
-        connectionDetails.setuser_name(user);
-        connectionDetails.setpassword(password);
-        return connectionDetails;
-    }
-
-    private StorageServerConnections populateBasicConnectionDetails(Guid id, 
String connection, StorageType type) {
-        StorageServerConnections connectionDetails = new 
StorageServerConnections();
-        connectionDetails.setid(id.toString());
-        connectionDetails.setconnection(connection);
-        connectionDetails.setstorage_type(type);
-        return connectionDetails;
-    }
-
-    private StorageDomain createDomain(StorageDomainDynamic domainDynamic) {
+    protected StorageDomain createDomain(StorageDomainDynamic domainDynamic) {
         StorageDomain domain = new StorageDomain();
         domain.setStorageName("mydomain");
         return domain;
@@ -239,59 +191,6 @@
         CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
                 VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID);
     }
-
-    @Test
-    public void updatePosixEmptyVFSType() {
-        StorageServerConnections newPosixConnection =
-                
createPosixConnection("multipass.my.domain.tlv.company.com:/export/allstorage/data1",
-                        StorageType.POSIXFS,
-                        null,
-                        "timeo=30");
-        parameters.setStorageServerConnection(newPosixConnection);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE);
-    }
-
-    @Test
-    public void updateISCSIConnectionEmptyIqn() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, "", 
"3260", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN);
-    }
-
-    @Test
-    public void addISCSIEmptyPort() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
-    }
-
-    @Test
-    public void addISCSIInvalidPort() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "-3650", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
-    }
-
-    @Test
-    public void addISCSIInvalidPortWithCharacters() {
-        StorageServerConnections newISCSIConnection =
-                createISCSIConnection("10.35.16.25", StorageType.ISCSI, 
"iqn.2013-04.myhat.com:aaa-target1", "abc", "user1", "mypassword123");
-        parameters.setStorageServerConnection(newISCSIConnection);
-        parameters.setVdsId(Guid.Empty);
-        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
-                VdcBllMessages.VALIDATION_STORAGE_CONNECTION_INVALID_PORT);
-    }
-
 
     @Test
     public void updateSeveralConnectionsWithSamePath() {
@@ -810,4 +709,12 @@
        boolean isExists = 
command.isConnWithSameDetailsExists(newISCSIConnection, null);
         assertFalse(isExists);
     }
+
+    protected ConnectStorageToVdsCommand getCommand() {
+        return command;
+    }
+
+    protected boolean createConnectionWithId() {
+        return true;
+    }
 }


-- 
To view, visit http://gerrit.ovirt.org/32488
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad571ca0c5788c375200847e8872706a8dfd7f3e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to