public static void oneTimeSetUp() throws Exception { BundleContext context = TestActivator.getContext(); packageAdminRef = context.getServiceReference(PackageAdmin.class); PackageAdmin pkgAdmin = context.getService(packageAdminRef); // Make sure these are not running stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP); stopTransient(pkgAdmin, BUNDLE_TESTSERVER); // Get an available port and assign it the "org.osgi.service.http.port" property. The // server will listen to this port and all tests use it to connect. System.setProperty(PROP_TESTSERVER_PORT, Integer.toString(obtainFreePort())); // Now start them again (with our property settings) if (!startTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP)) throw new IllegalStateException("Unable to start bundle " + BUNDLE_EQUINOX_HTTP); if (!startTransient(pkgAdmin, BUNDLE_TESTSERVER)) throw new IllegalStateException("Unable to start bundle " + BUNDLE_TESTSERVER); // We must ensure that our IServiceUI service wins because the SDK registers one declaratively Hashtable properties = new Hashtable(1); properties.put( org.osgi.framework.Constants.SERVICE_RANKING, Integer.valueOf(Integer.MAX_VALUE)); certificateUIRegistration = context.registerService( UIServices.class.getName(), new DelegatingAuthService(), properties); setUpCounter = 1; }
private String getValueFor(String property) { if (property == null) return null; String result = TestActivator.getContext().getProperty(property); if (result == null && archiveAndRepositoryProperties == null) return null; if (result == null) archiveAndRepositoryProperties.getProperty(property); if (result == null) result = archiveAndRepositoryProperties.getProperty(property + '.' + Platform.getOS()); return result; }
/* * Helper method to return the install location. Return null if it is unavailable. */ public static File getInstallLocation() { Location installLocation = ServiceHelper.getService( TestActivator.getContext(), Location.class, Location.INSTALL_FILTER); if (installLocation == null || !installLocation.isSet()) return null; URL url = installLocation.getURL(); if (url == null) return null; return URLUtil.toFile(url); }
public static void oneTimeTearDown() throws Exception { BundleContext context = TestActivator.getContext(); certificateUIRegistration.unregister(); PackageAdmin pkgAdmin = context.getService(packageAdminRef); stopTransient(pkgAdmin, BUNDLE_TESTSERVER); stopTransient(pkgAdmin, BUNDLE_EQUINOX_HTTP); context.ungetService(packageAdminRef); setUpCounter = 0; }
/* * Clean up the temporary data used to run the tests. * This method is not intended to be called by clients, it will be called * automatically when the clients use a ReconcilerTestSuite. */ public void cleanup() throws Exception { // rm -rf eclipse sub-dir boolean leaveDirty = Boolean.parseBoolean(TestActivator.getContext().getProperty("p2.tests.doNotClean")); if (leaveDirty) return; for (Iterator iter = toRemove.iterator(); iter.hasNext(); ) { File next = (File) iter.next(); delete(next); } output = null; toRemove.clear(); }
protected void parseExitdata(String message) { // if the exit data contains a message telling us the location of the log file, then get it String data = TestActivator.getContext().getProperty("eclipse.exitdata"); if (data == null) return; String log = null; // big hack but for now assume the log file path is the last segment of the error message for (StringTokenizer tokenizer = new StringTokenizer(data); tokenizer.hasMoreTokens(); ) log = tokenizer.nextToken(); if (log == null) return; // remove trailing "." if (log.endsWith(".")) log = log.substring(0, log.length() - 1); String errors = read(log); if (errors == null) return; // fail using the text from the log file assertOK(message, new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, errors)); }