AutonomiccsSystemVmsGuru implements VirtualMachineGuru, InitializingBean { protected void setIpAddressOfEachNic(AutonomiccsSystemVm autonomiccsSystemVm, DataCenter dc, List<NicProfile> nics) { for (NicProfile nic : nics) { if (nic.getTrafficType() == TrafficType.Management) { autonomiccsSystemVm.setManagementIpAddress(nic.getIPv4Address()); continue; } if (nic.getTrafficType() == TrafficType.Control) { autonomiccsSystemVm.setPrivateIpAddress(nic.getIPv4Address()); continue; } if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) { autonomiccsSystemVm.setPublicIpAddress(nic.getIPv4Address()); } } }  @Override void afterPropertiesSet(); @Override boolean finalizeCommandsOnStart(Commands arg0, VirtualMachineProfile arg1); @Override boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void finalizeExpunge(VirtualMachine vm); @Override boolean finalizeStart(VirtualMachineProfile arg0, long arg1, Commands arg2, ReservationContext arg3); @Override void finalizeStop(VirtualMachineProfile arg0, Answer arg1); @Override boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); @Override void prepareStop(VirtualMachineProfile arg0);  }
@Test public void setEachNicIpAddressTestNetworkTypeAdvanced() { AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); DataCenter dc = Mockito.mock(DataCenter.class); Mockito.when(dc.getNetworkType()).thenReturn(NetworkType.Advanced); List<NicProfile> nics = createNicsOfManagementTrafficControlTrafficAndTheGivenTraffic(TrafficType.Public); configureDoNothingAtSetEachNicIpAddressTests(autonomiccsSystemVm); spy.setIpAddressOfEachNic(autonomiccsSystemVm, dc, nics); verifySetEachNicIpAddressCalledMethods(autonomiccsSystemVm, 1, 1, 1); }
@Test public void setEachNicIpAddressTestNetworkTypeAdvancedDcIsSecurityGroupEnabled() { AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); DataCenter dc = setupDataCenter(NetworkType.Basic, true); List<NicProfile> nics = createNicsOfManagementTrafficControlTrafficAndTheGivenTraffic(TrafficType.Guest); configureDoNothingAtSetEachNicIpAddressTests(autonomiccsSystemVm); spy.setIpAddressOfEachNic(autonomiccsSystemVm, dc, nics); verifySetEachNicIpAddressCalledMethods(autonomiccsSystemVm, 1, 1, 1); }
@Test public void setEachNicIpAddressTestNetworkTypeAdvancedDcIsSecurityGroupNotEnabled() { AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); DataCenter dc = setupDataCenter(NetworkType.Advanced, false); List<NicProfile> nics = createNicsOfManagementTrafficControlTrafficAndTheGivenTraffic(TrafficType.Guest); configureDoNothingAtSetEachNicIpAddressTests(autonomiccsSystemVm); spy.setIpAddressOfEachNic(autonomiccsSystemVm, dc, nics); verifySetEachNicIpAddressCalledMethods(autonomiccsSystemVm, 1, 1, 0); }
@Test public void setEachNicIpAddressTestNetworkTypeBasic() { AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); DataCenter dc = setupDataCenter(NetworkType.Basic, true); List<NicProfile> nics = createNicsOfManagementTrafficControlTrafficAndTheGivenTraffic(TrafficType.Guest); configureDoNothingAtSetEachNicIpAddressTests(autonomiccsSystemVm); spy.setIpAddressOfEachNic(autonomiccsSystemVm, dc, nics); verifySetEachNicIpAddressCalledMethods(autonomiccsSystemVm, 1, 1, 1); }