### Question:
HostClient { @SuppressWarnings("unchecked") public List<Host> get(HostGetParam param) { JSONObject params = JSONObject.fromObject(param, defaultConfig); if (accessor.checkVersion("2.0") < 0) { if (params.containsKey("selectGroups")) { params.put("select_groups", params.remove("selectGroups")); } } else { if (params.containsKey("output") && "extend".equals(params.getString("output"))) { params.put("selectInterfaces", "extend"); } } JSONArray result = (JSONArray) accessor.execute("host.get", params); JsonConfig config = defaultConfig.copy(); config.setCollectionType(List.class); config.setRootClass(Host.class); config.getClassMap().put("parenttemplates", Template.class); config.getClassMap().put("groups", Hostgroup.class); config.getClassMap().put("interfaces", Hostinterface.class); config.getClassMap().put("maintenances", Maintenance.class); List<Host> hosts = (List<Host>) JSONArray.toCollection(result, config); if (accessor.checkVersion("2.0") >= 0) { for (Host host : hosts) { if (host.getInterfaces() != null && host.getInterfaces().size() > 0) { Hostinterface hostinterface = host.getInterfaces().get(0); host.setDns(hostinterface.getDns()); host.setIp(hostinterface.getIp()); host.setPort(hostinterface.getPort()); host.setUseip(hostinterface.getUseip()); } } } else { for (Host host : hosts) { Hostinterface hostinterface = new Hostinterface(); hostinterface.setDns(host.getDns()); hostinterface.setIp(host.getIp()); hostinterface.setPort(host.getPort()); hostinterface.setUseip(host.getUseip()); hostinterface.setType(1); hostinterface.setMain(1); host.setInterfaces(Arrays.asList(hostinterface)); } } return hosts; } HostClient(ZabbixAccessor accessor, JsonConfig defaultConfig); @SuppressWarnings("unchecked") List<Host> get(HostGetParam param); @SuppressWarnings("unchecked") List<String> create(HostCreateParam param); @SuppressWarnings("unchecked") List<String> update(HostUpdateParam param); @SuppressWarnings("unchecked") List<String> delete(List<String> hostids);  }### Answer:
@Test public void testGetAll() { HostGetParam param = new HostGetParam(); param.setOutput("extend"); param.setSelectGroups("extend"); param.setSelectParentTemplates("extend"); List<Host> hosts = client.host().get(param); for (Host host : hosts) { log.trace(ReflectionToStringBuilder.toString(host, ToStringStyle.SHORT_PREFIX_STYLE)); } assertTrue(hosts.size() > 0); }
@Test public void testGet() { String hostid; if (client.checkVersion("2.0") < 0) { hostid = "10017"; } else { hostid = "10084"; } HostGetParam param = new HostGetParam(); param.setHostids(Arrays.asList(hostid)); param.setOutput("extend"); param.setSelectGroups("extend"); param.setSelectParentTemplates("extend"); List<Host> hosts = client.host().get(param); assertEquals(1, hosts.size()); assertEquals(hostid, hosts.get(0).getHostid()); assertEquals(1, hosts.get(0).getGroups().size()); if (client.checkVersion("2.0") < 0) { assertEquals(1, hosts.get(0).getParenttemplates().size()); } else { assertEquals(2, hosts.get(0).getParenttemplates().size()); } }
@Test public void testGetNotExist() { HostGetParam param = new HostGetParam(); param.setHostids(Arrays.asList("999999")); param.setOutput("extend"); param.setSelectGroups("extend"); param.setSelectParentTemplates("extend"); List<Host> hosts = client.host().get(param); assertEquals(0, hosts.size()); }