Skip to content

Commit b1c0632

Browse files
committed
Reworked the formatting and structure of the api project's unit tests.
Signed-off-by: Chip Childers <chip.childers@gmail.com>
1 parent e953b77 commit b1c0632

28 files changed

Lines changed: 2109 additions & 1827 deletions

api/src/com/cloud/agent/api/CheckNetworkCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
public class CheckNetworkCommand extends Command {
2424

2525
List<PhysicalNetworkSetupInfo> networkInfoList;
26-
26+
2727
public CheckNetworkCommand(List<PhysicalNetworkSetupInfo> networkInfoList) {
2828
this.networkInfoList = networkInfoList;
2929
}
30-
30+
3131
public List<PhysicalNetworkSetupInfo> getPhysicalNetworkInfoList() {
3232
return networkInfoList;
3333
}
34-
34+
3535
protected CheckNetworkCommand() {
3636
}
37-
37+
3838
@Override
3939
public boolean executeInSequence() {
4040
return true;

api/src/com/cloud/agent/api/SnapshotCommand.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,38 @@
1717
package com.cloud.agent.api;
1818

1919
/**
20-
* This currently assumes that both primary and secondary storage are mounted on the XenServer.
20+
* This currently assumes that both primary and secondary storage are mounted on
21+
* the XenServer.
2122
*/
2223
public class SnapshotCommand extends Command {
2324
protected String primaryStoragePoolNameLabel;
2425
private String snapshotUuid;
2526
private String snapshotName;
2627
private String secondaryStorageUrl;
27-
private Long dcId;
28-
private Long accountId;
29-
private Long volumeId;
28+
private Long dcId;
29+
private Long accountId;
30+
private Long volumeId;
3031
private String volumePath;
31-
32+
3233
protected SnapshotCommand() {
33-
34+
3435
}
35-
36+
3637
/**
37-
* @param primaryStoragePoolNameLabel The primary storage Pool
38-
* @param snapshotUuid The UUID of the snapshot which is going to be backed up
39-
* @param secondaryStoragePoolURL This is what shows up in the UI when you click on Secondary storage.
40-
* 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
41-
* If you have better ideas on how to get it, you are welcome.
38+
* @param primaryStoragePoolNameLabel
39+
* The primary storage Pool
40+
* @param snapshotUuid
41+
* The UUID of the snapshot which is going to be backed up
42+
* @param secondaryStoragePoolURL
43+
* This is what shows up in the UI when you click on Secondary
44+
* storage. In the code, it is present as: In the
45+
* vmops.host_details table, there is a field mount.parent. This
46+
* is the value of that field If you have better ideas on how to
47+
* get it, you are welcome.
4248
*/
4349
public SnapshotCommand(String primaryStoragePoolNameLabel,
44-
String secondaryStorageUrl,
45-
String snapshotUuid,
46-
String snapshotName,
47-
Long dcId,
48-
Long accountId,
49-
Long volumeId)
50-
{
50+
String secondaryStorageUrl, String snapshotUuid,
51+
String snapshotName, Long dcId, Long accountId, Long volumeId) {
5152
this.primaryStoragePoolNameLabel = primaryStoragePoolNameLabel;
5253
this.snapshotUuid = snapshotUuid;
5354
this.secondaryStorageUrl = secondaryStorageUrl;
@@ -70,19 +71,18 @@ public String getPrimaryStoragePoolNameLabel() {
7071
public String getSnapshotUuid() {
7172
return snapshotUuid;
7273
}
73-
74+
7475
public String getSnapshotName() {
75-
return snapshotName;
76+
return snapshotName;
7677
}
77-
78+
7879
/**
7980
* @return the secondaryStoragePoolURL
8081
*/
8182
public String getSecondaryStorageUrl() {
8283
return secondaryStorageUrl;
8384
}
8485

85-
8686
public Long getDataCenterId() {
8787
return dcId;
8888
}
@@ -94,13 +94,13 @@ public Long getAccountId() {
9494
public Long getVolumeId() {
9595
return volumeId;
9696
}
97-
97+
9898
public String getVolumePath() {
99-
return volumePath;
99+
return volumePath;
100100
}
101-
101+
102102
public void setVolumePath(String path) {
103-
volumePath = path;
103+
volumePath = path;
104104
}
105105

106106
/**

api/test/src/com/cloud/agent/api/test/AgentControlAnswerTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
// under the License.
1717
package src.com.cloud.agent.api.test;
1818

19-
import com.cloud.agent.api.*;
20-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertFalse;
20+
2121
import org.junit.Test;
2222

23+
import com.cloud.agent.api.AgentControlAnswer;
24+
import com.cloud.agent.api.AgentControlCommand;
25+
2326
public class AgentControlAnswerTest {
24-
AgentControlCommand acc = new AgentControlCommand();
25-
AgentControlAnswer aca = new AgentControlAnswer(acc);
27+
AgentControlCommand acc = new AgentControlCommand();
28+
AgentControlAnswer aca = new AgentControlAnswer(acc);
2629

27-
@Test
28-
public void testExecuteInSequence() {
29-
boolean b = acc.executeInSequence();
30-
assertFalse(b);
31-
}
30+
@Test
31+
public void testExecuteInSequence() {
32+
boolean b = acc.executeInSequence();
33+
assertFalse(b);
34+
}
3235
}

api/test/src/com/cloud/agent/api/test/AgentControlCommandTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
// under the License.
1717
package src.com.cloud.agent.api.test;
1818

19-
import com.cloud.agent.api.*;
20-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertFalse;
20+
2121
import org.junit.Test;
2222

23+
import com.cloud.agent.api.AgentControlCommand;
24+
2325
public class AgentControlCommandTest {
24-
AgentControlCommand acc = new AgentControlCommand();
26+
AgentControlCommand acc = new AgentControlCommand();
2527

26-
@Test
27-
public void testExecuteInSequence() {
28-
boolean b = acc.executeInSequence();
29-
assertFalse(b);
30-
}
28+
@Test
29+
public void testExecuteInSequence() {
30+
boolean b = acc.executeInSequence();
31+
assertFalse(b);
32+
}
3133
}

api/test/src/com/cloud/agent/api/test/AnswerTest.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,58 @@
1616
// under the License.
1717
package src.com.cloud.agent.api.test;
1818

19-
import com.cloud.agent.api.*;
20-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
21+
2122
import org.junit.Test;
2223

24+
import com.cloud.agent.api.AgentControlCommand;
25+
import com.cloud.agent.api.Answer;
26+
import com.cloud.agent.api.UnsupportedAnswer;
27+
2328
public class AnswerTest {
24-
AgentControlCommand acc = new AgentControlCommand();
25-
Answer a = new Answer(acc, true, "details");
29+
AgentControlCommand acc = new AgentControlCommand();
30+
Answer a = new Answer(acc, true, "details");
31+
32+
@Test
33+
public void testExecuteInSequence() {
34+
boolean b = a.executeInSequence();
35+
assertFalse(b);
36+
}
37+
38+
@Test
39+
public void testGetResult() {
40+
boolean b = a.getResult();
41+
assertTrue(b);
42+
}
2643

27-
@Test
28-
public void testExecuteInSequence() {
29-
boolean b = a.executeInSequence();
30-
assertFalse(b);
31-
}
44+
@Test
45+
public void testGetDetails() {
46+
String d = a.getDetails();
47+
assertTrue(d.equals("details"));
48+
}
3249

33-
@Test
34-
public void testGetResult() {
35-
boolean b = a.getResult();
36-
assertTrue(b);
37-
}
50+
@Test
51+
public void testCreateUnsupportedCommandAnswer() {
52+
UnsupportedAnswer usa = Answer.createUnsupportedCommandAnswer(acc);
53+
boolean b = usa.executeInSequence();
54+
assertFalse(b);
3855

39-
@Test
40-
public void testGetDetails() {
41-
String d = a.getDetails();
42-
assertTrue(d.equals("details"));
43-
}
56+
b = usa.getResult();
57+
assertFalse(b);
4458

45-
@Test
46-
public void testCreateUnsupportedCommandAnswer() {
47-
UnsupportedAnswer usa = Answer.createUnsupportedCommandAnswer(acc);
48-
boolean b = usa.executeInSequence();
49-
assertFalse(b);
50-
51-
b = usa.getResult();
52-
assertFalse(b);
59+
String d = usa.getDetails();
60+
assertTrue(d.equals("Unsupported command issued:" + acc.toString()
61+
+ ". Are you sure you got the right type of server?"));
5362

54-
String d = usa.getDetails();
55-
assertTrue(d.equals("Unsupported command issued:" + acc.toString() + ". Are you sure you got the right type of server?"));
63+
usa = Answer.createUnsupportedVersionAnswer(acc);
64+
b = usa.executeInSequence();
65+
assertFalse(b);
5666

57-
usa = Answer.createUnsupportedVersionAnswer(acc);
58-
b = usa.executeInSequence();
59-
assertFalse(b);
60-
61-
b = usa.getResult();
62-
assertFalse(b);
67+
b = usa.getResult();
68+
assertFalse(b);
6369

64-
d = usa.getDetails();
65-
assertTrue(d.equals("Unsuppored Version."));
66-
}
70+
d = usa.getDetails();
71+
assertTrue(d.equals("Unsuppored Version."));
72+
}
6773
}

api/test/src/com/cloud/agent/api/test/AttachIsoCommandTest.java

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,65 @@
1616
// under the License.
1717
package src.com.cloud.agent.api.test;
1818

19-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
22+
2023
import org.junit.Test;
2124

22-
import com.cloud.agent.api.*;
25+
import com.cloud.agent.api.AttachIsoCommand;
2326

2427
public class AttachIsoCommandTest {
25-
AttachIsoCommand aic = new AttachIsoCommand("vmname", "isopath", false);
28+
AttachIsoCommand aic = new AttachIsoCommand("vmname", "isopath", false);
29+
30+
@Test
31+
public void testGetVmName() {
32+
String vmName = aic.getVmName();
33+
assertTrue(vmName.equals("vmname"));
34+
}
35+
36+
@Test
37+
public void testGetIsoPath() {
38+
String isoPath = aic.getIsoPath();
39+
assertTrue(isoPath.equals("isopath"));
40+
}
41+
42+
@Test
43+
public void testIsAttach() {
44+
boolean b = aic.isAttach();
45+
assertFalse(b);
46+
}
47+
48+
@Test
49+
public void testGetStoreUrl() {
50+
aic.setStoreUrl("http://incubator.apache.org/cloudstack/");
51+
String url = aic.getStoreUrl();
52+
assertTrue(url.equals("http://incubator.apache.org/cloudstack/"));
53+
}
2654

27-
@Test
28-
public void testGetVmName() {
29-
String vmName = aic.getVmName();
30-
assertTrue(vmName.equals("vmname"));
31-
}
55+
@Test
56+
public void testExecuteInSequence() {
57+
boolean b = aic.executeInSequence();
58+
assertTrue(b);
59+
}
3260

33-
@Test
34-
public void testGetIsoPath() {
35-
String isoPath = aic.getIsoPath();
36-
assertTrue(isoPath.equals("isopath"));
37-
}
38-
39-
@Test
40-
public void testIsAttach() {
41-
boolean b = aic.isAttach();
42-
assertFalse(b);
43-
}
61+
@Test
62+
public void testAllowCaching() {
63+
boolean b = aic.allowCaching();
64+
assertTrue(b);
65+
}
4466

45-
@Test
46-
public void testGetStoreUrl() {
47-
aic.setStoreUrl("http://incubator.apache.org/cloudstack/");
48-
String url = aic.getStoreUrl();
49-
assertTrue(url.equals("http://incubator.apache.org/cloudstack/"));
50-
}
51-
52-
@Test
53-
public void testExecuteInSequence() {
54-
boolean b = aic.executeInSequence();
55-
assertTrue(b);
56-
}
57-
58-
@Test
59-
public void testAllowCaching() {
60-
boolean b = aic.allowCaching();
61-
assertTrue(b);
62-
}
63-
64-
@Test
65-
public void testGetWait() {
66-
int b;
67-
aic.setWait(5);
68-
b = aic.getWait();
69-
assertEquals(b, 5);
70-
aic.setWait(-3);
71-
b = aic.getWait();
72-
assertEquals(b, -3);
73-
aic.setWait(0);
74-
b = aic.getWait();
75-
assertEquals(b, 0);
76-
}
67+
@Test
68+
public void testGetWait() {
69+
int b;
70+
aic.setWait(5);
71+
b = aic.getWait();
72+
assertEquals(b, 5);
73+
aic.setWait(-3);
74+
b = aic.getWait();
75+
assertEquals(b, -3);
76+
aic.setWait(0);
77+
b = aic.getWait();
78+
assertEquals(b, 0);
79+
}
7780
}

0 commit comments

Comments
 (0)