@Before public void setupTest() throws IOException, ParserConfigurationException, SAXException { Properties setupProps = SetupProperties.setup(null); if (setupProps.getProperty("testBackwardsCompatability") != null && Boolean.parseBoolean(setupProps.getProperty("testBackwardsCompatability"))) { setupProps = SetupProperties.setup(setupProps.getProperty("version1Properties")); } baseUrl = setupProps.getProperty("baseUri"); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); basicCreds = new UsernamePasswordCredentials(userId, pw); response = OSLCUtils.getResponseFromUrl( baseUrl, currentUrl, basicCreds, OSLCConstants.CT_DISC_CAT_XML); responseBody = EntityUtils.toString(response.getEntity()); // Get XML Doc from response doc = OSLCUtils.createXMLDocFromResponseBody(responseBody); }
@Parameters public static Collection<Object[]> getAllServiceProviderCatalogUrls() throws IOException, ParserConfigurationException, SAXException, XPathException { // Checks the ServiceProviderCatalog at the specified baseUrl of the REST service in order to // grab all urls // to other ServiceProviders contained within it, recursively. Properties setupProps = SetupProperties.setup(null); Collection<Object[]> coll = getReferencedCatalogUrls(setupProps.getProperty("baseUri")); return coll; }
public static Collection<Object[]> getReferencedCatalogUrls(String base) throws IOException, ParserConfigurationException, SAXException, XPathException { Properties setupProps = SetupProperties.setup(null); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); HttpResponse resp = OSLCUtils.getResponseFromUrl( base, base, new UsernamePasswordCredentials(userId, pw), OSLCConstants.CT_DISC_CAT_XML); // If we're not looking at a catalog, return empty list. if (!resp.getEntity().getContentType().getValue().contains(OSLCConstants.CT_DISC_CAT_XML)) { System.out.println("The url: " + base + " does not refer to a ServiceProviderCatalog."); System.out.println( "The content-type of a ServiceProviderCatalog should be " + OSLCConstants.CT_DISC_CAT_XML); System.out.println("The content-type returned was " + resp.getEntity().getContentType()); EntityUtils.consume(resp.getEntity()); return new ArrayList<Object[]>(); } Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity())); // ArrayList to contain the urls from all SPCs Collection<Object[]> data = new ArrayList<Object[]>(); data.add(new Object[] {base}); // Get all ServiceProviderCatalog urls from the base document in order to test them as well, // recursively checking them for other ServiceProviderCatalogs further down. NodeList spcs = (NodeList) OSLCUtils.getXPath() .evaluate( "//oslc_disc:entry/oslc_disc:ServiceProviderCatalog/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { String uri = spcs.item(i).getNodeValue(); uri = OSLCUtils.absoluteUrlFromRelative(base, uri); if (!uri.equals(base)) { Collection<Object[]> subCollection = getReferencedCatalogUrls(uri); Iterator<Object[]> iter = subCollection.iterator(); while (iter.hasNext()) { data.add(iter.next()); } } } return data; }