OpenStackParser { public NetworkCollection parseSubnetCollectionResponse (String response) throws OCCIException { Link link; ArrayList<Link> links; NetworkCollection ret = null; SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); builder.setIgnoringElementContentWhitespace(true); Document xmldoc; log.info("[OpenStackParser] Parsing subnet collection response..."); try { xmldoc = builder.build(new StringReader(response)); XPath xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); List idList = xpath.selectNodes(xmldoc); xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); List nameList = xpath.selectNodes(xmldoc); if (idList.size() == nameList.size()) { links = new ArrayList<Link>(); ret = new NetworkCollection(); Iterator idIt = idList.iterator(); Iterator nameIt = nameList.iterator(); while (idIt.hasNext()) { link = new Link(); link.setHref(((Element)idIt.next()).getValue()); link.setName(((Element)nameIt.next()).getValue()); links.add(link); } ret = new NetworkCollection(); ret.getNetwork().addAll(links); } 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] Subnet 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 testParseSubnetCollectionResponse() { NetworkCollection results; OpenStackParser parser = new OpenStackParser(); try { results = parser.parseSubnetCollectionResponse(SUBNETCOLLECTIONRESPONSE); assertEquals(2, results.getNetwork().size()); assertEquals("08eae331-0402-425a-923c-34f7cfe39c1b", results.getNetwork().get(0).getHref()); assertEquals("54d6f61d-db07-451c-9ab3-b9609b6b6f0b", results.getNetwork().get(1).getHref()); assertEquals("private-subnet", results.getNetwork().get(0).getName()); assertEquals("my_subnet", results.getNetwork().get(1).getName()); results = parser.parseSubnetCollectionResponse( SUBNETCOLLECTIONMALFORMEDRESPONSE); fail(); } catch (OCCIException e) { assertTrue(true); } }