OpenStackParser { public InstanceTypeCollection parseInstanceTypeCollectionResponse (String response) throws OCCIException { InstanceTypeCollection ret = null; List<Link> linkList; Link link; SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); builder.setIgnoringElementContentWhitespace(true); Document xmldoc; log.info("[OpenStackParser] " + "Parsing instance type collection response..."); try { xmldoc = builder.build(new StringReader(response)); XPath xpath = XPath.newInstance(" xpath.addNamespace("ns", COMPUTENAMESPACE); xpath.addNamespace("atom", ATOMNAMESPACE); List idList = xpath.selectNodes(xmldoc); xpath = XPath.newInstance(" xpath.addNamespace("ns", COMPUTENAMESPACE); xpath.addNamespace("atom", ATOMNAMESPACE); List nameList = xpath.selectNodes(xmldoc); if (idList.size() == nameList.size()) { ret = new InstanceTypeCollection(); linkList = new ArrayList<Link>(); for (int i = 0 ; i < idList.size() ; i++) { link = new Link(); link.setHref(((Attribute)idList.get(i)).getValue()); link.setName(((Attribute)nameList.get(i)).getValue()); linkList.add(link); } ret.getInstanceType().addAll(linkList); } else { OCCIException exception = new OCCIException(); exception.setMessage(MALFORMEDRESPONSE); log.error(MALFORMEDRESPONSE); throw exception; } } catch (JDOMException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } log.debug("[OpenStackParser] " + "Instance type collection response parsed..."); return ret; }  String[] parseAuthorizationResponse(String response); String[][] parseNetworkCollectionResponse(String response); String[] parseCreatedNetworkResponse(String response); NetworkCollection parseSubnetCollectionResponse(String response); Network parseSubnetResponse(String response); StorageCollection parseStorageCollectionResponse(String response); Storage parseStorageResponse(String response); StorageCollection parseImageCollectionResponse(String response); Storage parseImageResponse(String response); ComputeCollection parseComputeCollectionResponse(String response); Compute parseComputeResponse(String response); String parseComputeInstanceTypeId(
    		String response,
    		HashMap<String, InstanceType> instanceTypes); List<Disk> parseAttachedStoragesResponse(String response); List<Nic> parseVirtualInterfacesResponse(String response); InstanceTypeCollection parseInstanceTypeCollectionResponse(String response); InstanceType parseInstanceTypeResponse(String response); Quota parseComputeQuotaResponse(String response); int parseStorageQuotaResponse(String response); ComputeState fromOpenStackComputeState(String state); String toOpenStackComputeState(ComputeState state); static final String KEYSTONENAMESPACE; static final String QUANTUMNAMESPACE; static final String PROVIDERNAMESPACE; static final String ROUTERNAMESPACE; static final String XSINAMESPACE; static final String VOLUMENAMESPACE; static final String ATOMNAMESPACE; static final String COMPUTENAMESPACE; static final String VIFNAMESPACE; static final String COMMONNAMESPACE; static final String BLOCKNAMESPACE; static final String OSVOLHOSTATTRNAMESPACE; static final String OSVOLIMAGEMETANAMESPACE; static final String OSVOLTENANTATTRNAMESPACE; }
@Test public void testParseInstanceTypeCollectionResponse() { InstanceTypeCollection results; OpenStackParser parser = new OpenStackParser(); try { results = parser.parseInstanceTypeCollectionResponse( INSTANCETYPECOLLECTIONRESPONSE); assertEquals(5, results.getInstanceType().size()); assertEquals("1", results.getInstanceType().get(0).getHref()); assertEquals("m1.tiny", results.getInstanceType().get(0).getName()); assertEquals("2", results.getInstanceType().get(1).getHref()); assertEquals( "m1.small", results.getInstanceType().get(1).getName()); assertEquals("3", results.getInstanceType().get(2).getHref()); assertEquals( "m1.medium", results.getInstanceType().get(2).getName()); assertEquals("4", results.getInstanceType().get(3).getHref()); assertEquals( "m1.large", results.getInstanceType().get(3).getName()); assertEquals("5", results.getInstanceType().get(4).getHref()); assertEquals( "m1.xlarge", results.getInstanceType().get(4).getName()); results = parser.parseInstanceTypeCollectionResponse( INSTANCETYPECOLLECTIONMALFORMEDRESPONSE); fail(); } catch (OCCIException e) { assertTrue(true); } }