private static void populateBigDecimal(Method method, Object model) throws Exception { method.invoke(model, new BigDecimal(rand(100))); }
@SuppressWarnings("unchecked") private static void fill(Method method, Object model, List<Class<?>> seen, int level) throws Exception { ParameterizedType returnType = (ParameterizedType) method.getGenericReturnType(); Class<?> childType = (Class<?>) returnType.getActualTypeArguments()[0]; if (level == 1 || unseen(childType, seen)) { List<Object> list = (List<Object>) method.invoke(model); Object child = null; if (childType.isEnum()) { Object[] labels = childType.getEnumConstants(); child = labels[rand(labels.length)]; } else { child = childType.newInstance(); } list.add(child); populate(child, child.getClass(), seen, ++level); } }
private static void random(Method m, Object model) throws Exception { Object value = null; if (takesString(m)) { value = garble(m); } else if (takesShort(m)) { value = (short) rand(100); } else if (takesInteger(m)) { value = rand(100); } else if (takesLong(m)) { value = (long) rand(1000000000); } else if (takesBoolean(m)) { value = RandomUtils.instance().nextBoolean(); } else if (takesDouble(m)) { value = RandomUtils.instance().nextDouble(); } if (value != null) { m.invoke(model, value); } }
@Override protected Host postPopulate(Host from) { while (from.getPort() == 0) { from.setPort(MappingTestHelper.rand(65535)); } from.getSpm().setPriority(3); from.getPowerManagement().setPmProxies(new PmProxies()); return from; }
@Override protected Template postPopulate(Template from) { from.setType(VmType.DESKTOP); from.setStorageErrorResumeBehaviour(VmStorageErrorResumeBehaviour.AUTO_RESUME); from.setOrigin(OriginType.VMWARE.name().toLowerCase()); List<BootDevice> devices = from.getOs().getBoot().getDevices().getDevices(); for (int i = 0; i < devices.size(); i++) { devices.set(i, BootDevice.NETWORK); } while (from.getCpu().getTopology().getSockets() == 0) { from.getCpu().getTopology().setSockets(MappingTestHelper.rand(100)); } while (from.getCpu().getTopology().getCores() == 0) { from.getCpu().getTopology().setCores(MappingTestHelper.rand(100)); } from.setTimeZone(new TimeZone()); from.getTimeZone().setName("Australia/Darwin"); from.getSerialNumber().setPolicy(SerialNumberPolicy.CUSTOM); from.getMigration().setAutoConverge(InheritableBoolean.TRUE); from.getMigration().setCompressed(InheritableBoolean.TRUE); from.getDisplay().setDisconnectAction(DisplayDisconnectAction.LOCK_SCREEN.toString()); for (NicConfiguration nicConfiguration : from.getInitialization().getNicConfigurations().getNicConfigurations()) { nicConfiguration.setBootProtocol(BootProtocol.STATIC); } return from; }