Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1c93f0981b63a662f0897d5bd2c1e57f218e28b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2007 Versant Corp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Markus Kuppe (mkuppe <at> versant <dot> com) - initial API and implementation
 ******************************************************************************/
package org.eclipse.ecf.tests.provider.jslp;

import org.eclipse.ecf.internal.provider.jslp.NullPatternAdvertiser;
import org.eclipse.ecf.internal.provider.jslp.NullPatternLocator;
import org.eclipse.ecf.provider.jslp.container.JSLPDiscoveryContainer;
import org.eclipse.ecf.tests.discovery.Activator;
import org.eclipse.ecf.tests.discovery.DiscoveryTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

public class JSLPDiscoveryTest extends DiscoveryTest {

	static {
		// we need SA functionality
		assertFalse("jSLP tests require net.slp.uaonly to be set to false because they need SA functionality.", new Boolean(System.getProperty("net.slp.uaonly")).booleanValue());
		// tests need root privileges to bind to slp port 427 in SA mode
		int port;
		try {
			port = Integer.parseInt(System.getProperty("net.slp.port", "427"));
		} catch (NumberFormatException e) {
			port = 427;
		}
		if(port <= 1024) {
			System.err.println("jSLP tests require root privileges to bind to port 427 (Alternatively the port can be set to a high port via -Dnet.slp.port=theHighPort");
		}
	}

	public JSLPDiscoveryTest() {
		super(JSLPDiscoveryContainer.NAME);
		setWaitTimeForProvider(JSLPDiscoveryContainer.REDISCOVER);
		//TODO-mkuppe https://bugs.eclipse.org/bugs/show_bug.cgi?id=230182
		setComparator(new JSLPTestComparator());
		//TODO-mkuppe https://bugs.eclipse.org/bugs/show_bug.cgi?id=218308
		setScope("default");
	}
	
	/**
	 * Test that the {@link NullPatternLocator} and {@link NullPatternAdvertiser} take
	 * over when the jSLP bundle gets stopped and that the SLP provider handles this gracefully
	 * @throws BundleException
	 */
	public void testJSLPBundleBecomesUnavailable() throws BundleException {
		Bundle bundle = null;
		try {
			// stop the bundle assuming there is only one installed
			BundleContext context = Activator.getDefault().getContext();
			Bundle[] bundles = context.getBundles();
			for(int i = 0; i < bundles.length; i++) {
				Bundle aBundle = bundles[i];
				if(aBundle.getSymbolicName().equals("ch.ethz.iks.slp")) {
					bundle = aBundle;
					break;
				}
			}
			assertNotNull("ch.ethz.iks.slp bundle not found", bundle);
			assertTrue(bundle.getState() == Bundle.ACTIVE);
			bundle.stop();
			assertTrue(bundle.getState() == Bundle.RESOLVED);
			assertEquals("No service should have been found since NullPatternLocator is active", discoveryContainer.getServices().length, 0);
		} finally {
			if(bundle != null) {
				bundle.start();
			}
		}
	}
}

Back to the top