OpenStackParser { public String[][] parseNetworkCollectionResponse (String response) throws OCCIException { String[][] ret = null; List idList, nameList, subnetList; XPath xpath; SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); builder.setIgnoringElementContentWhitespace(true); Document xmldoc; log.info("[OpenStackParser] Parsing network collection response..."); try { xmldoc = builder.build(new StringReader(response)); xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("provider", PROVIDERNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("router", ROUTERNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); idList = xpath.selectNodes(xmldoc); xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("provider", PROVIDERNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("router", ROUTERNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); nameList = xpath.selectNodes(xmldoc); ret = new String[idList.size()][]; if (idList.size() == nameList.size()) { for (int i = 0; i < idList.size(); i++) { String id = ((Element)idList.get(i)).getValue(); xpath = XPath.newInstance(" id + "\"]/*/ns:subnet"); xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("provider", PROVIDERNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("router", ROUTERNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); subnetList = xpath.selectNodes(xmldoc); ret[i] = new String[subnetList.size() + 2]; ret[i][0] = id; ret[i][1] = ((Element)nameList.get(i)).getValue(); for (int j = 0; j < subnetList.size(); j++) { ret[i][j+2] = ((Element)subnetList.get(j)).getValue(); } } } 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] Network 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 testParseNetworkCollectionResponse() { String[][] results; OpenStackParser parser = new OpenStackParser(); try { results = parser.parseNetworkCollectionResponse(NETWORKCOLLECTIONRESPONSE); assertEquals(2, results.length); assertEquals(3, results[0].length); assertEquals(4, results[1].length); assertEquals("d32019d3-bc6e-4319-9c1d-6722fc136a22", results[0][0]); assertEquals("private-network", results[0][1]); assertEquals("54d6f61d-db07-451c-9ab3-b9609b6b6f0b", results[0][2]); assertEquals("db193ab3-96e3-4cb3-8fc5-05f4296d0324", results[1][0]); assertEquals("private", results[1][1]); assertEquals("08eae331-0402-425a-923c-34f7cfe39c1b", results[1][2]); assertEquals("08eae331-0402-425a-923c-34f7cfe39c1c", results[1][3]); results = parser.parseNetworkCollectionResponse( NETWORKCOLLECTIONMALFORMEDRESPONSE); fail(); } catch (OCCIException e) { assertTrue(true); } }