AutonomiccsSystemVmsGuru implements VirtualMachineGuru, InitializingBean { protected String configureNicDhcpAndDns(VirtualMachineProfile profile, StringBuilder buf, boolean externalDhcp) { if (externalDhcp) { buf.append(" bootproto=dhcp"); } DataCenterVO dc = datacenterDao.findById(profile.getVirtualMachine().getDataCenterId()); buf.append(" internaldns1=").append(dc.getInternalDns1()); if (dc.getInternalDns2() != null) { buf.append(" internaldns2=").append(dc.getInternalDns2()); } buf.append(" dns1=").append(dc.getDns1()); if (dc.getDns2() != null) { buf.append(" dns2=").append(dc.getDns2()); } return buf.toString(); }  @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 configureNicDhcpAndDnsTest() { StringBuilder buf = new StringBuilder(); DataCenterVO dc = configureDataCenterDns("internalDns1", "internalDns2", "dns1", "dns2"); VirtualMachineProfile profile = configureDcProfileAndVm(dc); spy.configureNicDhcpAndDns(profile, buf, true); Assert.assertEquals(" bootproto=dhcp internaldns1=internalDns1 internaldns2=internalDns2 dns1=dns1 dns2=dns2", buf.toString()); }
@Test public void configureNicDhcpAndDnsTestNotExternalDhcp() { StringBuilder buf = new StringBuilder(); DataCenterVO dc = configureDataCenterDns("internalDns1", "internalDns2", "dns1", "dns2"); VirtualMachineProfile profile = configureDcProfileAndVm(dc); spy.configureNicDhcpAndDns(profile, buf, false); Assert.assertEquals(" internaldns1=internalDns1 internaldns2=internalDns2 dns1=dns1 dns2=dns2", buf.toString()); }
@Test public void configureNicDhcpAndDnsTestAllDnsBlank() { StringBuilder buf = new StringBuilder(); DataCenterVO dc = configureDataCenterDns("", "", "", ""); VirtualMachineProfile profile = configureDcProfileAndVm(dc); spy.configureNicDhcpAndDns(profile, buf, true); Assert.assertEquals(" bootproto=dhcp internaldns1= internaldns2= dns1= dns2=", buf.toString()); }
@Test public void configureNicDhcpAndDnsTestAllDnsNull() { StringBuilder buf = new StringBuilder(); DataCenterVO dc = configureDataCenterDns(null, null, null, null); VirtualMachineProfile profile = configureDcProfileAndVm(dc); spy.configureNicDhcpAndDns(profile, buf, true); Assert.assertEquals(" bootproto=dhcp internaldns1=null dns1=null", buf.toString()); }