mirror of https://github.com/apache/cloudstack.git
more tests, fix pre-commit
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
568c1aab7a
commit
7bdd70399a
|
|
@ -66,7 +66,7 @@ public class DeployVMCmd extends BaseDeployVMCmd {
|
|||
@Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.UUID, entityType = SnapshotResponse.class, since = "4.21")
|
||||
private Long snapshotId;
|
||||
|
||||
@Parameter(name = "blank", type = CommandType.BOOLEAN, since = "4.22.1")
|
||||
@Parameter(name = "blank", type = CommandType.BOOLEAN, since = "4.23.0")
|
||||
private Boolean blankInstance;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,8 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
|
|||
type = CommandType.UUID,
|
||||
entityType = StoragePoolResponse.class,
|
||||
description = "Storage pool ID to create the volume in. Cannot be used with the snapshotid parameter.",
|
||||
authorized = {RoleType.Admin})
|
||||
authorized = {RoleType.Admin},
|
||||
since = "4.23.0")
|
||||
private Long storageId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -150,6 +151,10 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
|
|||
}
|
||||
|
||||
public Long getSnapshotId() {
|
||||
if (storageId != null && snapshotId != null) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
|
||||
"Snapshot ID cannot be specified with the Storage ID.");
|
||||
}
|
||||
return snapshotId;
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +169,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
|
|||
public Long getStorageId() {
|
||||
if (snapshotId != null && storageId != null) {
|
||||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
|
||||
"StorageId parameter cannot be specified with the SnapshotId parameter.");
|
||||
"Storage ID cannot be specified with the Snapshot ID.");
|
||||
}
|
||||
return storageId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.api.command.admin.vm;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
public class AssignVMCmdTest {
|
||||
|
||||
@Test
|
||||
public void test_setSkipNetwork_default() {
|
||||
AssignVMCmd assignVMCmd = new AssignVMCmd();
|
||||
Object value = ReflectionTestUtils.getField(assignVMCmd, "skipNetwork");
|
||||
Assert.assertTrue(value instanceof Boolean);
|
||||
Assert.assertFalse((Boolean) value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_setSkipNetwork_set() {
|
||||
AssignVMCmd assignVMCmd = new AssignVMCmd();
|
||||
assignVMCmd.setSkipNetwork(true);
|
||||
Object value = ReflectionTestUtils.getField(assignVMCmd, "skipNetwork");
|
||||
Assert.assertTrue(value instanceof Boolean);
|
||||
Assert.assertTrue((Boolean) value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isSkipNetwork_default() {
|
||||
AssignVMCmd assignVMCmd = new AssignVMCmd();
|
||||
Assert.assertFalse(assignVMCmd.isSkipNetwork());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isSkipNetwork_set() {
|
||||
AssignVMCmd assignVMCmd = new AssignVMCmd();
|
||||
ReflectionTestUtils.setField(assignVMCmd, "skipNetwork", true);
|
||||
Assert.assertTrue(assignVMCmd.isSkipNetwork());
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.cloudstack.api.command.user.vm;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
|
@ -41,6 +42,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.NetworkService;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.vm.VmDetailConstants;
|
||||
|
|
@ -480,4 +482,152 @@ public class DeployVMCmdTest {
|
|||
});
|
||||
assertTrue(thrownException.getMessage().contains("Unable to translate and find entity with datadisktemplateid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetServiceOfferingId() {
|
||||
cmd.setServiceOfferingId(101L);
|
||||
assertEquals(Long.valueOf(101L), cmd.getServiceOfferingId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTemplateId() {
|
||||
cmd.setTemplateId(102L);
|
||||
assertEquals(Long.valueOf(102L), cmd.getTemplateId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolumeId() {
|
||||
cmd.setVolumeId(103L);
|
||||
assertEquals(Long.valueOf(103L), cmd.getVolumeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSnapshotId() {
|
||||
cmd.setSnapshotId(104L);
|
||||
assertEquals(Long.valueOf(104L), cmd.getSnapshotId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetZoneId() {
|
||||
cmd.setZoneId(105L);
|
||||
assertEquals(Long.valueOf(105L), cmd.getZoneId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetName() {
|
||||
cmd.setName("vm-name");
|
||||
assertEquals("vm-name", cmd.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDisplayName() {
|
||||
cmd.setDisplayName("vm-display-name");
|
||||
assertEquals("vm-display-name", cmd.getDisplayName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAccountName() {
|
||||
cmd.setAccountName("account-name");
|
||||
assertEquals("account-name", cmd.getAccountName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDomainId() {
|
||||
cmd.setDomainId(106L);
|
||||
assertEquals(Long.valueOf(106L), cmd.getDomainId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNetworkIds() {
|
||||
List<Long> networkIds = Arrays.asList(11L, 12L);
|
||||
cmd.setNetworkIds(networkIds);
|
||||
assertEquals(networkIds, cmd.getNetworkIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetBootType() {
|
||||
cmd.setBootType("UEFI");
|
||||
assertEquals(BootType.UEFI, cmd.getBootType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetBootMode() {
|
||||
cmd.setBootType("UEFI");
|
||||
cmd.setBootMode("SECURE");
|
||||
assertEquals(BootMode.SECURE, cmd.getBootMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetHypervisor() {
|
||||
cmd.setHypervisor("KVM");
|
||||
assertEquals(HypervisorType.KVM, cmd.getHypervisor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUserData() {
|
||||
cmd.setUserData("dXNlci1kYXRh");
|
||||
assertEquals("dXNlci1kYXRh", cmd.getUserData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetKeyboard() {
|
||||
cmd.setKeyboard("us");
|
||||
assertEquals("us", cmd.getKeyboard());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetProjectId() {
|
||||
cmd.setProjectId(107L);
|
||||
assertEquals(Long.valueOf(107L), ReflectionTestUtils.getField(cmd, "projectId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDisplayVm() {
|
||||
cmd.setDisplayVm(Boolean.FALSE);
|
||||
assertEquals(Boolean.FALSE, cmd.isDisplayVm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetUserDataId() {
|
||||
cmd.setUserDataId(108L);
|
||||
assertEquals(Long.valueOf(108L), cmd.getUserdataId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAffinityGroupIds() {
|
||||
List<Long> affinityGroupIds = Arrays.asList(21L, 22L);
|
||||
cmd.setAffinityGroupIds(affinityGroupIds);
|
||||
assertEquals(affinityGroupIds, cmd.getAffinityGroupIdList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDetails() {
|
||||
Map<String, String> details = new HashMap<>();
|
||||
details.put("key", "value");
|
||||
cmd.setDetails(details);
|
||||
assertEquals(details, ReflectionTestUtils.getField(cmd, "details"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetExtraConfig() {
|
||||
cmd.setExtraConfig("cpu-mode=host-passthrough");
|
||||
assertEquals("cpu-mode=host-passthrough", cmd.getExtraConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDynamicScalingEnabled() {
|
||||
cmd.setDynamicScalingEnabled(Boolean.FALSE);
|
||||
assertFalse(cmd.isDynamicScalingEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsBlankInstance() {
|
||||
assertFalse(cmd.isBlankInstance());
|
||||
|
||||
cmd.setBlankInstance(true);
|
||||
assertTrue(cmd.isBlankInstance());
|
||||
|
||||
cmd.setBlankInstance(false);
|
||||
assertFalse(cmd.isBlankInstance());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,4 +89,3 @@ public class ApiRouteHandlerTest extends RouteHandlerTestSupport {
|
|||
assertContains(response.body(), "\"reason\":\"Not found\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BackupTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
Backup backup = new Backup();
|
||||
backup.setName("backup-vm1");
|
||||
backup.setDescription("Full backup");
|
||||
backup.setCreationDate(1714465200000L);
|
||||
backup.setPhase("succeeded");
|
||||
backup.setFromCheckpointId("cp-1");
|
||||
backup.setToCheckpointId("cp-2");
|
||||
assertEquals("backup-vm1", backup.getName());
|
||||
assertEquals("Full backup", backup.getDescription());
|
||||
assertEquals(Long.valueOf(1714465200000L), backup.getCreationDate());
|
||||
assertEquals("succeeded", backup.getPhase());
|
||||
assertEquals("cp-1", backup.getFromCheckpointId());
|
||||
assertEquals("cp-2", backup.getToCheckpointId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gettersSetters_VmAndHost() {
|
||||
Backup backup = new Backup();
|
||||
Vm vm = Vm.of("/api/vms/v1", "v1");
|
||||
Host host = Host.of("/api/hosts/h1", "h1");
|
||||
backup.setVm(vm);
|
||||
backup.setHost(host);
|
||||
assertEquals("v1", backup.getVm().getId());
|
||||
assertEquals("h1", backup.getHost().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disks_NamedList() {
|
||||
Backup backup = new Backup();
|
||||
Disk disk = new Disk();
|
||||
disk.setName("disk-1");
|
||||
NamedList<Disk> disks = NamedList.of("disk", Collections.singletonList(disk));
|
||||
backup.setDisks(disks);
|
||||
assertNotNull(backup.getDisks());
|
||||
assertEquals(1, backup.getDisks().getItems().size());
|
||||
assertEquals("disk-1", backup.getDisks().getItems().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsNameAndPhase() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Backup backup = new Backup();
|
||||
backup.setName("nightly");
|
||||
backup.setPhase("running");
|
||||
String json = mapper.toJson(backup);
|
||||
assertTrue(json.contains("\"name\":\"nightly\""));
|
||||
assertTrue(json.contains("\"phase\":\"running\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BaseDtoTest {
|
||||
@Test
|
||||
public void zeroUuid_ConstantValue() {
|
||||
assertEquals("00000000-0000-0000-0000-000000000000", BaseDto.ZERO_UUID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActionLink_BuildsRelAndHref() {
|
||||
Link link = BaseDto.getActionLink("start", "/ovirt-engine/api/vms/1");
|
||||
assertEquals("start", link.getRel());
|
||||
assertEquals("/ovirt-engine/api/vms/1/start", link.getHref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ref_of_SetsHrefAndId() {
|
||||
Ref ref = Ref.of("https://host/api/templates/abc", "abc");
|
||||
assertEquals("https://host/api/templates/abc", ref.getHref());
|
||||
assertEquals("abc", ref.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void link_of_SetsRelAndHref() {
|
||||
Link link = Link.of("edit", "/api/vms/1");
|
||||
assertEquals("edit", link.getRel());
|
||||
assertEquals("/api/vms/1", link.getHref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ref_JsonOmitsNullId() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Ref ref = new Ref();
|
||||
ref.setHref("/api/vms/1");
|
||||
String json = mapper.toJson(ref);
|
||||
assertTrue(json.contains("\"href\":\"/api/vms/1\""));
|
||||
assertFalse(json.contains("\"id\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void link_JsonContainsRelAndHref() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Link link = Link.of("delete", "/api/disks/7");
|
||||
String json = mapper.toJson(link);
|
||||
assertTrue(json.contains("\"rel\":\"delete\""));
|
||||
assertTrue(json.contains("\"href\":\"/api/disks/7\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void baseDto_GettersSetters() {
|
||||
Ref ref = new Ref();
|
||||
assertNull(ref.getHref());
|
||||
assertNull(ref.getId());
|
||||
ref.setHref("/test");
|
||||
ref.setId("id-1");
|
||||
assertEquals("/test", ref.getHref());
|
||||
assertEquals("id-1", ref.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vmOf_SetsHrefAndId() {
|
||||
Vm vm = Vm.of("/ovirt-engine/api/vms/1", "1");
|
||||
assertNotNull(vm);
|
||||
assertEquals("/ovirt-engine/api/vms/1", vm.getHref());
|
||||
assertEquals("1", vm.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostOf_SetsHrefAndId() {
|
||||
Host host = Host.of("/ovirt-engine/api/hosts/h1", "h1");
|
||||
assertNotNull(host);
|
||||
assertEquals("/ovirt-engine/api/hosts/h1", host.getHref());
|
||||
assertEquals("h1", host.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CertificateTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
Certificate cert = new Certificate();
|
||||
cert.setOrganization("Apache");
|
||||
cert.setSubject("CN=cloudstack.apache.org");
|
||||
assertEquals("Apache", cert.getOrganization());
|
||||
assertEquals("CN=cloudstack.apache.org", cert.getSubject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_IncludesOrganizationAndSubject() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Certificate cert = new Certificate();
|
||||
cert.setOrganization("Apache");
|
||||
cert.setSubject("CN=host");
|
||||
String json = mapper.toJson(cert);
|
||||
assertTrue(json.contains("\"organization\":\"Apache\""));
|
||||
assertTrue(json.contains("\"subject\":\"CN=host\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DiskTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
Disk disk = new Disk();
|
||||
disk.setName("root-disk");
|
||||
disk.setAlias("vm-alias");
|
||||
disk.setFormat("cow");
|
||||
disk.setProvisionedSize("10737418240");
|
||||
disk.setActualSize("2147483648");
|
||||
disk.setStatus("ok");
|
||||
disk.setImageId("img-uuid-1");
|
||||
disk.setBootable("true");
|
||||
assertEquals("root-disk", disk.getName());
|
||||
assertEquals("vm-alias", disk.getAlias());
|
||||
assertEquals("cow", disk.getFormat());
|
||||
assertEquals("10737418240", disk.getProvisionedSize());
|
||||
assertEquals("2147483648", disk.getActualSize());
|
||||
assertEquals("ok", disk.getStatus());
|
||||
assertEquals("img-uuid-1", disk.getImageId());
|
||||
assertEquals("true", disk.getBootable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsFormatAndName() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Disk disk = new Disk();
|
||||
disk.setName("data-disk");
|
||||
disk.setFormat("raw");
|
||||
String json = mapper.toJson(disk);
|
||||
assertTrue(json.contains("\"name\":\"data-disk\""));
|
||||
assertTrue(json.contains("\"format\":\"raw\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_OmitsNullOptionals() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Disk disk = new Disk();
|
||||
disk.setName("minimal");
|
||||
String json = mapper.toJson(disk);
|
||||
assertFalse(json.contains("\"alias\""));
|
||||
assertFalse(json.contains("\"bootable\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DtoSerializationTest {
|
||||
|
||||
@Test
|
||||
public void diskAttachmentJson_UsesInterfaceProperty() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
DiskAttachment diskAttachment = new DiskAttachment();
|
||||
diskAttachment.setIface("virtio_scsi");
|
||||
|
||||
String json = mapper.toJson(diskAttachment);
|
||||
|
||||
assertTrue(json.contains("\"interface\":\"virtio_scsi\""));
|
||||
assertFalse(json.contains("\"iface\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nicJson_UsesInterfacePropertyAndRoundTrips() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Nic nic = new Nic();
|
||||
nic.setInterfaceType("virtio");
|
||||
|
||||
String json = mapper.toJson(nic);
|
||||
Nic read = mapper.jsonMapper().readValue(json, Nic.class);
|
||||
|
||||
assertTrue(json.contains("\"interface\":\"virtio\""));
|
||||
assertFalse(json.contains("interface_type"));
|
||||
assertEquals("virtio", read.getInterfaceType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vmJson_IgnoresCloudStackSpecificFields() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Vm vm = new Vm();
|
||||
vm.setName("vm-1");
|
||||
vm.setAccountId("account-uuid");
|
||||
vm.setAffinityGroupId("affinity-uuid");
|
||||
vm.setUserDataId("userdata-uuid");
|
||||
|
||||
String json = mapper.toJson(vm);
|
||||
|
||||
assertTrue(json.contains("\"name\":\"vm-1\""));
|
||||
assertFalse(json.contains("account_id"));
|
||||
assertFalse(json.contains("affinity_group_id"));
|
||||
assertFalse(json.contains("user_data_id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vmXml_WritesEmptyElements() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Vm vm = new Vm();
|
||||
|
||||
String xml = mapper.toXml(vm);
|
||||
|
||||
assertTrue(xml.contains("<io/>"));
|
||||
assertTrue(xml.contains("<migration/>"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FaultTest {
|
||||
@Test
|
||||
public void constructor_SetsReasonAndDetail() {
|
||||
Fault fault = new Fault("Not Found", "Entity was not found");
|
||||
assertEquals("Not Found", fault.getReason());
|
||||
assertEquals("Entity was not found", fault.getDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsReasonAndDetail() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Fault fault = new Fault("Unauthorized", "Invalid credentials");
|
||||
String json = mapper.toJson(fault);
|
||||
assertTrue(json.contains("\"reason\":\"Unauthorized\""));
|
||||
assertTrue(json.contains("\"detail\":\"Invalid credentials\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HostTest {
|
||||
@Test
|
||||
public void of_SetsHrefAndId() {
|
||||
Host host = Host.of("/api/hosts/h1", "h1");
|
||||
assertNotNull(host);
|
||||
assertEquals("/api/hosts/h1", host.getHref());
|
||||
assertEquals("h1", host.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gettersSetters_CoreFields() {
|
||||
Host host = new Host();
|
||||
host.setAddress("192.168.1.10");
|
||||
host.setStatus("up");
|
||||
host.setName("kvm-host-01");
|
||||
host.setPort("54321");
|
||||
assertEquals("192.168.1.10", host.getAddress());
|
||||
assertEquals("up", host.getStatus());
|
||||
assertEquals("kvm-host-01", host.getName());
|
||||
assertEquals("54321", host.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hardwareInformation_GettersSetters() {
|
||||
Host.HardwareInformation hw = new Host.HardwareInformation();
|
||||
hw.setManufacturer("Dell");
|
||||
hw.setProductName("PowerEdge R740");
|
||||
hw.setSerialNumber("SN12345");
|
||||
hw.setUuid("uuid-001");
|
||||
hw.setVersion("1.0");
|
||||
assertEquals("Dell", hw.getManufacturer());
|
||||
assertEquals("PowerEdge R740", hw.getProductName());
|
||||
assertEquals("SN12345", hw.getSerialNumber());
|
||||
assertEquals("uuid-001", hw.getUuid());
|
||||
assertEquals("1.0", hw.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostJson_ContainsAddressAndStatus() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Host host = new Host();
|
||||
host.setAddress("10.0.0.1");
|
||||
host.setStatus("up");
|
||||
String json = mapper.toJson(host);
|
||||
assertTrue(json.contains("\"address\":\"10.0.0.1\""));
|
||||
assertTrue(json.contains("\"status\":\"up\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ImageTransferTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
ImageTransfer it = new ImageTransfer();
|
||||
it.setPhase("initializing");
|
||||
it.setDirection("upload");
|
||||
it.setFormat("raw");
|
||||
it.setTransferUrl("http://host:54322/images/xxx");
|
||||
it.setTransferred("0");
|
||||
it.setActive("true");
|
||||
assertEquals("initializing", it.getPhase());
|
||||
assertEquals("upload", it.getDirection());
|
||||
assertEquals("raw", it.getFormat());
|
||||
assertEquals("http://host:54322/images/xxx", it.getTransferUrl());
|
||||
assertEquals("0", it.getTransferred());
|
||||
assertEquals("true", it.getActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hostAndDiskRefs() {
|
||||
ImageTransfer it = new ImageTransfer();
|
||||
Ref host = Ref.of("/api/hosts/h1", "h1");
|
||||
Ref disk = Ref.of("/api/disks/d1", "d1");
|
||||
Ref image = Ref.of("/api/images/img1", "img1");
|
||||
it.setHost(host);
|
||||
it.setDisk(disk);
|
||||
it.setImage(image);
|
||||
assertEquals("h1", it.getHost().getId());
|
||||
assertEquals("d1", it.getDisk().getId());
|
||||
assertEquals("img1", it.getImage().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsPhaseAndDirection() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
ImageTransfer it = new ImageTransfer();
|
||||
it.setPhase("transferring");
|
||||
it.setDirection("download");
|
||||
String json = mapper.toJson(it);
|
||||
assertTrue(json.contains("\"phase\":\"transferring\""));
|
||||
assertTrue(json.contains("\"direction\":\"download\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MacIpTest {
|
||||
@Test
|
||||
public void mac_GettersSetters() {
|
||||
Mac mac = new Mac();
|
||||
mac.setAddress("02:00:00:00:00:01");
|
||||
assertEquals("02:00:00:00:00:01", mac.getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mac_JsonSerializes() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Mac mac = new Mac();
|
||||
mac.setAddress("aa:bb:cc:dd:ee:ff");
|
||||
String json = mapper.toJson(mac);
|
||||
assertTrue(json.contains("\"address\":\"aa:bb:cc:dd:ee:ff\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ip_GettersSetters() {
|
||||
Ip ip = new Ip();
|
||||
ip.setAddress("192.168.1.1");
|
||||
ip.setGateway("192.168.1.254");
|
||||
ip.setNetmask("255.255.255.0");
|
||||
ip.setVersion("v4");
|
||||
assertEquals("192.168.1.1", ip.getAddress());
|
||||
assertEquals("192.168.1.254", ip.getGateway());
|
||||
assertEquals("255.255.255.0", ip.getNetmask());
|
||||
assertEquals("v4", ip.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ip_JsonOmitsNullGateway() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Ip ip = new Ip();
|
||||
ip.setAddress("10.0.0.1");
|
||||
ip.setVersion("v4");
|
||||
String json = mapper.toJson(ip);
|
||||
assertTrue(json.contains("\"address\":\"10.0.0.1\""));
|
||||
assertFalse(json.contains("\"gateway\""));
|
||||
assertFalse(json.contains("\"netmask\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class NamedListTest {
|
||||
|
||||
@Test
|
||||
public void of_NullItems_UsesEmptyList() {
|
||||
NamedList<String> namedList = NamedList.of("item", null);
|
||||
|
||||
assertNotNull(namedList.getItems());
|
||||
assertTrue(namedList.getItems().isEmpty());
|
||||
assertTrue(namedList.asMap().containsKey("item"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void of_ValidName_StoresItemsInMap() {
|
||||
List<String> values = Arrays.asList("a", "b");
|
||||
NamedList<String> namedList = NamedList.of("values", values);
|
||||
|
||||
assertEquals(values, namedList.getItems());
|
||||
assertEquals(values, namedList.asMap().get("values"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void of_EmptyName_ThrowsIllegalArgumentException() {
|
||||
try {
|
||||
NamedList.of("", Collections.singletonList("x"));
|
||||
fail("Expected IllegalArgumentException for empty name");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("name must be non-empty", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMap_InvalidMapShape_ThrowsIllegalArgumentException() {
|
||||
try {
|
||||
NamedList.fromMap(null);
|
||||
fail("Expected IllegalArgumentException for null map");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Expected single-property object for NamedList", e.getMessage());
|
||||
}
|
||||
|
||||
Map<String, List<String>> invalid = new HashMap<>();
|
||||
invalid.put("a", Collections.singletonList("x"));
|
||||
invalid.put("b", Collections.singletonList("y"));
|
||||
|
||||
try {
|
||||
NamedList.fromMap(invalid);
|
||||
fail("Expected IllegalArgumentException for map with multiple keys");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Expected single-property object for NamedList", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMap_SingleEntry_ReturnsNamedList() {
|
||||
Map<String, List<String>> map = Collections.singletonMap("usage", Collections.singletonList("vm"));
|
||||
|
||||
NamedList<String> namedList = NamedList.fromMap(map);
|
||||
|
||||
assertEquals(Collections.singletonList("vm"), namedList.getItems());
|
||||
assertEquals(map, namedList.asMap());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||
public class OvfXmlUtilTest {
|
||||
|
||||
String configuration = "<ovf:Envelope xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1/\" xmlns:rasd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData\" xmlns:vssd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ovf:version=\"4.4.0.0\">" +
|
||||
"<Content ovf:id=\"out\" xsi:type=\"ovf:VirtualSystem_Type\"><Name>adm-v9</Name><Description>adm-v9</Description>"+
|
||||
"<Content ovf:id=\"out\" xsi:type=\"ovf:VirtualSystem_Type\"><Name>adm-v9</Name><Description>adm-v9</Description>" +
|
||||
"<Section xsi:type=\"ovf:VirtualHardwareSection_Type\"><Info>1 CPU, 512 Memory</Info><System><vssd:VirtualSystemType>ENGINE 4.4.0.0</vssd:VirtualSystemType></System><Item><rasd:Caption>1 virtual cpu</rasd:Caption><rasd:Description>Number of virtual CPU</rasd:Description><rasd:InstanceId>1</rasd:InstanceId><rasd:ResourceType>3</rasd:ResourceType><rasd:num_of_sockets>1</rasd:num_of_sockets><rasd:cpu_per_socket>1</rasd:cpu_per_socket><rasd:threads_per_cpu>1</rasd:threads_per_cpu><rasd:max_num_of_vcpus>1</rasd:max_num_of_vcpus><rasd:VirtualQuantity>1</rasd:VirtualQuantity></Item>" +
|
||||
"<Item><rasd:Caption>512 MB of memory</rasd:Caption><rasd:Description>Memory Size</rasd:Description><rasd:InstanceId>2</rasd:InstanceId><rasd:ResourceType>4</rasd:ResourceType><rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits><rasd:VirtualQuantity>512</rasd:VirtualQuantity></Item>" +
|
||||
"</Section></Content></ovf:Envelope>";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProductInfoApiTest {
|
||||
// ---- ProductInfo -------------------------------------------------------
|
||||
@Test
|
||||
public void productInfo_GettersSetters() {
|
||||
ProductInfo info = new ProductInfo();
|
||||
info.setInstanceId("inst-1");
|
||||
info.setName("oVirt Engine");
|
||||
Version version = new Version();
|
||||
version.setMajor("4");
|
||||
version.setMinor("23");
|
||||
info.setVersion(version);
|
||||
assertEquals("inst-1", info.getInstanceId());
|
||||
assertEquals("oVirt Engine", info.getName());
|
||||
assertNotNull(info.getVersion());
|
||||
assertEquals("4", info.getVersion().getMajor());
|
||||
assertEquals("23", info.getVersion().getMinor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void productInfoJson_ContainsInstanceId() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
ProductInfo info = new ProductInfo();
|
||||
info.setInstanceId("inst-abc");
|
||||
info.setName("CloudStack");
|
||||
String json = mapper.toJson(info);
|
||||
assertTrue(json.contains("\"instance_id\":\"inst-abc\""));
|
||||
assertTrue(json.contains("\"name\":\"CloudStack\""));
|
||||
}
|
||||
|
||||
// ---- SpecialObjects ----------------------------------------------------
|
||||
@Test
|
||||
public void specialObjects_GettersSetters() {
|
||||
SpecialObjects so = new SpecialObjects();
|
||||
Ref blank = Ref.of("/api/templates/blank", "blank");
|
||||
Ref root = Ref.of("/api/tags/root", "root");
|
||||
so.setBlankTemplate(blank);
|
||||
so.setRootTag(root);
|
||||
assertEquals("blank", so.getBlankTemplate().getId());
|
||||
assertEquals("root", so.getRootTag().getId());
|
||||
}
|
||||
|
||||
// ---- ApiSummary --------------------------------------------------------
|
||||
@Test
|
||||
public void apiSummary_HostsAndVms() {
|
||||
ApiSummary summary = new ApiSummary();
|
||||
SummaryCount hosts = new SummaryCount(2, 5);
|
||||
SummaryCount vms = new SummaryCount(10, 20);
|
||||
summary.setHosts(hosts);
|
||||
summary.setVms(vms);
|
||||
assertEquals("2", summary.getHosts().getActive());
|
||||
assertEquals("5", summary.getHosts().getTotal());
|
||||
assertEquals("10", summary.getVms().getActive());
|
||||
assertEquals("20", summary.getVms().getTotal());
|
||||
}
|
||||
|
||||
// ---- Api root -----------------------------------------------------------
|
||||
@Test
|
||||
public void api_GettersSetters() {
|
||||
Api api = new Api();
|
||||
api.setTime(1714465200000L);
|
||||
ProductInfo info = new ProductInfo();
|
||||
info.setName("CloudStack");
|
||||
api.setProductInfo(info);
|
||||
Ref authUser = Ref.of("/api/users/admin", "admin");
|
||||
api.setAuthenticatedUser(authUser);
|
||||
assertEquals(Long.valueOf(1714465200000L), api.getTime());
|
||||
assertEquals("CloudStack", api.getProductInfo().getName());
|
||||
assertEquals("admin", api.getAuthenticatedUser().getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SnapshotTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setDate(1714465200000L);
|
||||
snapshot.setSnapshotType("regular");
|
||||
snapshot.setSnapshotStatus("ok");
|
||||
snapshot.setDescription("Daily backup");
|
||||
snapshot.setPersistMemorystate("false");
|
||||
assertEquals(Long.valueOf(1714465200000L), snapshot.getDate());
|
||||
assertEquals("regular", snapshot.getSnapshotType());
|
||||
assertEquals("ok", snapshot.getSnapshotStatus());
|
||||
assertEquals("Daily backup", snapshot.getDescription());
|
||||
assertEquals("false", snapshot.getPersistMemorystate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsSnapshotTypeAndDate() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Snapshot snapshot = new Snapshot();
|
||||
snapshot.setSnapshotType("memory");
|
||||
snapshot.setDate(1000L);
|
||||
String json = mapper.toJson(snapshot);
|
||||
assertTrue(json.contains("\"snapshot_type\":\"memory\""));
|
||||
assertTrue(json.contains("\"date\":1000"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StorageDomainTest {
|
||||
@Test
|
||||
public void gettersSetters() {
|
||||
StorageDomain sd = new StorageDomain();
|
||||
sd.setName("data-domain");
|
||||
sd.setType("data");
|
||||
sd.setStatus("active");
|
||||
sd.setAvailable("107374182400");
|
||||
sd.setUsed("21474836480");
|
||||
sd.setStorageFormat("v5");
|
||||
assertEquals("data-domain", sd.getName());
|
||||
assertEquals("data", sd.getType());
|
||||
assertEquals("active", sd.getStatus());
|
||||
assertEquals("107374182400", sd.getAvailable());
|
||||
assertEquals("21474836480", sd.getUsed());
|
||||
assertEquals("v5", sd.getStorageFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_ContainsNameAndType() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
StorageDomain sd = new StorageDomain();
|
||||
sd.setName("nfs-storage");
|
||||
sd.setType("data");
|
||||
String json = mapper.toJson(sd);
|
||||
assertTrue(json.contains("\"name\":\"nfs-storage\""));
|
||||
assertTrue(json.contains("\"type\":\"data\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SummaryCountTest {
|
||||
@Test
|
||||
public void constructor_IntValues_ConvertsToStrings() {
|
||||
SummaryCount count = new SummaryCount(3, 10);
|
||||
assertEquals("3", count.getActive());
|
||||
assertEquals("10", count.getTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultConstructor_NullValues() {
|
||||
SummaryCount count = new SummaryCount();
|
||||
assertNull(count.getActive());
|
||||
assertNull(count.getTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_OmitsNullFields() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
SummaryCount count = new SummaryCount();
|
||||
String json = mapper.toJson(count);
|
||||
assertFalse(json.contains("active"));
|
||||
assertFalse(json.contains("total"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void json_IncludesPopulatedFields() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
SummaryCount count = new SummaryCount(5, 20);
|
||||
String json = mapper.toJson(count);
|
||||
assertEquals("{\"active\":\"5\",\"total\":\"20\"}", json);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TopologyTest {
|
||||
|
||||
@Test
|
||||
public void constructor_IntValues_ConvertsToStrings() {
|
||||
Topology topology = new Topology(2, 4, 1);
|
||||
|
||||
assertEquals("2", topology.getSockets());
|
||||
assertEquals("4", topology.getCores());
|
||||
assertEquals("1", topology.getThreads());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultConstructor_NullFields() {
|
||||
Topology topology = new Topology();
|
||||
|
||||
assertNull(topology.getSockets());
|
||||
assertNull(topology.getCores());
|
||||
assertNull(topology.getThreads());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cpuWithTopology_Serializes() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Cpu cpu = new Cpu();
|
||||
cpu.setName("Intel Xeon");
|
||||
cpu.setArchitecture("x86_64");
|
||||
Topology topology = new Topology(4, 8, 2);
|
||||
cpu.setTopology(topology);
|
||||
|
||||
String json = mapper.toJson(cpu);
|
||||
|
||||
assertNotNull(json);
|
||||
// Mapper uses SNAKE_CASE, so field names become snake_case
|
||||
assertEquals("Intel Xeon", cpu.getName());
|
||||
assertEquals("x86_64", cpu.getArchitecture());
|
||||
assertEquals(topology, cpu.getTopology());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topologyJson_OmitsNullFields() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
Topology topology = new Topology();
|
||||
topology.setSockets("2");
|
||||
|
||||
String json = mapper.toJson(topology);
|
||||
|
||||
assertNotNull(json);
|
||||
// only sockets is set
|
||||
assertEquals("2", topology.getSockets());
|
||||
assertNull(topology.getCores());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.apache.cloudstack.utils.CloudStackVersion;
|
||||
import org.apache.cloudstack.veeam.VeeamControlService;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class VersionTest {
|
||||
|
||||
@Test
|
||||
public void fromPackageAndCSVersion_CompleteVersion_IncludesPackageAndCsFields() {
|
||||
CloudStackVersion csVersion = CloudStackVersion.parse("4.23.1.2");
|
||||
try (MockedStatic<VeeamControlService> mocked = Mockito.mockStatic(VeeamControlService.class)) {
|
||||
mocked.when(VeeamControlService::getPackageVersion).thenReturn("4.23.1.2");
|
||||
mocked.when(VeeamControlService::getCSVersion).thenReturn(csVersion);
|
||||
|
||||
Version version = Version.fromPackageAndCSVersion(true);
|
||||
|
||||
assertEquals("4.23.1.2", version.getFullVersion());
|
||||
assertEquals("4", version.getMajor());
|
||||
assertEquals("23", version.getMinor());
|
||||
assertEquals("1", version.getBuild());
|
||||
assertEquals("2", version.getRevision());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromPackageAndCSVersion_IncompleteVersion_DoesNotSetFullVersion() {
|
||||
CloudStackVersion csVersion = CloudStackVersion.parse("4.23.1.2");
|
||||
try (MockedStatic<VeeamControlService> mocked = Mockito.mockStatic(VeeamControlService.class)) {
|
||||
mocked.when(VeeamControlService::getPackageVersion).thenReturn("4.23.1.2");
|
||||
mocked.when(VeeamControlService::getCSVersion).thenReturn(csVersion);
|
||||
|
||||
Version version = Version.fromPackageAndCSVersion(false);
|
||||
|
||||
assertNull(version.getFullVersion());
|
||||
assertEquals("4", version.getMajor());
|
||||
assertEquals("23", version.getMinor());
|
||||
assertEquals("1", version.getBuild());
|
||||
assertEquals("2", version.getRevision());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromPackageAndCSVersion_NullCloudStackVersion_ReturnsWithoutNumericParts() {
|
||||
try (MockedStatic<VeeamControlService> mocked = Mockito.mockStatic(VeeamControlService.class)) {
|
||||
mocked.when(VeeamControlService::getPackageVersion).thenReturn("4.23.1.2");
|
||||
mocked.when(VeeamControlService::getCSVersion).thenReturn(null);
|
||||
|
||||
Version version = Version.fromPackageAndCSVersion(true);
|
||||
|
||||
assertEquals("4.23.1.2", version.getFullVersion());
|
||||
assertNull(version.getMajor());
|
||||
assertNull(version.getMinor());
|
||||
assertNull(version.getBuild());
|
||||
assertNull(version.getRevision());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class VmTest {
|
||||
|
||||
@Test
|
||||
public void of_SetsHrefAndId() {
|
||||
Vm vm = Vm.of("/ovirt-engine/api/vms/1", "1");
|
||||
|
||||
assertEquals("/ovirt-engine/api/vms/1", vm.getHref());
|
||||
assertEquals("1", vm.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosGetDefault_UsesSeaBiosAndDisabledBootMenu() {
|
||||
Vm.Bios bios = Vm.Bios.getDefault();
|
||||
|
||||
assertEquals(Vm.Bios.Type.q35_sea_bios.name(), bios.getType());
|
||||
assertEquals("false", bios.getBootMenu().getEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosUpdateBios_UsesSecureBootWhenRequested() {
|
||||
Vm.Bios bios = Vm.Bios.getDefault();
|
||||
|
||||
Vm.Bios.updateBios(bios, ApiConstants.BootMode.SECURE.toString());
|
||||
|
||||
assertEquals(Vm.Bios.Type.q35_secure_boot.name(), bios.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosUpdateBios_UsesOvmfForNonSecureMode() {
|
||||
Vm.Bios bios = Vm.Bios.getDefault();
|
||||
|
||||
Vm.Bios.updateBios(bios, ApiConstants.BootMode.LEGACY.toString());
|
||||
|
||||
assertEquals(Vm.Bios.Type.q35_ovmf.name(), bios.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosGetBiosFromOrdinal_FallsBackToDefaultWhenInvalid() {
|
||||
Vm.Bios bios = Vm.Bios.getBiosFromOrdinal("not-a-number");
|
||||
|
||||
assertEquals(Vm.Bios.Type.q35_sea_bios.name(), bios.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosGetBiosFromOrdinal_MapsKnownOrdinals() {
|
||||
Vm.Bios secure = Vm.Bios.getBiosFromOrdinal(String.valueOf(Vm.Bios.Type.q35_secure_boot.ordinal()));
|
||||
Vm.Bios ovmf = Vm.Bios.getBiosFromOrdinal(String.valueOf(Vm.Bios.Type.q35_ovmf.ordinal()));
|
||||
|
||||
assertEquals(Vm.Bios.Type.q35_secure_boot.name(), secure.getType());
|
||||
assertEquals(Vm.Bios.Type.q35_ovmf.name(), ovmf.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biosRetrieveBootOptions_ReturnsExpectedMappings() {
|
||||
Pair<ApiConstants.BootType, ApiConstants.BootMode> defaults = Vm.Bios.retrieveBootOptions(null);
|
||||
Pair<ApiConstants.BootType, ApiConstants.BootMode> secure = Vm.Bios.retrieveBootOptions(typeOnly(Vm.Bios.Type.q35_secure_boot.name()));
|
||||
Pair<ApiConstants.BootType, ApiConstants.BootMode> uefiLegacy = Vm.Bios.retrieveBootOptions(typeOnly(Vm.Bios.Type.q35_ovmf.name()));
|
||||
|
||||
assertEquals(ApiConstants.BootType.BIOS, defaults.first());
|
||||
assertEquals(ApiConstants.BootMode.LEGACY, defaults.second());
|
||||
assertEquals(ApiConstants.BootType.UEFI, secure.first());
|
||||
assertEquals(ApiConstants.BootMode.SECURE, secure.second());
|
||||
assertEquals(ApiConstants.BootType.UEFI, uefiLegacy.first());
|
||||
assertEquals(ApiConstants.BootMode.LEGACY, uefiLegacy.second());
|
||||
}
|
||||
|
||||
private Vm.Bios typeOnly(String type) {
|
||||
Vm.Bios bios = new Vm.Bios();
|
||||
bios.setType(type);
|
||||
return bios;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.cloudstack.veeam.utils.Mapper;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VnicProfileReportedDeviceTest {
|
||||
// ---- VnicProfile -------------------------------------------------------
|
||||
@Test
|
||||
public void vnicProfile_GettersSetters() {
|
||||
VnicProfile profile = new VnicProfile();
|
||||
profile.setName("default");
|
||||
profile.setDescription("Default vNIC profile");
|
||||
Ref network = Ref.of("/api/networks/net1", "net1");
|
||||
Ref dc = Ref.of("/api/datacenters/dc1", "dc1");
|
||||
profile.setNetwork(network);
|
||||
profile.setDataCenter(dc);
|
||||
assertEquals("default", profile.getName());
|
||||
assertEquals("Default vNIC profile", profile.getDescription());
|
||||
assertEquals("net1", profile.getNetwork().getId());
|
||||
assertEquals("dc1", profile.getDataCenter().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vnicProfileJson_ContainsName() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
VnicProfile profile = new VnicProfile();
|
||||
profile.setName("my-profile");
|
||||
String json = mapper.toJson(profile);
|
||||
assertTrue(json.contains("\"name\":\"my-profile\""));
|
||||
}
|
||||
|
||||
// ---- ReportedDevice ----------------------------------------------------
|
||||
@Test
|
||||
public void reportedDevice_GettersSetters() {
|
||||
ReportedDevice device = new ReportedDevice();
|
||||
device.setName("eth0");
|
||||
device.setType("bridge");
|
||||
device.setDescription("Primary NIC");
|
||||
Mac mac = new Mac();
|
||||
mac.setAddress("aa:bb:cc:dd:ee:01");
|
||||
device.setMac(mac);
|
||||
NamedList<Ip> ips = NamedList.of("ip", Collections.singletonList(new Ip()));
|
||||
device.setIps(ips);
|
||||
assertEquals("eth0", device.getName());
|
||||
assertEquals("bridge", device.getType());
|
||||
assertEquals("Primary NIC", device.getDescription());
|
||||
assertEquals("aa:bb:cc:dd:ee:01", device.getMac().getAddress());
|
||||
assertNotNull(device.getIps());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportedDeviceJson_ContainsNameAndType() throws Exception {
|
||||
Mapper mapper = new Mapper();
|
||||
ReportedDevice device = new ReportedDevice();
|
||||
device.setName("ens3");
|
||||
device.setType("ethernet");
|
||||
String json = mapper.toJson(device);
|
||||
assertTrue(json.contains("\"name\":\"ens3\""));
|
||||
assertTrue(json.contains("\"type\":\"ethernet\""));
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ public class DataUtilTest {
|
|||
|
||||
@Test
|
||||
public void testB64Url_UsesUrlSafeAlphabetAndNoPadding() {
|
||||
final String encoded = DataUtil.b64Url(new byte[]{(byte)0xfb, (byte)0xff});
|
||||
final String encoded = DataUtil.b64Url(new byte[]{(byte) 0xfb, (byte) 0xff});
|
||||
assertEquals("-_8", encoded);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue