OpenStackParser { public Compute parseComputeResponse (String response) throws OCCIException { String id, name, state; Attribute flavorId; Compute ret = null; SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); builder.setIgnoringElementContentWhitespace(true); Document xmldoc; log.info("[OpenStackParser] Parsing compute response..."); try { xmldoc = builder.build(new StringReader(response)); XPath xpath = XPath.newInstance(" xpath.addNamespace("ns", COMPUTENAMESPACE); xpath.addNamespace("atom", ATOMNAMESPACE); Element server = (Element)xpath.selectSingleNode(xmldoc); id = server.getAttributeValue("id"); name = server.getAttributeValue("name"); state = server.getAttributeValue("status"); xpath = XPath.newInstance(" xpath.addNamespace("ns", COMPUTENAMESPACE); xpath.addNamespace("atom", ATOMNAMESPACE); flavorId = (Attribute) xpath.selectSingleNode(xmldoc); if (id != null && name != null && state != null && flavorId != null) { ret = new Compute(); ret.setHref(id); ret.setName(name); ret.setState(fromOpenStackComputeState(state)); ret.setInstanceType(flavorId.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] Compute 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 testParseComputeResponse() { Compute results; OpenStackParser parser = new OpenStackParser(); try { results = parser.parseComputeResponse(COMPUTERESPONSE); assertEquals("3f9f7d18-aaf3-4703-b368-ea9b4d609c95", results.getHref()); assertEquals("new-server-test", results.getName()); assertEquals(ComputeState.ACTIVE, results.getState()); assertEquals("1", results.getInstanceType()); results = parser.parseComputeResponse( COMPUTEMALFORMEDRESPONSE); fail(); } catch (OCCIException e) { assertTrue(true); } }