Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Alexander Kuppe2010-06-25 10:57:42 -0400
committerMarkus Alexander Kuppe2010-06-25 10:57:42 -0400
commitd5c12f84eef1e8b4d7baa5d6a4eb10aaad5bebb9 (patch)
tree6a90b6f16e08984531042c980080c3e5b219e72d /tests/bundles/org.eclipse.ecf.tests.provider.dnssd
parent1ca6c0816b9b5a1316ea5d9264e62477028d60e4 (diff)
downloadorg.eclipse.ecf-d5c12f84eef1e8b4d7baa5d6a4eb10aaad5bebb9.tar.gz
org.eclipse.ecf-d5c12f84eef1e8b4d7baa5d6a4eb10aaad5bebb9.tar.xz
org.eclipse.ecf-d5c12f84eef1e8b4d7baa5d6a4eb10aaad5bebb9.zip
NEW - bug 314999: [Discovery][DNS-SD] Implement IDiscoveryAdvertiser
https://bugs.eclipse.org/bugs/show_bug.cgi?id=314999
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.provider.dnssd')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF4
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserComparator.java58
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserServiceTest.java80
3 files changed, 133 insertions, 9 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
index 7e82b5d28..059f4447b 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/META-INF/MANIFEST.MF
@@ -10,7 +10,9 @@ Require-Bundle: org.eclipse.equinox.common;bundle-version="3.4.0",
org.eclipse.ecf.discovery;bundle-version="3.0.0",
org.eclipse.ecf.provider.dnssd;bundle-version="1.0.0",
org.eclipse.ecf.tests.discovery;bundle-version="2.0.0",
- org.junit;bundle-version="3.8.2"
+ org.junit;bundle-version="3.8.2",
+ org.xbill.dns;bundle-version="2.0.8",
+ org.eclipse.equinox.concurrent;bundle-version="1.0.100"
Bundle-ActivationPolicy: lazy
Import-Package: org.osgi.framework;version="1.3.0",
org.osgi.service.cm;version="1.2.0"
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserComparator.java b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserComparator.java
new file mode 100644
index 000000000..d7b5a276c
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserComparator.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Markus Alexander Kuppe.
+ * 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 Alexander Kuppe (ecf-dev_eclipse.org <at> lemmster <dot> de) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.tests.provider.dnssd;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.SRVRecord;
+import org.xbill.DNS.TXTRecord;
+
+public class DnsSdAdvertiserComparator implements Comparator {
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(final Object arg0, final Object arg1) {
+ int result = -1;
+ if (arg0 instanceof IServiceInfo && arg1 instanceof List) {
+ final IServiceInfo serviceInfo = (IServiceInfo) arg0;
+ result = (serviceInfo.getServiceProperties().size() + 5) * -1;
+
+ final List records = (List) arg1;
+ for (final Iterator itr = records.iterator(); itr.hasNext();) {
+ final Record record = (Record) itr.next();
+ if(record instanceof SRVRecord) {
+ final SRVRecord srvRec = (SRVRecord) record;
+ final String name = srvRec.getName().toString();
+ if(name.startsWith("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO)) {
+ final String target = srvRec.getTarget().toString();
+ result += serviceInfo.getPriority() == srvRec.getPriority() ? 1 : -1;
+ result += serviceInfo.getWeight() == srvRec.getWeight() ? 1 : -1;
+ result += 3600 == srvRec.getTTL() ? 1 : -1;
+ result += serviceInfo.getLocation().getHost().equals(target.substring(0, target.length() - 1)) ? 1 : -1;
+ result += serviceInfo.getLocation().getPort() == srvRec.getPort() ? 1 : -1;
+ }
+ } else if(record instanceof TXTRecord) {
+ final String[] str = record.rdataToString().split("=");
+ final String key = str[0].substring(1);
+ final String value = str[1].substring(0, str[1].length() - 1);
+ final Object property = serviceInfo.getServiceProperties().getProperty(key);
+ result += value.equals(property.toString()) ? 1 : -1;
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserServiceTest.java b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserServiceTest.java
index d63e5f721..c434149d7 100644
--- a/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserServiceTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.provider.dnssd/src/org/eclipse/ecf/tests/provider/dnssd/DnsSdAdvertiserServiceTest.java
@@ -10,41 +10,97 @@
******************************************************************************/
package org.eclipse.ecf.tests.provider.dnssd;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.discovery.IDiscoveryAdvertiser;
import org.eclipse.ecf.discovery.IDiscoveryLocator;
import org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest;
-import org.eclipse.ecf.tests.discovery.Activator;
+import org.xbill.DNS.Message;
+import org.xbill.DNS.Name;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.SimpleResolver;
+import org.xbill.DNS.TSIG;
+import org.xbill.DNS.Update;
+import org.xbill.DNS.ZoneTransferIn;
public class DnsSdAdvertiserServiceTest extends AbstractDiscoveryTest {
public DnsSdAdvertiserServiceTest() {
super(DnsSdTestHelper.ECF_DISCOVERY_DNSSD);
setNamingAuthority(DnsSdTestHelper.NAMING_AUTH);
- setScope(DnsSdTestHelper.DOMAIN);
- setServices(new String[]{DnsSdTestHelper.SCHEME});
+ setScope(DnsSdTestHelper.REG_DOMAIN);
+ setServices(new String[]{DnsSdTestHelper.REG_SCHEME});
setProtocol(DnsSdTestHelper.PROTO);
- setComparator(new DnsSdDiscoveryComparator());
+ setComparator(new DnsSdAdvertiserComparator());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // purge all SRV records from the test domain
+ ZoneTransferIn xfr = ZoneTransferIn.newAXFR(new Name(DnsSdTestHelper.REG_DOMAIN), DnsSdTestHelper.DNS_SERVER, null);
+ List records = xfr.run();
+ for (Iterator itr = records.iterator(); itr.hasNext();) {
+ Record record = (Record) itr.next();
+ String name = record.getName().toString();
+ if(name.startsWith("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO)) {
+ Update update = new Update(Name.fromString(DnsSdTestHelper.REG_DOMAIN + "."));
+ update.delete(record);
+ SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
+ resolver.setTCP(true);
+ resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
+ Message response = resolver.send(update);
+ int rcode = response.getRcode();
+ assertTrue("", rcode == 0);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
}
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest#getDiscoveryLocator()
*/
protected IDiscoveryAdvertiser getDiscoveryAdvertiser() {
- return Activator.getDefault().getDiscoveryAdvertiser(containerUnderTest);
+ return (IDiscoveryAdvertiser) Activator.getDefault().getDiscoveryLocator();
}
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.AbstractDiscoveryTest#getDiscoveryLocator()
*/
protected IDiscoveryLocator getDiscoveryLocator() {
- return Activator.getDefault().getDiscoveryLocator(containerUnderTest);
+ return Activator.getDefault().getDiscoveryLocator();
}
-
+
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.provider.dnssd.DnsSdDiscoveryServiceTest#testRegisterService()
*/
- public void testRegisterService() throws ContainerConnectException {
+ public void testRegisterService() throws Exception {
+
+ // actually register the service
+ discoveryAdvertiser.registerService(serviceInfo);
+
+ // check postcondition service is registered
+ ZoneTransferIn xfr = ZoneTransferIn.newAXFR(new Name(DnsSdTestHelper.REG_DOMAIN), DnsSdTestHelper.DNS_SERVER, null);
+ assertTrue("Mismatch between DNS response and IServiceInfo", comparator.compare(serviceInfo, xfr.run()) == 0);
+ }
+
+
+ /**
+ * Tests that a register is handled correctly when no key is present
+ * for that domain and the underlying ddns call fails
+ */
+ public void testRegisterServiceWithoutHostKey() {
fail("Not yet implemented");
}
@@ -54,4 +110,12 @@ public class DnsSdAdvertiserServiceTest extends AbstractDiscoveryTest {
public void testUnregisterService() throws ContainerConnectException {
fail("Not yet implemented");
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.tests.provider.dnssd.DnsSdDiscoveryServiceTest#testUnregisterAllServices()
+ */
+ public void testUnregisterAllServices() throws ContainerConnectException {
+ //TODO make sure not to accidentally remove preexisting SRV records
+ fail("Not yet implemented");
+ }
}

Back to the top