/** * Uses Nested Search Criteria for search Verifies that the results are returned Verifies size of * the result set Verifies that none of the attribute is null * * @throws Exception */ public void testEntireObjectNestedSearch3() throws Exception { CRTMonitor searchObject = new CRTMonitor(); Collection results = getApplicationService() .search( "gov.nih.nci.cacoresdk.domain.inheritance.twolevelinheritance.CRTMonitor", searchObject); assertNotNull(results); assertEquals(1, results.size()); for (Iterator i = results.iterator(); i.hasNext(); ) { CRTMonitor result = (CRTMonitor) i.next(); toXML(result); validateClassElements(result); validateAttribute(result, "id", result.getId()); validateAttribute(result, "height", result.getHeight()); validateAttribute(result, "width", result.getWidth()); validateAttribute(result, "brand", result.getBrand()); validateAttribute(result, "refreshRate", result.getRefreshRate()); assertTrue(validateXMLData(result, searchObject.getClass())); CRTMonitor result2 = (CRTMonitor) fromXML(result); assertNotNull(result2); assertNotNull(result2.getId()); assertNotNull(result2.getHeight()); assertNotNull(result2.getWidth()); assertNotNull(result2.getBrand()); assertNotNull(result2.getRefreshRate()); } }
/** * Uses Nested Search Criteria for inheritance as association in search Verifies that the results * are returned Verifies size of the result set Verifies that none of the attribute is null * * @throws Exception */ public void testAssociationNestedSearch1() throws Exception { Monitor searchObject = new Monitor(); searchObject.setBrand("A"); Collection results = getApplicationService() .search( "gov.nih.nci.cacoresdk.domain.inheritance.twolevelinheritance.CRTMonitor", searchObject); assertNotNull(results); assertEquals(1, results.size()); for (Iterator i = results.iterator(); i.hasNext(); ) { CRTMonitor result = (CRTMonitor) i.next(); toXML(result); CRTMonitor result2 = (CRTMonitor) fromXML(result); assertNotNull(result2); assertNotNull(result2.getId()); assertNotNull(result2.getBrand()); } }
/** * Uses Nested Search Criteria for search Verifies that the results are returned Verifies size of * the result set Verifies that none of the attributes are null * * @throws Exception */ public void testGet() throws Exception { try { CRTMonitor searchObject = new CRTMonitor(); Collection results = getApplicationService() .search( "gov.nih.nci.cacoresdk.domain.inheritance.twolevelinheritance.CRTMonitor", searchObject); String id = ""; if (results != null && results.size() > 0) { CRTMonitor obj = (CRTMonitor) ((List) results).get(0); id = obj.getId().getExtension(); } else return; if (id.equals("")) return; String url = baseURL + "/rest/CRTMonitor/" + id; WebClient client = WebClient.create(url); client.type("application/xml").accept("application/xml"); Response response = client.get(); if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) { InputStream is = (InputStream) response.getEntity(); org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false); org.jdom.Document jDoc = builder.build(is); assertEquals(jDoc.getRootElement().getName(), "response"); } else if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } File myFile = new File("CRTMonitor" + "XML.xml"); System.out.println("writing data to file " + myFile.getAbsolutePath()); FileWriter myWriter = new FileWriter(myFile); BufferedReader br = new BufferedReader(new InputStreamReader(((InputStream) response.getEntity()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { myWriter.write(output); System.out.println(output); } myWriter.flush(); myWriter.close(); } catch (Exception e) { e.printStackTrace(); throw e; } }