Skip to content

Commit 7bdd703

Browse files
committed
more tests, fix pre-commit
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 568c1aa commit 7bdd703

25 files changed

Lines changed: 1527 additions & 6 deletions

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class DeployVMCmd extends BaseDeployVMCmd {
6666
@Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.UUID, entityType = SnapshotResponse.class, since = "4.21")
6767
private Long snapshotId;
6868

69-
@Parameter(name = "blank", type = CommandType.BOOLEAN, since = "4.22.1")
69+
@Parameter(name = "blank", type = CommandType.BOOLEAN, since = "4.23.0")
7070
private Boolean blankInstance;
7171

7272

api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
114114
type = CommandType.UUID,
115115
entityType = StoragePoolResponse.class,
116116
description = "Storage pool ID to create the volume in. Cannot be used with the snapshotid parameter.",
117-
authorized = {RoleType.Admin})
117+
authorized = {RoleType.Admin},
118+
since = "4.23.0")
118119
private Long storageId;
119120

120121
/////////////////////////////////////////////////////
@@ -150,6 +151,10 @@ public Long getMaxIops() {
150151
}
151152

152153
public Long getSnapshotId() {
154+
if (storageId != null && snapshotId != null) {
155+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
156+
"Snapshot ID cannot be specified with the Storage ID.");
157+
}
153158
return snapshotId;
154159
}
155160

@@ -164,7 +169,7 @@ private Long getProjectId() {
164169
public Long getStorageId() {
165170
if (snapshotId != null && storageId != null) {
166171
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
167-
"StorageId parameter cannot be specified with the SnapshotId parameter.");
172+
"Storage ID cannot be specified with the Snapshot ID.");
168173
}
169174
return storageId;
170175
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.admin.vm;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.springframework.test.util.ReflectionTestUtils;
23+
24+
public class AssignVMCmdTest {
25+
26+
@Test
27+
public void test_setSkipNetwork_default() {
28+
AssignVMCmd assignVMCmd = new AssignVMCmd();
29+
Object value = ReflectionTestUtils.getField(assignVMCmd, "skipNetwork");
30+
Assert.assertTrue(value instanceof Boolean);
31+
Assert.assertFalse((Boolean) value);
32+
}
33+
34+
@Test
35+
public void test_setSkipNetwork_set() {
36+
AssignVMCmd assignVMCmd = new AssignVMCmd();
37+
assignVMCmd.setSkipNetwork(true);
38+
Object value = ReflectionTestUtils.getField(assignVMCmd, "skipNetwork");
39+
Assert.assertTrue(value instanceof Boolean);
40+
Assert.assertTrue((Boolean) value);
41+
}
42+
43+
@Test
44+
public void test_isSkipNetwork_default() {
45+
AssignVMCmd assignVMCmd = new AssignVMCmd();
46+
Assert.assertFalse(assignVMCmd.isSkipNetwork());
47+
}
48+
49+
@Test
50+
public void test_isSkipNetwork_set() {
51+
AssignVMCmd assignVMCmd = new AssignVMCmd();
52+
ReflectionTestUtils.setField(assignVMCmd, "skipNetwork", true);
53+
Assert.assertTrue(assignVMCmd.isSkipNetwork());
54+
}
55+
}

api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmdTest.java

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.api.command.user.vm;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertNull;
2223
import static org.junit.Assert.assertThrows;
@@ -41,6 +42,7 @@
4142
import org.springframework.test.util.ReflectionTestUtils;
4243

4344
import com.cloud.exception.InvalidParameterValueException;
45+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4446
import com.cloud.network.NetworkService;
4547
import com.cloud.utils.db.EntityManager;
4648
import com.cloud.vm.VmDetailConstants;
@@ -480,4 +482,152 @@ public void testGetDataDiskTemplateToDiskOfferingMapInvalidTemplateId() {
480482
});
481483
assertTrue(thrownException.getMessage().contains("Unable to translate and find entity with datadisktemplateid"));
482484
}
485+
486+
@Test
487+
public void testSetServiceOfferingId() {
488+
cmd.setServiceOfferingId(101L);
489+
assertEquals(Long.valueOf(101L), cmd.getServiceOfferingId());
490+
}
491+
492+
@Test
493+
public void testSetTemplateId() {
494+
cmd.setTemplateId(102L);
495+
assertEquals(Long.valueOf(102L), cmd.getTemplateId());
496+
}
497+
498+
@Test
499+
public void testSetVolumeId() {
500+
cmd.setVolumeId(103L);
501+
assertEquals(Long.valueOf(103L), cmd.getVolumeId());
502+
}
503+
504+
@Test
505+
public void testSetSnapshotId() {
506+
cmd.setSnapshotId(104L);
507+
assertEquals(Long.valueOf(104L), cmd.getSnapshotId());
508+
}
509+
510+
@Test
511+
public void testSetZoneId() {
512+
cmd.setZoneId(105L);
513+
assertEquals(Long.valueOf(105L), cmd.getZoneId());
514+
}
515+
516+
@Test
517+
public void testSetName() {
518+
cmd.setName("vm-name");
519+
assertEquals("vm-name", cmd.getName());
520+
}
521+
522+
@Test
523+
public void testSetDisplayName() {
524+
cmd.setDisplayName("vm-display-name");
525+
assertEquals("vm-display-name", cmd.getDisplayName());
526+
}
527+
528+
@Test
529+
public void testSetAccountName() {
530+
cmd.setAccountName("account-name");
531+
assertEquals("account-name", cmd.getAccountName());
532+
}
533+
534+
@Test
535+
public void testSetDomainId() {
536+
cmd.setDomainId(106L);
537+
assertEquals(Long.valueOf(106L), cmd.getDomainId());
538+
}
539+
540+
@Test
541+
public void testSetNetworkIds() {
542+
List<Long> networkIds = Arrays.asList(11L, 12L);
543+
cmd.setNetworkIds(networkIds);
544+
assertEquals(networkIds, cmd.getNetworkIds());
545+
}
546+
547+
@Test
548+
public void testSetBootType() {
549+
cmd.setBootType("UEFI");
550+
assertEquals(BootType.UEFI, cmd.getBootType());
551+
}
552+
553+
@Test
554+
public void testSetBootMode() {
555+
cmd.setBootType("UEFI");
556+
cmd.setBootMode("SECURE");
557+
assertEquals(BootMode.SECURE, cmd.getBootMode());
558+
}
559+
560+
@Test
561+
public void testSetHypervisor() {
562+
cmd.setHypervisor("KVM");
563+
assertEquals(HypervisorType.KVM, cmd.getHypervisor());
564+
}
565+
566+
@Test
567+
public void testSetUserData() {
568+
cmd.setUserData("dXNlci1kYXRh");
569+
assertEquals("dXNlci1kYXRh", cmd.getUserData());
570+
}
571+
572+
@Test
573+
public void testSetKeyboard() {
574+
cmd.setKeyboard("us");
575+
assertEquals("us", cmd.getKeyboard());
576+
}
577+
578+
@Test
579+
public void testSetProjectId() {
580+
cmd.setProjectId(107L);
581+
assertEquals(Long.valueOf(107L), ReflectionTestUtils.getField(cmd, "projectId"));
582+
}
583+
584+
@Test
585+
public void testSetDisplayVm() {
586+
cmd.setDisplayVm(Boolean.FALSE);
587+
assertEquals(Boolean.FALSE, cmd.isDisplayVm());
588+
}
589+
590+
@Test
591+
public void testSetUserDataId() {
592+
cmd.setUserDataId(108L);
593+
assertEquals(Long.valueOf(108L), cmd.getUserdataId());
594+
}
595+
596+
@Test
597+
public void testSetAffinityGroupIds() {
598+
List<Long> affinityGroupIds = Arrays.asList(21L, 22L);
599+
cmd.setAffinityGroupIds(affinityGroupIds);
600+
assertEquals(affinityGroupIds, cmd.getAffinityGroupIdList());
601+
}
602+
603+
@Test
604+
public void testSetDetails() {
605+
Map<String, String> details = new HashMap<>();
606+
details.put("key", "value");
607+
cmd.setDetails(details);
608+
assertEquals(details, ReflectionTestUtils.getField(cmd, "details"));
609+
}
610+
611+
@Test
612+
public void testSetExtraConfig() {
613+
cmd.setExtraConfig("cpu-mode=host-passthrough");
614+
assertEquals("cpu-mode=host-passthrough", cmd.getExtraConfig());
615+
}
616+
617+
@Test
618+
public void testSetDynamicScalingEnabled() {
619+
cmd.setDynamicScalingEnabled(Boolean.FALSE);
620+
assertFalse(cmd.isDynamicScalingEnabled());
621+
}
622+
623+
@Test
624+
public void testIsBlankInstance() {
625+
assertFalse(cmd.isBlankInstance());
626+
627+
cmd.setBlankInstance(true);
628+
assertTrue(cmd.isBlankInstance());
629+
630+
cmd.setBlankInstance(false);
631+
assertFalse(cmd.isBlankInstance());
632+
}
483633
}

plugins/integrations/veeam-control-service/src/test/java/org/apache/cloudstack/veeam/api/ApiRouteHandlerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,3 @@ public void testHandleUnknownPathReturnsNotFound() throws Exception {
8989
assertContains(response.body(), "\"reason\":\"Not found\"");
9090
}
9191
}
92-
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.veeam.api.dto;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.assertNotNull;
22+
23+
import java.util.Collections;
24+
25+
import org.apache.cloudstack.veeam.utils.Mapper;
26+
import org.junit.Test;
27+
28+
public class BackupTest {
29+
@Test
30+
public void gettersSetters() {
31+
Backup backup = new Backup();
32+
backup.setName("backup-vm1");
33+
backup.setDescription("Full backup");
34+
backup.setCreationDate(1714465200000L);
35+
backup.setPhase("succeeded");
36+
backup.setFromCheckpointId("cp-1");
37+
backup.setToCheckpointId("cp-2");
38+
assertEquals("backup-vm1", backup.getName());
39+
assertEquals("Full backup", backup.getDescription());
40+
assertEquals(Long.valueOf(1714465200000L), backup.getCreationDate());
41+
assertEquals("succeeded", backup.getPhase());
42+
assertEquals("cp-1", backup.getFromCheckpointId());
43+
assertEquals("cp-2", backup.getToCheckpointId());
44+
}
45+
46+
@Test
47+
public void gettersSetters_VmAndHost() {
48+
Backup backup = new Backup();
49+
Vm vm = Vm.of("/api/vms/v1", "v1");
50+
Host host = Host.of("/api/hosts/h1", "h1");
51+
backup.setVm(vm);
52+
backup.setHost(host);
53+
assertEquals("v1", backup.getVm().getId());
54+
assertEquals("h1", backup.getHost().getId());
55+
}
56+
57+
@Test
58+
public void disks_NamedList() {
59+
Backup backup = new Backup();
60+
Disk disk = new Disk();
61+
disk.setName("disk-1");
62+
NamedList<Disk> disks = NamedList.of("disk", Collections.singletonList(disk));
63+
backup.setDisks(disks);
64+
assertNotNull(backup.getDisks());
65+
assertEquals(1, backup.getDisks().getItems().size());
66+
assertEquals("disk-1", backup.getDisks().getItems().get(0).getName());
67+
}
68+
69+
@Test
70+
public void json_ContainsNameAndPhase() throws Exception {
71+
Mapper mapper = new Mapper();
72+
Backup backup = new Backup();
73+
backup.setName("nightly");
74+
backup.setPhase("running");
75+
String json = mapper.toJson(backup);
76+
assertTrue(json.contains("\"name\":\"nightly\""));
77+
assertTrue(json.contains("\"phase\":\"running\""));
78+
}
79+
}

0 commit comments

Comments
 (0)