2222import java .util .HashMap ;
2323import java .util .Map ;
2424
25+ import org .apache .cloudstack .api .ApiConstants ;
2526import org .apache .cloudstack .api .response .BackupResponse ;
2627import org .apache .cloudstack .backup .Backup ;
2728import org .apache .cloudstack .backup .BackupOfferingVO ;
4243import com .cloud .domain .DomainVO ;
4344import com .cloud .domain .dao .DomainDao ;
4445import com .cloud .hypervisor .Hypervisor ;
46+ import com .cloud .network .dao .NetworkDao ;
47+ import com .cloud .network .dao .NetworkVO ;
48+ import com .cloud .service .ServiceOfferingVO ;
49+ import com .cloud .service .dao .ServiceOfferingDao ;
4550import com .cloud .storage .Storage ;
4651import com .cloud .storage .VMTemplateVO ;
4752import com .cloud .storage .dao .VMTemplateDao ;
@@ -82,6 +87,12 @@ public class BackupDaoImplTest {
8287 @ Mock
8388 private VMTemplateDao templateDao ;
8489
90+ @ Mock
91+ ServiceOfferingDao serviceOfferingDao ;
92+
93+ @ Mock
94+ NetworkDao networkDao ;
95+
8596 @ Test
8697 public void testLoadDetails () {
8798 Long backupId = 1L ;
@@ -125,6 +136,7 @@ public void testNewBackupResponse() {
125136 Long backupId = 7L ;
126137 Long templateId = 8L ;
127138 String templateUuid = "template-uuid1" ;
139+ String serviceOfferingUuid = "service-offering-uuid1" ;
128140
129141 BackupVO backup = new BackupVO ();
130142 ReflectionTestUtils .setField (backup , "id" , backupId );
@@ -168,8 +180,20 @@ public void testNewBackupResponse() {
168180 when (template .getFormat ()).thenReturn (Storage .ImageFormat .QCOW2 );
169181 when (template .getUuid ()).thenReturn (templateUuid );
170182 when (template .getName ()).thenReturn ("template1" );
171- when (templateDao .findById ( templateId )).thenReturn (template );
183+ when (templateDao .findByUuid ( templateUuid )).thenReturn (template );
172184 Map <String , String > details = new HashMap <>();
185+ details .put (ApiConstants .TEMPLATE_ID , templateUuid );
186+
187+ ServiceOfferingVO serviceOffering = mock (ServiceOfferingVO .class );
188+ when (serviceOffering .getUuid ()).thenReturn (serviceOfferingUuid );
189+ when (serviceOffering .getName ()).thenReturn ("service-offering1" );
190+ when (serviceOfferingDao .findByUuid (serviceOfferingUuid )).thenReturn (serviceOffering );
191+ details .put (ApiConstants .SERVICE_OFFERING_ID , serviceOfferingUuid );
192+
193+ NetworkVO network = mock (NetworkVO .class );
194+ when (network .getName ()).thenReturn ("network1" );
195+ when (networkDao .findByUuid ("network-uuid1" )).thenReturn (network );
196+ details .put (ApiConstants .NICS , "[{\" networkid\" :\" network-uuid1\" }]" );
173197
174198 Mockito .when (backupDetailsDao .listDetailsKeyPairs (backup .getId (), true )).thenReturn (details );
175199
@@ -186,7 +210,9 @@ public void testNewBackupResponse() {
186210 Assert .assertEquals ("offering-uuid" , response .getBackupOfferingId ());
187211 Assert .assertEquals ("test-offering" , response .getBackupOffering ());
188212 Assert .assertEquals ("MANUAL" , response .getIntervalType ());
189- Assert .assertEquals ("{isiso=false, hypervisor=Simulator, templatename=template1, templateid=template-uuid1}" , response .getVmDetails ().toString ());
213+ Assert .assertEquals ("{serviceofferingid=service-offering-uuid1, isiso=false, hypervisor=Simulator, " +
214+ "nics=[{\" networkid\" :\" network-uuid1\" ,\" networkname\" :\" network1\" }], serviceofferingname=service-offering1, " +
215+ "templatename=template1, templateid=template-uuid1}" , response .getVmDetails ().toString ());
190216 Assert .assertEquals (true , response .getVmOfferingRemoved ());
191217 }
192218}
0 commit comments