OpenStackParser { public Network parseSubnetResponse (String response) throws OCCIException { Network ret = null; Element href, address, name; String size; SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); builder.setIgnoringElementContentWhitespace(true); Document xmldoc; int netClass; log.info("[OpenStackParser] Parsing subnet response..."); try { ret = new Network(); xmldoc = builder.build(new StringReader(response)); XPath xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); href = (Element)xpath.selectSingleNode(xmldoc); xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); address = (Element)xpath.selectSingleNode(xmldoc); xpath = XPath.newInstance(" xpath.addNamespace("ns", QUANTUMNAMESPACE); xpath.addNamespace("quantum", QUANTUMNAMESPACE); xpath.addNamespace("xsi", XSINAMESPACE); name = (Element)xpath.selectSingleNode(xmldoc); if (href != null && address != null && name != null) { ret.setAddress(address.getValue()); ret.setHref(href.getValue()); ret.setName(name.getValue()); netClass = Integer.parseInt(ret.getAddress().split("\\.")[0]); size = null; if (netClass < 128) { size = "A"; } else if (netClass < 192) { size = "B"; } else if (netClass < 224) { size = "C"; } else if (netClass < 240) { size = "D"; } else if (netClass < 256) { size = "E"; } else { OCCIException exception = new OCCIException(); exception.setMessage(BADADDRESS); log.error(BADADDRESS); throw exception; } ret.setSize(size); } 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 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 testParseSubnetResponse() { Network results; OpenStackParser parser = new OpenStackParser(); try { results = parser.parseSubnetResponse(SUBNETRESPONSE); assertEquals("192.0.0.0/8", results.getAddress()); assertEquals("54d6f61d-db07-451c-9ab3-b9609b6b6f0b", results.getHref()); assertEquals("test_subnet_1", results.getName()); assertEquals("C", results.getSize()); results = parser.parseSubnetResponse( SUBNETMALFORMEDRESPONSE); fail(); } catch (OCCIException e) { assertTrue(true); } }