|
34 | 34 | import org.junit.jupiter.api.BeforeEach; |
35 | 35 | import org.junit.jupiter.api.DisplayName; |
36 | 36 | import org.junit.jupiter.api.Test; |
| 37 | +import org.junit.jupiter.params.ParameterizedTest; |
| 38 | +import org.junit.jupiter.params.provider.ValueSource; |
37 | 39 | import org.junit.jupiter.api.extension.ExtendWith; |
38 | 40 | import org.mockito.InjectMocks; |
39 | 41 | import org.mockito.Mock; |
@@ -1413,6 +1415,71 @@ public void populateVmDiskBytesWriteUsageResponseTest() throws Exception { |
1413 | 1415 | verify(entityManagerMock).findByIdIncludingRemoved(VolumeVO.class, 28L); |
1414 | 1416 | } |
1415 | 1417 |
|
| 1418 | + @ParameterizedTest |
| 1419 | + @ValueSource(ints = { |
| 1420 | + UsageTypes.RUNNING_VM, |
| 1421 | + UsageTypes.IP_ADDRESS, |
| 1422 | + UsageTypes.NETWORK_BYTES_SENT, |
| 1423 | + UsageTypes.VM_DISK_IO_READ, |
| 1424 | + UsageTypes.VOLUME, |
| 1425 | + UsageTypes.TEMPLATE, |
| 1426 | + UsageTypes.SNAPSHOT, |
| 1427 | + UsageTypes.LOAD_BALANCER_POLICY, |
| 1428 | + UsageTypes.PORT_FORWARDING_RULE, |
| 1429 | + UsageTypes.NETWORK_OFFERING, |
| 1430 | + UsageTypes.VPN_USERS, |
| 1431 | + UsageTypes.SECURITY_GROUP, |
| 1432 | + UsageTypes.BACKUP, |
| 1433 | + UsageTypes.VM_SNAPSHOT, |
| 1434 | + UsageTypes.VOLUME_SECONDARY, |
| 1435 | + UsageTypes.VM_SNAPSHOT_ON_PRIMARY, |
| 1436 | + UsageTypes.BUCKET |
| 1437 | + }) |
| 1438 | + public void createUsageResponseDispatchesAllUsageTypes(int usageType) { |
| 1439 | + UsageVO usageRecord = mock(UsageVO.class); |
| 1440 | + Account account = mock(Account.class); |
| 1441 | + DomainVO domain = new DomainVO(); |
| 1442 | + |
| 1443 | + when(usageRecord.getAccountId()).thenReturn(1L); |
| 1444 | + when(usageRecord.getZoneId()).thenReturn(null); |
| 1445 | + when(usageRecord.getDescription()).thenReturn("usage description"); |
| 1446 | + when(usageRecord.getUsageDisplay()).thenReturn("usage"); |
| 1447 | + when(usageRecord.getUsageType()).thenReturn(usageType); |
| 1448 | + when(usageRecord.getVmInstanceId()).thenReturn(null); |
| 1449 | + when(usageRecord.getVmName()).thenReturn(null); |
| 1450 | + when(usageRecord.getTemplateId()).thenReturn(null); |
| 1451 | + when(usageRecord.getOfferingId()).thenReturn(1L); |
| 1452 | + when(usageRecord.getUsageId()).thenReturn(1L); |
| 1453 | + when(usageRecord.getNetworkId()).thenReturn(null); |
| 1454 | + when(usageRecord.getRawUsage()).thenReturn(null); |
| 1455 | + when(usageRecord.getSize()).thenReturn(null); |
| 1456 | + when(usageRecord.getVirtualSize()).thenReturn(null); |
| 1457 | + when(usageRecord.getType()).thenReturn("UserVm"); |
| 1458 | + when(usageRecord.getStartDate()).thenReturn(null); |
| 1459 | + when(usageRecord.getEndDate()).thenReturn(null); |
| 1460 | + |
| 1461 | + when(account.getType()).thenReturn(Account.Type.NORMAL); |
| 1462 | + when(account.getId()).thenReturn(1L); |
| 1463 | + when(account.getUuid()).thenReturn("account-uuid"); |
| 1464 | + when(account.getAccountName()).thenReturn("account"); |
| 1465 | + when(account.getDomainId()).thenReturn(2L); |
| 1466 | + domain.setId(2L); |
| 1467 | + domain.setUuid("domain-uuid"); |
| 1468 | + domain.setName("domain"); |
| 1469 | + domain.setPath("/domain/"); |
| 1470 | + |
| 1471 | + try (MockedStatic<ApiDBUtils> ignored = Mockito.mockStatic(ApiDBUtils.class)) { |
| 1472 | + when(ApiDBUtils.findAccountById(1L)).thenReturn(account); |
| 1473 | + when(ApiDBUtils.findDomainById(2L)).thenReturn(domain); |
| 1474 | + |
| 1475 | + UsageRecordResponse response = helper.createUsageResponse(usageRecord, null, false); |
| 1476 | + |
| 1477 | + assertEquals(usageType, response.getUsageType()); |
| 1478 | + assertEquals("account-uuid", response.getAccountId()); |
| 1479 | + assertEquals("domain-uuid", response.getDomainId()); |
| 1480 | + } |
| 1481 | + } |
| 1482 | + |
1416 | 1483 | private Object invokeUsageDetailsHelper(String methodName, Class<?>[] parameterTypes, Object... args) throws Exception { |
1417 | 1484 | Method method = ApiResponseHelper.class.getDeclaredMethod(methodName, parameterTypes); |
1418 | 1485 | method.setAccessible(true); |
|
0 commit comments