@@ -1480,6 +1480,51 @@ public void createUsageResponseDispatchesAllUsageTypes(int usageType) {
14801480 }
14811481 }
14821482
1483+ @ Test
1484+ @ DisplayName ("createUsageResponse preserves non-public network details" )
1485+ public void createUsageResponsePreservesNonPublicNetworkDetails () {
1486+ UsageVO usageRecord = mock (UsageVO .class );
1487+ Account account = mock (Account .class );
1488+ DomainVO domain = new DomainVO ();
1489+ NetworkVO network = mock (NetworkVO .class );
1490+
1491+ when (usageRecord .getAccountId ()).thenReturn (1L );
1492+ when (usageRecord .getUsageType ()).thenReturn (UsageTypes .NETWORK_BYTES_SENT );
1493+ when (usageRecord .getType ()).thenReturn ("UserVm" );
1494+ when (usageRecord .getUsageId ()).thenReturn (14L );
1495+ when (usageRecord .getNetworkId ()).thenReturn (24L );
1496+ when (usageRecord .getRawUsage ()).thenReturn (1024D );
1497+ when (usageRecord .getVmInstanceId ()).thenReturn (null );
1498+ when (usageRecord .getVmName ()).thenReturn ("vm" );
1499+ when (usageRecord .getTemplateId ()).thenReturn (null );
1500+ when (usageRecord .getOfferingId ()).thenReturn (null );
1501+
1502+ when (account .getType ()).thenReturn (Account .Type .NORMAL );
1503+ when (account .getUuid ()).thenReturn ("account-uuid" );
1504+ when (account .getAccountName ()).thenReturn ("account" );
1505+ when (account .getDomainId ()).thenReturn (2L );
1506+ domain .setId (2L );
1507+ domain .setUuid ("domain-uuid" );
1508+ domain .setName ("domain" );
1509+ domain .setPath ("/domain/" );
1510+
1511+ when (entityManagerMock .findByIdIncludingRemoved (NetworkVO .class , 24L )).thenReturn (network );
1512+ when (network .getId ()).thenReturn (24L );
1513+ when (network .getUuid ()).thenReturn ("network-uuid" );
1514+ when (network .getName ()).thenReturn ("guest-network" );
1515+ when (network .getTrafficType ()).thenReturn (Networks .TrafficType .Guest );
1516+
1517+ try (MockedStatic <ApiDBUtils > ignored = Mockito .mockStatic (ApiDBUtils .class )) {
1518+ when (ApiDBUtils .findAccountById (1L )).thenReturn (account );
1519+ when (ApiDBUtils .findDomainById (2L )).thenReturn (domain );
1520+
1521+ UsageRecordResponse response = helper .createUsageResponse (usageRecord , null , false );
1522+
1523+ assertResponseField (response , "networkId" , "network-uuid" );
1524+ assertResponseField (response , "resourceName" , "guest-network" );
1525+ }
1526+ }
1527+
14831528 private Object invokeUsageDetailsHelper (String methodName , Class <?>[] parameterTypes , Object ... args ) throws Exception {
14841529 Method method = ApiResponseHelper .class .getDeclaredMethod (methodName , parameterTypes );
14851530 method .setAccessible (true );
0 commit comments