mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Reworked the formatting and structure of the api project's unit tests.
Signed-off-by: Chip Childers <chip.childers@gmail.com>
This commit is contained in:
parent
e953b77492
commit
b1c063298d
@ -17,7 +17,8 @@
|
|||||||
package com.cloud.agent.api;
|
package com.cloud.agent.api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This currently assumes that both primary and secondary storage are mounted on the XenServer.
|
* This currently assumes that both primary and secondary storage are mounted on
|
||||||
|
* the XenServer.
|
||||||
*/
|
*/
|
||||||
public class SnapshotCommand extends Command {
|
public class SnapshotCommand extends Command {
|
||||||
protected String primaryStoragePoolNameLabel;
|
protected String primaryStoragePoolNameLabel;
|
||||||
@ -34,20 +35,20 @@ public class SnapshotCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param primaryStoragePoolNameLabel The primary storage Pool
|
* @param primaryStoragePoolNameLabel
|
||||||
* @param snapshotUuid The UUID of the snapshot which is going to be backed up
|
* The primary storage Pool
|
||||||
* @param secondaryStoragePoolURL This is what shows up in the UI when you click on Secondary storage.
|
* @param snapshotUuid
|
||||||
* In the code, it is present as: In the vmops.host_details table, there is a field mount.parent. This is the value of that field
|
* The UUID of the snapshot which is going to be backed up
|
||||||
* If you have better ideas on how to get it, you are welcome.
|
* @param secondaryStoragePoolURL
|
||||||
|
* This is what shows up in the UI when you click on Secondary
|
||||||
|
* storage. In the code, it is present as: In the
|
||||||
|
* vmops.host_details table, there is a field mount.parent. This
|
||||||
|
* is the value of that field If you have better ideas on how to
|
||||||
|
* get it, you are welcome.
|
||||||
*/
|
*/
|
||||||
public SnapshotCommand(String primaryStoragePoolNameLabel,
|
public SnapshotCommand(String primaryStoragePoolNameLabel,
|
||||||
String secondaryStorageUrl,
|
String secondaryStorageUrl, String snapshotUuid,
|
||||||
String snapshotUuid,
|
String snapshotName, Long dcId, Long accountId, Long volumeId) {
|
||||||
String snapshotName,
|
|
||||||
Long dcId,
|
|
||||||
Long accountId,
|
|
||||||
Long volumeId)
|
|
||||||
{
|
|
||||||
this.primaryStoragePoolNameLabel = primaryStoragePoolNameLabel;
|
this.primaryStoragePoolNameLabel = primaryStoragePoolNameLabel;
|
||||||
this.snapshotUuid = snapshotUuid;
|
this.snapshotUuid = snapshotUuid;
|
||||||
this.secondaryStorageUrl = secondaryStorageUrl;
|
this.secondaryStorageUrl = secondaryStorageUrl;
|
||||||
@ -82,7 +83,6 @@ public class SnapshotCommand extends Command {
|
|||||||
return secondaryStorageUrl;
|
return secondaryStorageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Long getDataCenterId() {
|
public Long getDataCenterId() {
|
||||||
return dcId;
|
return dcId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,10 +16,13 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.AgentControlAnswer;
|
||||||
|
import com.cloud.agent.api.AgentControlCommand;
|
||||||
|
|
||||||
public class AgentControlAnswerTest {
|
public class AgentControlAnswerTest {
|
||||||
AgentControlCommand acc = new AgentControlCommand();
|
AgentControlCommand acc = new AgentControlCommand();
|
||||||
AgentControlAnswer aca = new AgentControlAnswer(acc);
|
AgentControlAnswer aca = new AgentControlAnswer(acc);
|
||||||
|
|||||||
@ -16,10 +16,12 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.AgentControlCommand;
|
||||||
|
|
||||||
public class AgentControlCommandTest {
|
public class AgentControlCommandTest {
|
||||||
AgentControlCommand acc = new AgentControlCommand();
|
AgentControlCommand acc = new AgentControlCommand();
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,15 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.AgentControlCommand;
|
||||||
|
import com.cloud.agent.api.Answer;
|
||||||
|
import com.cloud.agent.api.UnsupportedAnswer;
|
||||||
|
|
||||||
public class AnswerTest {
|
public class AnswerTest {
|
||||||
AgentControlCommand acc = new AgentControlCommand();
|
AgentControlCommand acc = new AgentControlCommand();
|
||||||
Answer a = new Answer(acc, true, "details");
|
Answer a = new Answer(acc, true, "details");
|
||||||
@ -52,7 +57,8 @@ public class AnswerTest {
|
|||||||
assertFalse(b);
|
assertFalse(b);
|
||||||
|
|
||||||
String d = usa.getDetails();
|
String d = usa.getDetails();
|
||||||
assertTrue(d.equals("Unsupported command issued:" + acc.toString() + ". Are you sure you got the right type of server?"));
|
assertTrue(d.equals("Unsupported command issued:" + acc.toString()
|
||||||
|
+ ". Are you sure you got the right type of server?"));
|
||||||
|
|
||||||
usa = Answer.createUnsupportedVersionAnswer(acc);
|
usa = Answer.createUnsupportedVersionAnswer(acc);
|
||||||
b = usa.executeInSequence();
|
b = usa.executeInSequence();
|
||||||
|
|||||||
@ -16,10 +16,13 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import com.cloud.agent.api.AttachIsoCommand;
|
||||||
|
|
||||||
public class AttachIsoCommandTest {
|
public class AttachIsoCommandTest {
|
||||||
AttachIsoCommand aic = new AttachIsoCommand("vmname", "isopath", false);
|
AttachIsoCommand aic = new AttachIsoCommand("vmname", "isopath", false);
|
||||||
|
|||||||
@ -16,13 +16,19 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.cloud.storage.Storage.StoragePoolType;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.AttachVolumeAnswer;
|
||||||
|
import com.cloud.agent.api.AttachVolumeCommand;
|
||||||
|
import com.cloud.storage.Storage.StoragePoolType;
|
||||||
|
|
||||||
public class AttachVolumeAnswerTest {
|
public class AttachVolumeAnswerTest {
|
||||||
AttachVolumeCommand avc = new AttachVolumeCommand(true, "vmname", StoragePoolType.Filesystem, "vFolder", "vPath", "vName", 123456789L, "chainInfo");
|
AttachVolumeCommand avc = new AttachVolumeCommand(true, "vmname",
|
||||||
|
StoragePoolType.Filesystem, "vFolder", "vPath", "vName",
|
||||||
|
123456789L, "chainInfo");
|
||||||
AttachVolumeAnswer ava1 = new AttachVolumeAnswer(avc);
|
AttachVolumeAnswer ava1 = new AttachVolumeAnswer(avc);
|
||||||
String results = "";
|
String results = "";
|
||||||
AttachVolumeAnswer ava2 = new AttachVolumeAnswer(avc, results);
|
AttachVolumeAnswer ava2 = new AttachVolumeAnswer(avc, results);
|
||||||
|
|||||||
@ -16,14 +16,18 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.storage.Storage.StoragePoolType;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import com.cloud.agent.api.AttachVolumeCommand;
|
||||||
|
import com.cloud.storage.Storage.StoragePoolType;
|
||||||
|
|
||||||
public class AttachVolumeCommandTest {
|
public class AttachVolumeCommandTest {
|
||||||
AttachVolumeCommand avc = new AttachVolumeCommand(true, "vmname", StoragePoolType.Filesystem, "vFolder", "vPath", "vName", 123456789L, "chainInfo");
|
AttachVolumeCommand avc = new AttachVolumeCommand(true, "vmname",
|
||||||
|
StoragePoolType.Filesystem, "vFolder", "vPath", "vName",
|
||||||
|
123456789L, "chainInfo");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteInSequence() {
|
public void testExecuteInSequence() {
|
||||||
|
|||||||
@ -16,13 +16,32 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.BackupSnapshotAnswer;
|
||||||
|
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||||
|
import com.cloud.storage.StoragePool;
|
||||||
|
|
||||||
public class BackupSnapshotAnswerTest {
|
public class BackupSnapshotAnswerTest {
|
||||||
BackupSnapshotCommand bsc = new BackupSnapshotCommand();
|
private BackupSnapshotCommand bsc;
|
||||||
BackupSnapshotAnswer bsa = new BackupSnapshotAnswer(bsc, true, "results", "bussname", false);
|
private BackupSnapshotAnswer bsa;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
|
||||||
|
StoragePool pool = Mockito.mock(StoragePool.class);
|
||||||
|
|
||||||
|
bsc = new BackupSnapshotCommand("primaryStoragePoolNameLabel",
|
||||||
|
"secondaryStoragePoolURL", 101L, 102L, 103L, 104L,
|
||||||
|
"volumePath", pool, "snapshotUuid", "snapshotName",
|
||||||
|
"prevSnapshotUuid", "prevBackupUuid", false, "vmName", 5);
|
||||||
|
bsa = new BackupSnapshotAnswer(bsc, true, "results", "bussname", false);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteInSequence() {
|
public void testExecuteInSequence() {
|
||||||
|
|||||||
@ -16,68 +16,118 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||||
import com.cloud.agent.api.to.StorageFilerTO;
|
import com.cloud.agent.api.to.StorageFilerTO;
|
||||||
import com.cloud.agent.api.to.SwiftTO;
|
import com.cloud.agent.api.to.SwiftTO;
|
||||||
import com.cloud.storage.StoragePool;
|
|
||||||
import com.cloud.storage.Storage.StoragePoolType;
|
import com.cloud.storage.Storage.StoragePoolType;
|
||||||
|
import com.cloud.storage.StoragePool;
|
||||||
import com.cloud.storage.StoragePoolStatus;
|
import com.cloud.storage.StoragePoolStatus;
|
||||||
import java.util.Date;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
|
|
||||||
public class BackupSnapshotCommandTest {
|
public class BackupSnapshotCommandTest {
|
||||||
public StoragePool pool = new StoragePool() {
|
public StoragePool pool = new StoragePool() {
|
||||||
public long getId() {return 1L;};
|
public long getId() {
|
||||||
public String getName() {return "name";};
|
return 1L;
|
||||||
public String getUuid() {return "bed9f83e-cac3-11e1-ac8a-0050568b007e";};
|
};
|
||||||
public StoragePoolType getPoolType() {return StoragePoolType.Filesystem;};
|
|
||||||
|
public String getName() {
|
||||||
|
return "name";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return "bed9f83e-cac3-11e1-ac8a-0050568b007e";
|
||||||
|
};
|
||||||
|
|
||||||
|
public StoragePoolType getPoolType() {
|
||||||
|
return StoragePoolType.Filesystem;
|
||||||
|
};
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
Date date = null;
|
Date date = null;
|
||||||
try{
|
try {
|
||||||
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 12:12:12");
|
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
}
|
.parse("01/01/1970 12:12:12");
|
||||||
catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
public Date getUpdateTime() {return new Date();};
|
|
||||||
public long getDataCenterId() {return 0L;};
|
public Date getUpdateTime() {
|
||||||
public long getCapacityBytes() {return 0L;};
|
return new Date();
|
||||||
public long getAvailableBytes() {return 0L;};
|
};
|
||||||
public Long getClusterId() {return 0L;};
|
|
||||||
public String getHostAddress() {return "hostAddress";};
|
public long getDataCenterId() {
|
||||||
public String getPath() {return "path";};
|
return 0L;
|
||||||
public String getUserInfo() {return "userInfo";};
|
};
|
||||||
public boolean isShared() {return false;};
|
|
||||||
public boolean isLocal() {return false;};
|
public long getCapacityBytes() {
|
||||||
public StoragePoolStatus getStatus() {return StoragePoolStatus.Up;};
|
return 0L;
|
||||||
public int getPort() {return 25;};
|
};
|
||||||
public Long getPodId() {return 0L;};
|
|
||||||
|
public long getAvailableBytes() {
|
||||||
|
return 0L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getClusterId() {
|
||||||
|
return 0L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getHostAddress() {
|
||||||
|
return "hostAddress";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return "path";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getUserInfo() {
|
||||||
|
return "userInfo";
|
||||||
|
};
|
||||||
|
|
||||||
|
public boolean isShared() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
public boolean isLocal() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
public StoragePoolStatus getStatus() {
|
||||||
|
return StoragePoolStatus.Up;
|
||||||
|
};
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return 25;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getPodId() {
|
||||||
|
return 0L;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
BackupSnapshotCommand bsc = new BackupSnapshotCommand(
|
BackupSnapshotCommand bsc = new BackupSnapshotCommand(
|
||||||
"primaryStoragePoolNameLabel",
|
"primaryStoragePoolNameLabel", "http://secondary.Storage.Url",
|
||||||
"http://secondary.Storage.Url",
|
101L, 102L, 103L, 104L, "vPath", pool,
|
||||||
101L,
|
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "sName",
|
||||||
102L,
|
|
||||||
103L,
|
|
||||||
104L,
|
|
||||||
"vPath",
|
|
||||||
pool,
|
|
||||||
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae",
|
|
||||||
"sName",
|
|
||||||
"9012793e-0657-11e2-bebc-0050568b0057",
|
"9012793e-0657-11e2-bebc-0050568b0057",
|
||||||
"7167e0b2-f5b0-11e1-8414-0050568b0057",
|
"7167e0b2-f5b0-11e1-8414-0050568b0057", false, "vmName", 5);
|
||||||
false,
|
|
||||||
"vmName",
|
|
||||||
5
|
|
||||||
);
|
|
||||||
|
|
||||||
BackupSnapshotCommand bsc1 = new BackupSnapshotCommand();
|
BackupSnapshotCommand bsc1 = new BackupSnapshotCommand(
|
||||||
|
"primaryStoragePoolNameLabel", "http://secondary.Storage.Url",
|
||||||
|
101L, 102L, 103L, 104L, "vPath", pool,
|
||||||
|
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "sName",
|
||||||
|
"9012793e-0657-11e2-bebc-0050568b0057",
|
||||||
|
"7167e0b2-f5b0-11e1-8414-0050568b0057", false, "vmName", 5);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPrimaryStoragePoolNameLabel() {
|
public void testGetPrimaryStoragePoolNameLabel() {
|
||||||
@ -147,17 +197,18 @@ public class BackupSnapshotCommandTest {
|
|||||||
assertEquals(StoragePoolType.Filesystem, type);
|
assertEquals(StoragePoolType.Filesystem, type);
|
||||||
|
|
||||||
String str = pool.toString();
|
String str = pool.toString();
|
||||||
assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":" + port.toString() + "|" + path + "]"));
|
assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":"
|
||||||
|
+ port.toString() + "|" + path + "]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCreated() {
|
public void testGetCreated() {
|
||||||
try{
|
try {
|
||||||
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 12:12:12");
|
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
|
.parse("01/01/1970 12:12:12");
|
||||||
Date d = pool.getCreated();
|
Date d = pool.getCreated();
|
||||||
assertTrue(d.compareTo(date) == 0);
|
assertTrue(d.compareTo(date) == 0);
|
||||||
}
|
} catch (ParseException e) {
|
||||||
catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,12 +16,16 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import com.cloud.agent.api.routing.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.BumpUpPriorityCommand;
|
||||||
|
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||||
|
|
||||||
public class BumpUpPriorityCommandTest {
|
public class BumpUpPriorityCommandTest {
|
||||||
|
|
||||||
BumpUpPriorityCommand bupc = new BumpUpPriorityCommand();
|
BumpUpPriorityCommand bupc = new BumpUpPriorityCommand();
|
||||||
|
|
||||||
// test super class
|
// test super class
|
||||||
@ -32,15 +36,19 @@ public class BumpUpPriorityCommandTest {
|
|||||||
value = bupc.getAccessDetail(NetworkElementCommand.ACCOUNT_ID);
|
value = bupc.getAccessDetail(NetworkElementCommand.ACCOUNT_ID);
|
||||||
assertTrue(value.equals("accountID"));
|
assertTrue(value.equals("accountID"));
|
||||||
|
|
||||||
bupc.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR, "GuestNetworkCIDR");
|
bupc.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR,
|
||||||
|
"GuestNetworkCIDR");
|
||||||
value = bupc.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR);
|
value = bupc.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_CIDR);
|
||||||
assertTrue(value.equals("GuestNetworkCIDR"));
|
assertTrue(value.equals("GuestNetworkCIDR"));
|
||||||
|
|
||||||
bupc.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY, "GuestNetworkGateway");
|
bupc.setAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY,
|
||||||
value = bupc.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
|
"GuestNetworkGateway");
|
||||||
|
value = bupc
|
||||||
|
.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
|
||||||
assertTrue(value.equals("GuestNetworkGateway"));
|
assertTrue(value.equals("GuestNetworkGateway"));
|
||||||
|
|
||||||
bupc.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, "GuestVlanTag");
|
bupc.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG,
|
||||||
|
"GuestVlanTag");
|
||||||
value = bupc.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG);
|
value = bupc.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG);
|
||||||
assertTrue(value.equals("GuestVlanTag"));
|
assertTrue(value.equals("GuestVlanTag"));
|
||||||
|
|
||||||
@ -52,11 +60,13 @@ public class BumpUpPriorityCommandTest {
|
|||||||
value = bupc.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
value = bupc.getAccessDetail(NetworkElementCommand.ROUTER_IP);
|
||||||
assertTrue(value.equals("RouterIP"));
|
assertTrue(value.equals("RouterIP"));
|
||||||
|
|
||||||
bupc.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, "RouterGuestIP");
|
bupc.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,
|
||||||
|
"RouterGuestIP");
|
||||||
value = bupc.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
|
value = bupc.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
|
||||||
assertTrue(value.equals("RouterGuestIP"));
|
assertTrue(value.equals("RouterGuestIP"));
|
||||||
|
|
||||||
bupc.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, "ZoneNetworkType");
|
bupc.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,
|
||||||
|
"ZoneNetworkType");
|
||||||
value = bupc.getAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE);
|
value = bupc.getAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE);
|
||||||
assertTrue(value.equals("ZoneNetworkType"));
|
assertTrue(value.equals("ZoneNetworkType"));
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,13 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CancelCommand;
|
||||||
|
|
||||||
public class CancelCommandTest {
|
public class CancelCommandTest {
|
||||||
CancelCommand cc = new CancelCommand(123456789L, "goodreason");
|
CancelCommand cc = new CancelCommand(123456789L, "goodreason");
|
||||||
|
|
||||||
|
|||||||
@ -16,13 +16,18 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import com.cloud.host.Status.Event;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.ChangeAgentAnswer;
|
||||||
|
import com.cloud.agent.api.ChangeAgentCommand;
|
||||||
|
import com.cloud.host.Status.Event;
|
||||||
|
|
||||||
public class ChangeAgentAnswerTest {
|
public class ChangeAgentAnswerTest {
|
||||||
ChangeAgentCommand cac = new ChangeAgentCommand(123456789L, Event.AgentConnected);
|
ChangeAgentCommand cac = new ChangeAgentCommand(123456789L,
|
||||||
|
Event.AgentConnected);
|
||||||
ChangeAgentAnswer caa = new ChangeAgentAnswer(cac, true);
|
ChangeAgentAnswer caa = new ChangeAgentAnswer(cac, true);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -16,13 +16,19 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.cloud.host.Status.Event;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.ChangeAgentCommand;
|
||||||
|
import com.cloud.host.Status.Event;
|
||||||
|
|
||||||
public class ChangeAgentCommandTest {
|
public class ChangeAgentCommandTest {
|
||||||
ChangeAgentCommand cac = new ChangeAgentCommand(123456789L, Event.AgentConnected);
|
|
||||||
|
ChangeAgentCommand cac = new ChangeAgentCommand(123456789L,
|
||||||
|
Event.AgentConnected);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAgentId() {
|
public void testGetAgentId() {
|
||||||
|
|||||||
@ -16,10 +16,14 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CheckHealthAnswer;
|
||||||
|
import com.cloud.agent.api.CheckHealthCommand;
|
||||||
|
|
||||||
public class CheckHealthAnswerTest {
|
public class CheckHealthAnswerTest {
|
||||||
CheckHealthCommand chc = new CheckHealthCommand();
|
CheckHealthCommand chc = new CheckHealthCommand();
|
||||||
CheckHealthAnswer cha = new CheckHealthAnswer(chc, true);
|
CheckHealthAnswer cha = new CheckHealthAnswer(chc, true);
|
||||||
@ -34,7 +38,7 @@ public class CheckHealthAnswerTest {
|
|||||||
public void testGetDetails() {
|
public void testGetDetails() {
|
||||||
String d = cha.getDetails();
|
String d = cha.getDetails();
|
||||||
boolean r = cha.getResult();
|
boolean r = cha.getResult();
|
||||||
assertTrue(d.equals("resource is " + (r? "alive" : "not alive")));
|
assertTrue(d.equals("resource is " + (r ? "alive" : "not alive")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -16,10 +16,13 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CheckHealthCommand;
|
||||||
|
|
||||||
public class CheckHealthCommandTest {
|
public class CheckHealthCommandTest {
|
||||||
CheckHealthCommand chc = new CheckHealthCommand();
|
CheckHealthCommand chc = new CheckHealthCommand();
|
||||||
|
|
||||||
|
|||||||
@ -16,14 +16,25 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
import com.cloud.host.Status.Event;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CheckNetworkAnswer;
|
||||||
|
import com.cloud.agent.api.CheckNetworkCommand;
|
||||||
|
|
||||||
public class CheckNetworkAnswerTest {
|
public class CheckNetworkAnswerTest {
|
||||||
CheckNetworkCommand cnc = new CheckNetworkCommand();
|
CheckNetworkCommand cnc;
|
||||||
CheckNetworkAnswer cna = new CheckNetworkAnswer(cnc, true, "details", true);
|
CheckNetworkAnswer cna;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
cnc = Mockito.mock(CheckNetworkCommand.class);
|
||||||
|
cna = new CheckNetworkAnswer(cnc, true, "details", true);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetResult() {
|
public void testGetResult() {
|
||||||
|
|||||||
@ -16,19 +16,33 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.cloud.agent.api.*;
|
|
||||||
import com.cloud.network.PhysicalNetworkSetupInfo;
|
import org.junit.Before;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CheckNetworkCommand;
|
||||||
|
import com.cloud.network.PhysicalNetworkSetupInfo;
|
||||||
|
|
||||||
public class CheckNetworkCommandTest {
|
public class CheckNetworkCommandTest {
|
||||||
CheckNetworkCommand cnc = new CheckNetworkCommand();
|
CheckNetworkCommand cnc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<PhysicalNetworkSetupInfo> net = Mockito.mock(List.class);
|
||||||
|
cnc = new CheckNetworkCommand(net);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPhysicalNetworkInfoList() {
|
public void testGetPhysicalNetworkInfoList() {
|
||||||
List<PhysicalNetworkSetupInfo> networkInfoList = cnc.getPhysicalNetworkInfoList();
|
List<PhysicalNetworkSetupInfo> networkInfoList = cnc
|
||||||
assertNull(networkInfoList);
|
.getPhysicalNetworkInfoList();
|
||||||
|
assertEquals(0, networkInfoList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -16,86 +16,197 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import java.util.List;
|
import static org.junit.Assert.assertFalse;
|
||||||
import java.util.Date;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import java.text.SimpleDateFormat;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import com.cloud.agent.api.*;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.CheckOnHostCommand;
|
||||||
import com.cloud.agent.api.to.HostTO;
|
import com.cloud.agent.api.to.HostTO;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.Status;
|
import com.cloud.host.Status;
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.resource.ResourceState;
|
import com.cloud.resource.ResourceState;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class CheckOnHostCommandTest {
|
public class CheckOnHostCommandTest {
|
||||||
public Host host = new Host() {
|
public Host host = new Host() {
|
||||||
public Status getState() {return Status.Up;};
|
public Status getState() {
|
||||||
public long getId() {return 101L;};
|
return Status.Up;
|
||||||
public String getName() {return "hostName";};
|
};
|
||||||
public Type getType() {return Host.Type.Storage;};
|
|
||||||
|
public long getId() {
|
||||||
|
return 101L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "hostName";
|
||||||
|
};
|
||||||
|
|
||||||
|
public Type getType() {
|
||||||
|
return Host.Type.Storage;
|
||||||
|
};
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
Date date = null;
|
Date date = null;
|
||||||
try{
|
try {
|
||||||
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 12:12:12");
|
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
}
|
.parse("01/01/1970 12:12:12");
|
||||||
catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
public Status getStatus() {return Status.Up;};
|
|
||||||
public String getPrivateIpAddress() {return "10.1.1.1";};
|
public Status getStatus() {
|
||||||
public String getStorageIpAddress() {return "10.1.1.2";};
|
return Status.Up;
|
||||||
public String getGuid() {return "bed9f83e-cac3-11e1-ac8a-0050568b007e";};
|
};
|
||||||
public Long getTotalMemory() {return 100000000000L;};
|
|
||||||
public Integer getCpus() {return 16;};
|
public String getPrivateIpAddress() {
|
||||||
public Long getSpeed() {return 2000000000L;};
|
return "10.1.1.1";
|
||||||
public Integer getProxyPort() {return 22;};
|
};
|
||||||
public Long getPodId() {return 16L;};
|
|
||||||
public long getDataCenterId() {return 17L;};
|
public String getStorageIpAddress() {
|
||||||
public String getParent() {return "parent";};
|
return "10.1.1.2";
|
||||||
public String getStorageIpAddressDeux() {return "10.1.1.3";};
|
};
|
||||||
public HypervisorType getHypervisorType() {return HypervisorType.XenServer;};
|
|
||||||
|
public String getGuid() {
|
||||||
|
return "bed9f83e-cac3-11e1-ac8a-0050568b007e";
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getTotalMemory() {
|
||||||
|
return 100000000000L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Integer getCpus() {
|
||||||
|
return 16;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getSpeed() {
|
||||||
|
return 2000000000L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Integer getProxyPort() {
|
||||||
|
return 22;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getPodId() {
|
||||||
|
return 16L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public long getDataCenterId() {
|
||||||
|
return 17L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return "parent";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getStorageIpAddressDeux() {
|
||||||
|
return "10.1.1.3";
|
||||||
|
};
|
||||||
|
|
||||||
|
public HypervisorType getHypervisorType() {
|
||||||
|
return HypervisorType.XenServer;
|
||||||
|
};
|
||||||
|
|
||||||
public Date getDisconnectedOn() {
|
public Date getDisconnectedOn() {
|
||||||
Date date = null;
|
Date date = null;
|
||||||
try{
|
try {
|
||||||
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/2012 12:12:12");
|
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
}
|
.parse("01/01/2012 12:12:12");
|
||||||
catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
public String getVersion() {return "4.0.1";};
|
|
||||||
public long getTotalSize() {return 100000000000L;};
|
public String getVersion() {
|
||||||
public String getCapabilities() {return "capabilities";};
|
return "4.0.1";
|
||||||
public long getLastPinged() {return 1L;};
|
};
|
||||||
public Long getManagementServerId() {return 2L;};
|
|
||||||
|
public long getTotalSize() {
|
||||||
|
return 100000000000L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getCapabilities() {
|
||||||
|
return "capabilities";
|
||||||
|
};
|
||||||
|
|
||||||
|
public long getLastPinged() {
|
||||||
|
return 1L;
|
||||||
|
};
|
||||||
|
|
||||||
|
public Long getManagementServerId() {
|
||||||
|
return 2L;
|
||||||
|
};
|
||||||
|
|
||||||
public Date getRemoved() {
|
public Date getRemoved() {
|
||||||
Date date = null;
|
Date date = null;
|
||||||
try{
|
try {
|
||||||
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("02/01/2012 12:12:12");
|
date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
}
|
.parse("02/01/2012 12:12:12");
|
||||||
catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return date;
|
return date;
|
||||||
};
|
};
|
||||||
public Long getClusterId() {return 3L;};
|
|
||||||
public String getPublicIpAddress() {return "10.1.1.4";};
|
public Long getClusterId() {
|
||||||
public String getPublicNetmask() {return "255.255.255.8";};
|
return 3L;
|
||||||
public String getPrivateNetmask() {return "255.255.255.16";};
|
};
|
||||||
public String getStorageNetmask() {return "255.255.255.24";};
|
|
||||||
public String getStorageMacAddress() {return "01:f4:17:38:0e:26";};
|
public String getPublicIpAddress() {
|
||||||
public String getPublicMacAddress() {return "02:f4:17:38:0e:26";};
|
return "10.1.1.4";
|
||||||
public String getPrivateMacAddress() {return "03:f4:17:38:0e:26";};
|
};
|
||||||
public String getStorageNetmaskDeux() {return "255.255.255.25";};
|
|
||||||
public String getStorageMacAddressDeux() {return "01:f4:17:38:0e:27";};
|
public String getPublicNetmask() {
|
||||||
public String getHypervisorVersion() {return "1.2.3.0";};
|
return "255.255.255.8";
|
||||||
public boolean isInMaintenanceStates() {return false;};
|
};
|
||||||
public ResourceState getResourceState() {return ResourceState.Enabled;};
|
|
||||||
|
public String getPrivateNetmask() {
|
||||||
|
return "255.255.255.16";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getStorageNetmask() {
|
||||||
|
return "255.255.255.24";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getStorageMacAddress() {
|
||||||
|
return "01:f4:17:38:0e:26";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getPublicMacAddress() {
|
||||||
|
return "02:f4:17:38:0e:26";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getPrivateMacAddress() {
|
||||||
|
return "03:f4:17:38:0e:26";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getStorageNetmaskDeux() {
|
||||||
|
return "255.255.255.25";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getStorageMacAddressDeux() {
|
||||||
|
return "01:f4:17:38:0e:27";
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getHypervisorVersion() {
|
||||||
|
return "1.2.3.0";
|
||||||
|
};
|
||||||
|
|
||||||
|
public boolean isInMaintenanceStates() {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
public ResourceState getResourceState() {
|
||||||
|
return ResourceState.Enabled;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckOnHostCommand cohc = new CheckOnHostCommand(host);
|
CheckOnHostCommand cohc = new CheckOnHostCommand(host);
|
||||||
@ -132,12 +243,12 @@ public class CheckOnHostCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetCreated() {
|
public void testGetCreated() {
|
||||||
try{
|
try {
|
||||||
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 12:12:12");
|
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
|
.parse("01/01/1970 12:12:12");
|
||||||
Date d = host.getCreated();
|
Date d = host.getCreated();
|
||||||
assertTrue(d.compareTo(date) == 0);
|
assertTrue(d.compareTo(date) == 0);
|
||||||
}
|
} catch (ParseException e) {
|
||||||
catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,12 +333,12 @@ public class CheckOnHostCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDisconnectedOn() {
|
public void testGetDisconnectedOn() {
|
||||||
try{
|
try {
|
||||||
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/2012 12:12:12");
|
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
|
.parse("01/01/2012 12:12:12");
|
||||||
Date d = host.getDisconnectedOn();
|
Date d = host.getDisconnectedOn();
|
||||||
assertTrue(d.compareTo(date) == 0);
|
assertTrue(d.compareTo(date) == 0);
|
||||||
}
|
} catch (ParseException e) {
|
||||||
catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,12 +375,12 @@ public class CheckOnHostCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRemoved() {
|
public void testGetRemoved() {
|
||||||
try{
|
try {
|
||||||
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("02/01/2012 12:12:12");
|
Date date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
|
||||||
|
.parse("02/01/2012 12:12:12");
|
||||||
Date d = host.getRemoved();
|
Date d = host.getRemoved();
|
||||||
assertTrue(d.compareTo(date) == 0);
|
assertTrue(d.compareTo(date) == 0);
|
||||||
}
|
} catch (ParseException e) {
|
||||||
catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,20 +16,29 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.agent.api.test;
|
package src.com.cloud.agent.api.test;
|
||||||
|
|
||||||
import com.cloud.agent.api.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.cloud.agent.api.SnapshotCommand;
|
||||||
|
|
||||||
public class SnapshotCommandTest {
|
public class SnapshotCommandTest {
|
||||||
SnapshotCommand ssc = new SnapshotCommand("primaryStoragePoolNameLabel",
|
SnapshotCommand ssc = new SnapshotCommand("primaryStoragePoolNameLabel",
|
||||||
"http://secondary.Storage.Url",
|
"http://secondary.Storage.Url",
|
||||||
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae",
|
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "snapshotName", 101L, 102L,
|
||||||
"snapshotName",
|
|
||||||
101L,
|
|
||||||
102L,
|
|
||||||
103L);
|
103L);
|
||||||
|
|
||||||
SnapshotCommand ssc1 = new SnapshotCommand();
|
SnapshotCommand ssc1;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
ssc1 = new SnapshotCommand("primaryStoragePoolNameLabel",
|
||||||
|
"secondaryStorageUrl", "snapshotUuid", "snapshotName", 101L,
|
||||||
|
102L, 103L);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPrimaryStoragePoolNameLabel() {
|
public void testGetPrimaryStoragePoolNameLabel() {
|
||||||
|
|||||||
@ -25,13 +25,11 @@ import org.junit.Test;
|
|||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.cloud.api.ResponseGenerator;
|
import com.cloud.api.commands.ActivateProjectCmd;
|
||||||
import com.cloud.api.response.ProjectResponse;
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.projects.Project;
|
import com.cloud.projects.Project;
|
||||||
import com.cloud.projects.ProjectService;
|
import com.cloud.projects.ProjectService;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserContext;
|
|
||||||
|
|
||||||
public class ActivateProjectCmdTest extends TestCase {
|
public class ActivateProjectCmdTest extends TestCase {
|
||||||
|
|
||||||
@ -43,7 +41,7 @@ public class ActivateProjectCmdTest extends TestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
activateProjectCmd = new ActivateProjectCmd(){
|
activateProjectCmd = new ActivateProjectCmd() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -53,17 +51,18 @@ public class ActivateProjectCmdTest extends TestCase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetEntityOwnerIdForNullProject() {
|
public void testGetEntityOwnerIdForNullProject() {
|
||||||
ProjectService projectService = Mockito.mock(ProjectService.class);
|
ProjectService projectService = Mockito.mock(ProjectService.class);
|
||||||
Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(null);
|
Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(
|
||||||
|
null);
|
||||||
activateProjectCmd._projectService = projectService;
|
activateProjectCmd._projectService = projectService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activateProjectCmd.getEntityOwnerId();
|
activateProjectCmd.getEntityOwnerId();
|
||||||
} catch(InvalidParameterValueException exception) {
|
} catch (InvalidParameterValueException exception) {
|
||||||
Assert.assertEquals("Unable to find project by id 2", exception.getLocalizedMessage());
|
Assert.assertEquals("Unable to find project by id 2",
|
||||||
|
exception.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,9 +73,11 @@ public class ActivateProjectCmdTest extends TestCase {
|
|||||||
ProjectService projectService = Mockito.mock(ProjectService.class);
|
ProjectService projectService = Mockito.mock(ProjectService.class);
|
||||||
Account account = Mockito.mock(Account.class);
|
Account account = Mockito.mock(Account.class);
|
||||||
Mockito.when(account.getId()).thenReturn(2L);
|
Mockito.when(account.getId()).thenReturn(2L);
|
||||||
Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(project);
|
Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(
|
||||||
|
project);
|
||||||
|
|
||||||
Mockito.when(projectService.getProjectOwner(Mockito.anyLong())).thenReturn(account);
|
Mockito.when(projectService.getProjectOwner(Mockito.anyLong()))
|
||||||
|
.thenReturn(account);
|
||||||
activateProjectCmd._projectService = projectService;
|
activateProjectCmd._projectService = projectService;
|
||||||
|
|
||||||
Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId());
|
Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId());
|
||||||
|
|||||||
@ -29,10 +29,10 @@ import com.cloud.exception.InvalidParameterValueException;
|
|||||||
import com.cloud.projects.Project;
|
import com.cloud.projects.Project;
|
||||||
import com.cloud.projects.ProjectService;
|
import com.cloud.projects.ProjectService;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
import com.cloud.api.commands.AddAccountToProjectCmd;
|
||||||
|
|
||||||
public class AddAccountToProjectCmdTest extends TestCase {
|
public class AddAccountToProjectCmdTest extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
private AddAccountToProjectCmd addAccountToProjectCmd;
|
private AddAccountToProjectCmd addAccountToProjectCmd;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@ -40,7 +40,7 @@ public class AddAccountToProjectCmdTest extends TestCase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
addAccountToProjectCmd = new AddAccountToProjectCmd(){
|
addAccountToProjectCmd = new AddAccountToProjectCmd() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getProjectId() {
|
public Long getProjectId() {
|
||||||
@ -50,42 +50,43 @@ public class AddAccountToProjectCmdTest extends TestCase {
|
|||||||
@Override
|
@Override
|
||||||
public String getAccountName() {
|
public String getAccountName() {
|
||||||
|
|
||||||
// to run the test testGetEventDescriptionForAccount set the accountName
|
// to run the test testGetEventDescriptionForAccount set the
|
||||||
// return "accountName";
|
// accountName
|
||||||
// to run the test the testGetEventDescriptionForNullAccount return accountname as null
|
// return "accountName";
|
||||||
|
// to run the test the testGetEventDescriptionForNullAccount
|
||||||
|
// return accountname as null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
// return "customer@abc.com";
|
// return "customer@abc.com";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****
|
/****
|
||||||
* Condition not handled in the code
|
* Condition not handled in the code
|
||||||
*
|
*
|
||||||
*****/
|
*****/
|
||||||
|
|
||||||
/*@Test
|
/*
|
||||||
public void testGetEntityOwnerIdForNullProject() {
|
* @Test public void testGetEntityOwnerIdForNullProject() {
|
||||||
|
*
|
||||||
ProjectService projectService = Mockito.mock(ProjectService.class);
|
* ProjectService projectService = Mockito.mock(ProjectService.class);
|
||||||
Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(null);
|
* Mockito
|
||||||
addAccountToProjectCmd._projectService = projectService;
|
* .when(projectService.getProject(Mockito.anyLong())).thenReturn(null);
|
||||||
|
* addAccountToProjectCmd._projectService = projectService;
|
||||||
try {
|
*
|
||||||
addAccountToProjectCmd.getEntityOwnerId();
|
* try { addAccountToProjectCmd.getEntityOwnerId(); }
|
||||||
} catch(InvalidParameterValueException exception) {
|
* catch(InvalidParameterValueException exception) {
|
||||||
Assert.assertEquals("Unable to find project by id 2", exception.getLocalizedMessage());
|
* Assert.assertEquals("Unable to find project by id 2",
|
||||||
}
|
* exception.getLocalizedMessage()); }
|
||||||
|
*
|
||||||
}*/
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetEntityOwnerIdForProject() {
|
public void testGetEntityOwnerIdForProject() {
|
||||||
@ -109,19 +110,20 @@ public class AddAccountToProjectCmdTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To run the test uncomment the return statement for getAccountName() in setup() and return null
|
* To run the test uncomment the return statement for getAccountName() in
|
||||||
|
* setup() and return null
|
||||||
*
|
*
|
||||||
* **/
|
* **/
|
||||||
|
|
||||||
|
/*
|
||||||
/*@Test
|
* @Test public void testGetEventDescriptionForNullAccount() {
|
||||||
public void testGetEventDescriptionForNullAccount() {
|
*
|
||||||
|
* String result = addAccountToProjectCmd.getEventDescription(); String
|
||||||
String result = addAccountToProjectCmd.getEventDescription();
|
* expected = "Sending invitation to email null to join project: 2";
|
||||||
String expected = "Sending invitation to email null to join project: 2";
|
* Assert.assertEquals(expected, result);
|
||||||
Assert.assertEquals(expected, result);
|
*
|
||||||
|
* }
|
||||||
}*/
|
*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
*
|
*
|
||||||
@ -129,47 +131,45 @@ public class AddAccountToProjectCmdTest extends TestCase {
|
|||||||
*
|
*
|
||||||
* ***/
|
* ***/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Test public void testGetEventDescriptionForAccount() {
|
||||||
/*@Test
|
*
|
||||||
public void testGetEventDescriptionForAccount() {
|
* String result = addAccountToProjectCmd.getEventDescription(); String
|
||||||
|
* expected = "Adding account accountName to project: 2";
|
||||||
String result = addAccountToProjectCmd.getEventDescription();
|
* Assert.assertEquals(expected, result);
|
||||||
String expected = "Adding account accountName to project: 2";
|
*
|
||||||
Assert.assertEquals(expected, result);
|
* }
|
||||||
|
*/
|
||||||
}*/
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForNullAccountNameEmail() {
|
public void testExecuteForNullAccountNameEmail() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addAccountToProjectCmd.execute();
|
addAccountToProjectCmd.execute();
|
||||||
} catch(InvalidParameterValueException exception) {
|
} catch (InvalidParameterValueException exception) {
|
||||||
Assert.assertEquals("Either accountName or email is required", exception.getLocalizedMessage());
|
Assert.assertEquals("Either accountName or email is required",
|
||||||
|
exception.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/*@Test
|
* @Test public void testExecuteForAccountNameEmail() {
|
||||||
public void testExecuteForAccountNameEmail() {
|
*
|
||||||
|
* try {
|
||||||
try {
|
*
|
||||||
|
* ComponentLocator c = Mockito.mock(ComponentLocator.class); UserContext
|
||||||
ComponentLocator c = Mockito.mock(ComponentLocator.class);
|
* userContext = Mockito.mock(UserContext.class);
|
||||||
UserContext userContext = Mockito.mock(UserContext.class);
|
*
|
||||||
|
* // Mockito.when(userContext.current()).thenReturn(userContext);
|
||||||
// Mockito.when(userContext.current()).thenReturn(userContext);
|
*
|
||||||
|
*
|
||||||
|
* addAccountToProjectCmd.execute(); } catch(InvalidParameterValueException
|
||||||
addAccountToProjectCmd.execute();
|
* exception) {
|
||||||
} catch(InvalidParameterValueException exception) {
|
* Assert.assertEquals("Either accountName or email is required",
|
||||||
Assert.assertEquals("Either accountName or email is required", exception.getLocalizedMessage());
|
* exception.getLocalizedMessage()); }
|
||||||
}
|
*
|
||||||
|
* }
|
||||||
}*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import com.cloud.api.ResponseGenerator;
|
import com.cloud.api.ResponseGenerator;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.response.ClusterResponse;
|
import com.cloud.api.commands.AddClusterCmd;
|
||||||
import com.cloud.exception.DiscoveryException;
|
import com.cloud.exception.DiscoveryException;
|
||||||
import com.cloud.exception.ResourceInUseException;
|
import com.cloud.exception.ResourceInUseException;
|
||||||
import com.cloud.org.Cluster;
|
import com.cloud.org.Cluster;
|
||||||
@ -41,27 +41,26 @@ public class AddClusterCmdTest extends TestCase {
|
|||||||
private ResourceService resourceService;
|
private ResourceService resourceService;
|
||||||
private ResponseGenerator responseGenerator;
|
private ResponseGenerator responseGenerator;
|
||||||
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException expectedException = ExpectedException.none();
|
public ExpectedException expectedException = ExpectedException.none();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
/* resourceService = Mockito.mock(ResourceService.class);
|
/*
|
||||||
responseGenerator = Mockito.mock(ResponseGenerator.class);
|
* resourceService = Mockito.mock(ResourceService.class);
|
||||||
*/ addClusterCmd = new AddClusterCmd(){
|
* responseGenerator = Mockito.mock(ResponseGenerator.class);
|
||||||
|
*/addClusterCmd = new AddClusterCmd() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForNullResult() {
|
public void testExecuteForNullResult() {
|
||||||
|
|
||||||
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mockito.when(resourceService.discoverCluster(addClusterCmd)).thenReturn(null);
|
Mockito.when(resourceService.discoverCluster(addClusterCmd))
|
||||||
|
.thenReturn(null);
|
||||||
} catch (ResourceInUseException e) {
|
} catch (ResourceInUseException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -78,12 +77,12 @@ public class AddClusterCmdTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
addClusterCmd.execute();
|
addClusterCmd.execute();
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add cluster", exception.getDescription());
|
Assert.assertEquals("Failed to add cluster",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForEmptyResult() {
|
public void testExecuteForEmptyResult() {
|
||||||
|
|
||||||
@ -93,12 +92,12 @@ public class AddClusterCmdTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
addClusterCmd.execute();
|
addClusterCmd.execute();
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add cluster", exception.getDescription());
|
Assert.assertEquals("Failed to add cluster",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForResult() throws Exception {
|
public void testExecuteForResult() throws Exception {
|
||||||
|
|
||||||
@ -109,15 +108,13 @@ public class AddClusterCmdTest extends TestCase {
|
|||||||
addClusterCmd._responseGenerator = responseGenerator;
|
addClusterCmd._responseGenerator = responseGenerator;
|
||||||
|
|
||||||
Cluster cluster = Mockito.mock(Cluster.class);
|
Cluster cluster = Mockito.mock(Cluster.class);
|
||||||
Cluster[] clusterArray = new Cluster[]{cluster};
|
Cluster[] clusterArray = new Cluster[] { cluster };
|
||||||
|
|
||||||
Mockito.when(resourceService.discoverCluster(addClusterCmd)).thenReturn(Arrays.asList(clusterArray));
|
Mockito.when(resourceService.discoverCluster(addClusterCmd))
|
||||||
|
.thenReturn(Arrays.asList(clusterArray));
|
||||||
|
|
||||||
addClusterCmd.execute();
|
addClusterCmd.execute();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,11 +16,6 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.api.commands.test;
|
package src.com.cloud.api.commands.test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -32,15 +27,13 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import com.cloud.api.ResponseGenerator;
|
import com.cloud.api.ResponseGenerator;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.AddHostCmd;
|
||||||
import com.cloud.api.response.HostResponse;
|
import com.cloud.api.response.HostResponse;
|
||||||
import com.cloud.api.response.ListResponse;
|
import com.cloud.api.response.ListResponse;
|
||||||
import com.cloud.exception.DiscoveryException;
|
import com.cloud.exception.DiscoveryException;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.Status;
|
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|
||||||
import com.cloud.resource.ResourceService;
|
import com.cloud.resource.ResourceService;
|
||||||
import com.cloud.resource.ResourceState;
|
|
||||||
|
|
||||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||||
|
|
||||||
@ -57,7 +50,7 @@ public class AddHostCmdTest extends TestCase {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
resourceService = Mockito.mock(ResourceService.class);
|
resourceService = Mockito.mock(ResourceService.class);
|
||||||
responseGenerator = Mockito.mock(ResponseGenerator.class);
|
responseGenerator = Mockito.mock(ResponseGenerator.class);
|
||||||
addHostCmd = new AddHostCmd(){
|
addHostCmd = new AddHostCmd() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,13 +60,13 @@ public class AddHostCmdTest extends TestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
addHostCmd.execute();
|
addHostCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add host", exception.getDescription());
|
Assert.assertEquals("Failed to add host",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForNullResult() {
|
public void testExecuteForNullResult() {
|
||||||
|
|
||||||
@ -81,7 +74,8 @@ public class AddHostCmdTest extends TestCase {
|
|||||||
addHostCmd._resourceService = resourceService;
|
addHostCmd._resourceService = resourceService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(null);
|
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(
|
||||||
|
null);
|
||||||
} catch (InvalidParameterValueException e) {
|
} catch (InvalidParameterValueException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -95,59 +89,63 @@ public class AddHostCmdTest extends TestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
addHostCmd.execute();
|
addHostCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add host", exception.getDescription());
|
Assert.assertEquals("Failed to add host",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/* @Test
|
* @Test public void testExecuteForResult() throws Exception {
|
||||||
public void testExecuteForResult() throws Exception {
|
*
|
||||||
|
* addHostCmd._resourceService = resourceService;
|
||||||
addHostCmd._resourceService = resourceService;
|
* addHostCmd._responseGenerator = responseGenerator; MockHost mockInstance
|
||||||
addHostCmd._responseGenerator = responseGenerator;
|
* = new MockHost(); MockHost[] mockArray = new MockHost[]{mockInstance};
|
||||||
MockHost mockInstance = new MockHost();
|
* HostResponse responseHost = new HostResponse();
|
||||||
MockHost[] mockArray = new MockHost[]{mockInstance};
|
* responseHost.setName("Test");
|
||||||
HostResponse responseHost = new HostResponse();
|
* Mockito.when(resourceService.discoverHosts(addHostCmd
|
||||||
responseHost.setName("Test");
|
* )).thenReturn(Arrays.asList(mockArray));
|
||||||
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(Arrays.asList(mockArray));
|
* Mockito.when(responseGenerator.createHostResponse
|
||||||
Mockito.when(responseGenerator.createHostResponse(mockInstance)).thenReturn(responseHost);
|
* (mockInstance)).thenReturn(responseHost); addHostCmd.execute();
|
||||||
addHostCmd.execute();
|
* Mockito.verify(responseGenerator).createHostResponse(mockInstance);
|
||||||
Mockito.verify(responseGenerator).createHostResponse(mockInstance);
|
* ListResponse<HostResponse> actualResponse =
|
||||||
ListResponse<HostResponse> actualResponse = ((ListResponse<HostResponse>)addHostCmd.getResponseObject());
|
* ((ListResponse<HostResponse>)addHostCmd.getResponseObject());
|
||||||
Assert.assertEquals(responseHost, actualResponse.getResponses().get(0));
|
* Assert.assertEquals(responseHost, actualResponse.getResponses().get(0));
|
||||||
Assert.assertEquals("addhostresponse", actualResponse.getResponseName());
|
* Assert.assertEquals("addhostresponse", actualResponse.getResponseName());
|
||||||
}
|
* }
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForResult() throws Exception {
|
public void testExecuteForResult() throws Exception {
|
||||||
|
|
||||||
addHostCmd._resourceService = resourceService;
|
addHostCmd._resourceService = resourceService;
|
||||||
addHostCmd._responseGenerator = responseGenerator;
|
addHostCmd._responseGenerator = responseGenerator;
|
||||||
Host host = Mockito.mock(Host.class);
|
Host host = Mockito.mock(Host.class);
|
||||||
Host[] mockArray = new Host[]{host};
|
Host[] mockArray = new Host[] { host };
|
||||||
|
|
||||||
HostResponse responseHost = new HostResponse();
|
HostResponse responseHost = new HostResponse();
|
||||||
responseHost.setName("Test");
|
responseHost.setName("Test");
|
||||||
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(Arrays.asList(mockArray));
|
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(
|
||||||
Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(responseHost);
|
Arrays.asList(mockArray));
|
||||||
|
Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(
|
||||||
|
responseHost);
|
||||||
addHostCmd.execute();
|
addHostCmd.execute();
|
||||||
Mockito.verify(responseGenerator).createHostResponse(host);
|
Mockito.verify(responseGenerator).createHostResponse(host);
|
||||||
ListResponse<HostResponse> actualResponse = ((ListResponse<HostResponse>)addHostCmd.getResponseObject());
|
ListResponse<HostResponse> actualResponse = ((ListResponse<HostResponse>) addHostCmd
|
||||||
|
.getResponseObject());
|
||||||
Assert.assertEquals(responseHost, actualResponse.getResponses().get(0));
|
Assert.assertEquals(responseHost, actualResponse.getResponses().get(0));
|
||||||
Assert.assertEquals("addhostresponse", actualResponse.getResponseName());
|
Assert.assertEquals("addhostresponse", actualResponse.getResponseName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForDiscoveryException() {
|
public void testExecuteForDiscoveryException() {
|
||||||
|
|
||||||
addHostCmd._resourceService = resourceService;
|
addHostCmd._resourceService = resourceService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow(DiscoveryException.class);
|
Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow(
|
||||||
|
DiscoveryException.class);
|
||||||
} catch (InvalidParameterValueException e) {
|
} catch (InvalidParameterValueException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -158,12 +156,10 @@ public class AddHostCmdTest extends TestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
addHostCmd.execute();
|
addHostCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertNull(exception.getDescription());
|
Assert.assertNull(exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import org.junit.rules.ExpectedException;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.AddNetworkServiceProviderCmd;
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.network.NetworkService;
|
import com.cloud.network.NetworkService;
|
||||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||||
@ -80,8 +81,10 @@ public class AddNetworkServiceProviderCmdTest extends TestCase {
|
|||||||
NetworkService networkService = Mockito.mock(NetworkService.class);
|
NetworkService networkService = Mockito.mock(NetworkService.class);
|
||||||
addNetworkServiceProviderCmd._networkService = networkService;
|
addNetworkServiceProviderCmd._networkService = networkService;
|
||||||
|
|
||||||
PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class);
|
PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito
|
||||||
Mockito.when(networkService.addProviderToPhysicalNetwork(Mockito.anyLong(),
|
.mock(PhysicalNetworkServiceProvider.class);
|
||||||
|
Mockito.when(
|
||||||
|
networkService.addProviderToPhysicalNetwork(Mockito.anyLong(),
|
||||||
Mockito.anyString(), Mockito.anyLong(),
|
Mockito.anyString(), Mockito.anyLong(),
|
||||||
Mockito.anyList())).thenReturn(
|
Mockito.anyList())).thenReturn(
|
||||||
physicalNetworkServiceProvider);
|
physicalNetworkServiceProvider);
|
||||||
@ -94,25 +97,26 @@ public class AddNetworkServiceProviderCmdTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocationException {
|
public void testCreateProviderToPhysicalNetworkFailure()
|
||||||
|
throws ResourceAllocationException {
|
||||||
|
|
||||||
NetworkService networkService = Mockito.mock(NetworkService.class);
|
NetworkService networkService = Mockito.mock(NetworkService.class);
|
||||||
addNetworkServiceProviderCmd._networkService = networkService;
|
addNetworkServiceProviderCmd._networkService = networkService;
|
||||||
|
|
||||||
Mockito.when(networkService.addProviderToPhysicalNetwork(Mockito.anyLong(),
|
Mockito.when(
|
||||||
|
networkService.addProviderToPhysicalNetwork(Mockito.anyLong(),
|
||||||
Mockito.anyString(), Mockito.anyLong(),
|
Mockito.anyString(), Mockito.anyLong(),
|
||||||
Mockito.anyList())).thenReturn(null);
|
Mockito.anyList())).thenReturn(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addNetworkServiceProviderCmd.create();
|
addNetworkServiceProviderCmd.create();
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add service provider entity to physical network", exception.getDescription());
|
Assert.assertEquals(
|
||||||
|
"Failed to add service provider entity to physical network",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,10 +27,8 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import com.cloud.api.ResponseGenerator;
|
import com.cloud.api.ResponseGenerator;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.AddSecondaryStorageCmd;
|
||||||
import com.cloud.api.response.HostResponse;
|
import com.cloud.api.response.HostResponse;
|
||||||
import com.cloud.api.response.ListResponse;
|
|
||||||
import com.cloud.exception.DiscoveryException;
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.resource.ResourceService;
|
import com.cloud.resource.ResourceService;
|
||||||
|
|
||||||
@ -50,7 +48,6 @@ public class AddSecondaryStorageCmdTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteForResult() throws Exception {
|
public void testExecuteForResult() throws Exception {
|
||||||
|
|
||||||
@ -58,27 +55,31 @@ public class AddSecondaryStorageCmdTest extends TestCase {
|
|||||||
addSecondaryStorageCmd._resourceService = resourceService;
|
addSecondaryStorageCmd._resourceService = resourceService;
|
||||||
|
|
||||||
Host host = Mockito.mock(Host.class);
|
Host host = Mockito.mock(Host.class);
|
||||||
Host[] mockHosts = new Host[] {host};
|
Host[] mockHosts = new Host[] { host };
|
||||||
|
|
||||||
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)).thenReturn(Arrays.asList(mockHosts));
|
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
|
||||||
|
.thenReturn(Arrays.asList(mockHosts));
|
||||||
|
|
||||||
ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
|
ResponseGenerator responseGenerator = Mockito
|
||||||
|
.mock(ResponseGenerator.class);
|
||||||
addSecondaryStorageCmd._responseGenerator = responseGenerator;
|
addSecondaryStorageCmd._responseGenerator = responseGenerator;
|
||||||
|
|
||||||
HostResponse responseHost = new HostResponse();
|
HostResponse responseHost = new HostResponse();
|
||||||
responseHost.setName("Test");
|
responseHost.setName("Test");
|
||||||
|
|
||||||
Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(responseHost);
|
Mockito.when(responseGenerator.createHostResponse(host)).thenReturn(
|
||||||
|
responseHost);
|
||||||
|
|
||||||
addSecondaryStorageCmd.execute();
|
addSecondaryStorageCmd.execute();
|
||||||
|
|
||||||
Mockito.verify(responseGenerator).createHostResponse(host);
|
Mockito.verify(responseGenerator).createHostResponse(host);
|
||||||
|
|
||||||
HostResponse actualResponse = (HostResponse)addSecondaryStorageCmd.getResponseObject();
|
HostResponse actualResponse = (HostResponse) addSecondaryStorageCmd
|
||||||
|
.getResponseObject();
|
||||||
|
|
||||||
Assert.assertEquals(responseHost, actualResponse);
|
Assert.assertEquals(responseHost, actualResponse);
|
||||||
Assert.assertEquals("addsecondarystorageresponse", actualResponse.getResponseName());
|
Assert.assertEquals("addsecondarystorageresponse",
|
||||||
|
actualResponse.getResponseName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,12 +91,14 @@ public class AddSecondaryStorageCmdTest extends TestCase {
|
|||||||
|
|
||||||
Host[] mockHosts = new Host[] {};
|
Host[] mockHosts = new Host[] {};
|
||||||
|
|
||||||
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)).thenReturn(Arrays.asList(mockHosts));
|
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
|
||||||
|
.thenReturn(Arrays.asList(mockHosts));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addSecondaryStorageCmd.execute();
|
addSecondaryStorageCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add secondary storage", exception.getDescription());
|
Assert.assertEquals("Failed to add secondary storage",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -106,15 +109,16 @@ public class AddSecondaryStorageCmdTest extends TestCase {
|
|||||||
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
||||||
addSecondaryStorageCmd._resourceService = resourceService;
|
addSecondaryStorageCmd._resourceService = resourceService;
|
||||||
|
|
||||||
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd)).thenReturn(null);
|
Mockito.when(resourceService.discoverHosts(addSecondaryStorageCmd))
|
||||||
|
.thenReturn(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addSecondaryStorageCmd.execute();
|
addSecondaryStorageCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add secondary storage", exception.getDescription());
|
Assert.assertEquals("Failed to add secondary storage",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,9 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package src.com.cloud.api.commands.test;
|
package src.com.cloud.api.commands.test;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -24,14 +27,12 @@ import org.mockito.Mockito;
|
|||||||
|
|
||||||
import com.cloud.api.ResponseGenerator;
|
import com.cloud.api.ResponseGenerator;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.AddSwiftCmd;
|
||||||
import com.cloud.api.response.SwiftResponse;
|
import com.cloud.api.response.SwiftResponse;
|
||||||
import com.cloud.exception.DiscoveryException;
|
import com.cloud.exception.DiscoveryException;
|
||||||
import com.cloud.resource.ResourceService;
|
import com.cloud.resource.ResourceService;
|
||||||
import com.cloud.storage.Swift;
|
import com.cloud.storage.Swift;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class AddSwiftCmdTest extends TestCase {
|
public class AddSwiftCmdTest extends TestCase {
|
||||||
|
|
||||||
private AddSwiftCmd addSwiftCmd;
|
private AddSwiftCmd addSwiftCmd;
|
||||||
@ -53,38 +54,42 @@ public class AddSwiftCmdTest extends TestCase {
|
|||||||
Swift swift = Mockito.mock(Swift.class);
|
Swift swift = Mockito.mock(Swift.class);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Mockito.when(resourceService.discoverSwift(addSwiftCmd)).thenReturn(swift);
|
Mockito.when(resourceService.discoverSwift(addSwiftCmd))
|
||||||
|
.thenReturn(swift);
|
||||||
} catch (DiscoveryException e) {
|
} catch (DiscoveryException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
|
ResponseGenerator responseGenerator = Mockito
|
||||||
|
.mock(ResponseGenerator.class);
|
||||||
addSwiftCmd._responseGenerator = responseGenerator;
|
addSwiftCmd._responseGenerator = responseGenerator;
|
||||||
|
|
||||||
SwiftResponse swiftResponse = Mockito.mock(SwiftResponse.class);
|
SwiftResponse swiftResponse = Mockito.mock(SwiftResponse.class);
|
||||||
|
|
||||||
Mockito.when(responseGenerator.createSwiftResponse(swift)).thenReturn(swiftResponse);
|
Mockito.when(responseGenerator.createSwiftResponse(swift)).thenReturn(
|
||||||
|
swiftResponse);
|
||||||
|
|
||||||
addSwiftCmd.execute();
|
addSwiftCmd.execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteFailure() {
|
public void testExecuteFailure() {
|
||||||
|
|
||||||
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
ResourceService resourceService = Mockito.mock(ResourceService.class);
|
||||||
addSwiftCmd._resourceService = resourceService;
|
addSwiftCmd._resourceService = resourceService;
|
||||||
try {
|
try {
|
||||||
Mockito.when(resourceService.discoverSwift(addSwiftCmd)).thenReturn(null);
|
Mockito.when(resourceService.discoverSwift(addSwiftCmd))
|
||||||
|
.thenReturn(null);
|
||||||
} catch (DiscoveryException e) {
|
} catch (DiscoveryException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addSwiftCmd.execute();
|
addSwiftCmd.execute();
|
||||||
} catch(ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add Swift", exception.getDescription());
|
Assert.assertEquals("Failed to add Swift",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.junit.rules.ExpectedException;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.AddVpnUserCmd;
|
||||||
import com.cloud.network.VpnUser;
|
import com.cloud.network.VpnUser;
|
||||||
import com.cloud.network.vpn.RemoteAccessVpnService;
|
import com.cloud.network.vpn.RemoteAccessVpnService;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -33,7 +34,6 @@ import com.cloud.user.AccountService;
|
|||||||
|
|
||||||
public class AddVpnUserCmdTest extends TestCase {
|
public class AddVpnUserCmdTest extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
private AddVpnUserCmd addVpnUserCmd;
|
private AddVpnUserCmd addVpnUserCmd;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@ -67,49 +67,50 @@ public class AddVpnUserCmdTest extends TestCase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Test
|
/*
|
||||||
public void testExecuteVpnUserNotFound() {
|
* @Test public void testExecuteVpnUserNotFound() {
|
||||||
|
*
|
||||||
EntityManager entityManager = Mockito.mock(EntityManager.class);
|
* EntityManager entityManager = Mockito.mock(EntityManager.class);
|
||||||
|
*
|
||||||
Mockito.when(entityManager.findById(VpnUser.class, Mockito.anyLong())).thenReturn(null);
|
* Mockito.when(entityManager.findById(VpnUser.class,
|
||||||
|
* Mockito.anyLong())).thenReturn(null);
|
||||||
addVpnUserCmd._entityMgr = entityManager;
|
*
|
||||||
try {
|
* addVpnUserCmd._entityMgr = entityManager; try { addVpnUserCmd.execute();
|
||||||
addVpnUserCmd.execute();
|
* } catch (Exception e) { }
|
||||||
} catch (Exception e) {
|
*
|
||||||
}
|
* }
|
||||||
|
*
|
||||||
}
|
*
|
||||||
|
* @Test public void testExecuteVpnUserFound() {
|
||||||
|
*
|
||||||
@Test
|
* EntityManager entityManager = Mockito.mock(EntityManager.class);
|
||||||
public void testExecuteVpnUserFound() {
|
* addVpnUserCmd._entityMgr = entityManager;
|
||||||
|
*
|
||||||
EntityManager entityManager = Mockito.mock(EntityManager.class);
|
* VpnUser vpnUser = Mockito.mock(VpnUser.class);
|
||||||
addVpnUserCmd._entityMgr = entityManager;
|
* Mockito.when(entityManager.findById(VpnUser.class,
|
||||||
|
* Mockito.anyLong())).thenReturn(vpnUser); addVpnUserCmd.execute();
|
||||||
VpnUser vpnUser = Mockito.mock(VpnUser.class);
|
*
|
||||||
Mockito.when(entityManager.findById(VpnUser.class, Mockito.anyLong())).thenReturn(vpnUser);
|
* }
|
||||||
addVpnUserCmd.execute();
|
*/
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateSuccess() {
|
public void testCreateSuccess() {
|
||||||
|
|
||||||
|
|
||||||
AccountService accountService = Mockito.mock(AccountService.class);
|
AccountService accountService = Mockito.mock(AccountService.class);
|
||||||
|
|
||||||
Account account = Mockito.mock(Account.class);
|
Account account = Mockito.mock(Account.class);
|
||||||
Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn(account);
|
Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn(
|
||||||
|
account);
|
||||||
|
|
||||||
addVpnUserCmd._accountService = accountService;
|
addVpnUserCmd._accountService = accountService;
|
||||||
|
|
||||||
RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class);
|
RemoteAccessVpnService ravService = Mockito
|
||||||
|
.mock(RemoteAccessVpnService.class);
|
||||||
|
|
||||||
VpnUser vpnUser = Mockito.mock(VpnUser.class);
|
VpnUser vpnUser = Mockito.mock(VpnUser.class);
|
||||||
Mockito.when(ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(vpnUser);
|
Mockito.when(
|
||||||
|
ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(),
|
||||||
|
Mockito.anyString())).thenReturn(vpnUser);
|
||||||
|
|
||||||
addVpnUserCmd._ravService = ravService;
|
addVpnUserCmd._ravService = ravService;
|
||||||
|
|
||||||
@ -117,25 +118,29 @@ public class AddVpnUserCmdTest extends TestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateFailure() {
|
public void testCreateFailure() {
|
||||||
|
|
||||||
AccountService accountService = Mockito.mock(AccountService.class);
|
AccountService accountService = Mockito.mock(AccountService.class);
|
||||||
Account account = Mockito.mock(Account.class);
|
Account account = Mockito.mock(Account.class);
|
||||||
Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn(account);
|
Mockito.when(accountService.getAccount(Mockito.anyLong())).thenReturn(
|
||||||
|
account);
|
||||||
|
|
||||||
addVpnUserCmd._accountService = accountService;
|
addVpnUserCmd._accountService = accountService;
|
||||||
|
|
||||||
RemoteAccessVpnService ravService = Mockito.mock(RemoteAccessVpnService.class);
|
RemoteAccessVpnService ravService = Mockito
|
||||||
Mockito.when(ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(null);
|
.mock(RemoteAccessVpnService.class);
|
||||||
|
Mockito.when(
|
||||||
|
ravService.addVpnUser(Mockito.anyLong(), Mockito.anyString(),
|
||||||
|
Mockito.anyString())).thenReturn(null);
|
||||||
|
|
||||||
addVpnUserCmd._ravService = ravService;
|
addVpnUserCmd._ravService = ravService;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addVpnUserCmd.create();
|
addVpnUserCmd.create();
|
||||||
} catch (ServerApiException exception) {
|
} catch (ServerApiException exception) {
|
||||||
Assert.assertEquals("Failed to add vpn user", exception.getDescription());
|
Assert.assertEquals("Failed to add vpn user",
|
||||||
|
exception.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user