You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2011/06/13 01:40:51 UTC
svn commit: r1135005 - in /river/jtsk/trunk/test/src/com/sun/jini:
discovery/ discovery/DiscoveryConstraintsTest.java discovery/plaintext/
discovery/plaintext/ClientTest.java discovery/ssl/
discovery/ssl/ClientTest.java outrigger/FastListTest.java
Author: peter_firmstone
Date: Sun Jun 12 23:40:50 2011
New Revision: 1135005
URL: http://svn.apache.org/viewvc?rev=1135005&view=rev
Log:
River-399 Add some junit tests for discovery.
Added:
river/jtsk/trunk/test/src/com/sun/jini/discovery/
river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java (with props)
river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/
river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java (with props)
river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/
river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java (with props)
Modified:
river/jtsk/trunk/test/src/com/sun/jini/outrigger/FastListTest.java
Added: river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java?rev=1135005&view=auto
==============================================================================
--- river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java (added)
+++ river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java Sun Jun 12 23:40:50 2011
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.discovery;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.constraint.Confidentiality;
+import net.jini.core.constraint.Integrity;
+import net.jini.core.constraint.InvocationConstraint;
+import net.jini.core.constraint.InvocationConstraints;
+import net.jini.core.constraint.ServerAuthentication;
+import net.jini.io.UnsupportedConstraintException;
+import net.jini.jeri.ssl.ConfidentialityStrength;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class DiscoveryConstraintsTest {
+
+ public DiscoveryConstraintsTest() {
+ }
+
+ DiscoveryConstraints instance;
+ InvocationConstraints constraints;
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ Collection<InvocationConstraint> required = new ArrayList<InvocationConstraint>(4);
+ InvocationConstraint integrity = Integrity.YES;
+ InvocationConstraint confidential = Confidentiality.YES;
+ InvocationConstraint serverAuth = ServerAuthentication.YES;
+ InvocationConstraint strength = ConfidentialityStrength.STRONG;
+ required.add(integrity);
+ required.add(confidential);
+ required.add(serverAuth);
+ required.add(strength);
+ Collection preferred = null;
+ constraints = new InvocationConstraints(required, preferred);
+ instance = null;
+ }
+
+// /**
+// * Test of multicastRequest method, of class DiscoveryConstraints.
+// */
+// @Test
+// public void multicastRequest() {
+// System.out.println("multicastRequest");
+// DiscoveryConstraints.multicastRequest();
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+//
+// /**
+// * Test of multicastAnnouncement method, of class DiscoveryConstraints.
+// */
+// @Test
+// public void multicastAnnouncement() {
+// System.out.println("multicastAnnouncement");
+// DiscoveryConstraints.multicastAnnouncement();
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+//
+// /**
+// * Test of unicastDiscovery method, of class DiscoveryConstraints.
+// */
+// @Test
+// public void unicastDiscovery() {
+// System.out.println("unicastDiscovery");
+// DiscoveryConstraints.unicastDiscovery();
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+//
+ /**
+ * Test of process() method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void process() throws Exception {
+ System.out.println("process");
+ instance = DiscoveryConstraints.process(constraints);
+ }
+
+ /**
+ * Test of chooseProtocolVersion method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void chooseProtocolVersion() throws Exception {
+ System.out.println("chooseProtocolVersion");
+ instance = DiscoveryConstraints.process(constraints);
+ int expResult = 2;
+ int result = instance.chooseProtocolVersion();
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ /**
+ * Test of checkProtocolVersion method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void checkProtocolVersion() throws Exception {
+ System.out.println("checkProtocolVersion");
+ int version = 2;
+ instance = DiscoveryConstraints.process(constraints);
+ instance.checkProtocolVersion(version);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ /**
+ * Test of getConnectionDeadline method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void getConnectionDeadline() throws Exception {
+ System.out.println("getConnectionDeadline");
+ long defaultValue = 0L;
+ instance = DiscoveryConstraints.process(constraints);
+ long expResult = 0L;
+ long result = instance.getConnectionDeadline(defaultValue);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ /**
+ * Test of getMulticastMaxPacketSize method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void getMulticastMaxPacketSize() throws Exception {
+ System.out.println("getMulticastMaxPacketSize");
+ int defaultValue = 0;
+ instance = DiscoveryConstraints.process(constraints);
+ int expResult = 0;
+ int result = instance.getMulticastMaxPacketSize(defaultValue);
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ /**
+ * Test of getMulticastTimeToLive method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void getMulticastTimeToLive() throws Exception {
+ System.out.println("getMulticastTimeToLive");
+ int defaultValue = 0;
+ instance = DiscoveryConstraints.process(constraints);
+ int expResult = 0;
+ int result = instance.getMulticastTimeToLive(defaultValue);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of getUnicastSocketTimeout method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void getUnicastSocketTimeout() throws Exception {
+ System.out.println("getUnicastSocketTimeout");
+ int defaultValue = 0;
+ instance = DiscoveryConstraints.process(constraints);
+ int expResult = 0;
+ int result = instance.getUnicastSocketTimeout(defaultValue);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of getUnfulfilledConstraints method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void getUnfulfilledConstraints() throws Exception {
+ System.out.println("getUnfulfilledConstraints");
+ instance = DiscoveryConstraints.process(constraints);
+ InvocationConstraints expResult = constraints;
+ InvocationConstraints result = instance.getUnfulfilledConstraints();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of getUnfulfilledConstraints method, of class DiscoveryConstraints.
+ */
+ @Test
+ public void testConstraints() throws Exception {
+ System.out.println("testConstraints");
+ Collection<InvocationConstraint> discoveryConstraints
+ = new ArrayList<InvocationConstraint>();
+ InvocationConstraint usoctimout = new UnicastSocketTimeout(10);
+ InvocationConstraint multicastMaxpackSize = new MulticastMaxPacketSize(512);
+ InvocationConstraint discoveryProtVer = DiscoveryProtocolVersion.TWO;
+ InvocationConstraint multicastTTL = new MulticastTimeToLive(100);
+ discoveryConstraints.add(usoctimout);
+ discoveryConstraints.add(multicastMaxpackSize);
+ discoveryConstraints.add(discoveryProtVer);
+ discoveryConstraints.add(multicastTTL);
+
+ Collection<InvocationConstraint> requiredAdditionalConstraints = new ArrayList<InvocationConstraint>(4);
+ InvocationConstraint integrity = Integrity.YES;
+ InvocationConstraint confidential = Confidentiality.YES;
+ InvocationConstraint serverAuth = ServerAuthentication.YES;
+ InvocationConstraint strength = ConfidentialityStrength.STRONG;
+ requiredAdditionalConstraints.add(integrity);
+ requiredAdditionalConstraints.add(confidential);
+ requiredAdditionalConstraints.add(serverAuth);
+ requiredAdditionalConstraints.add(strength);
+
+ Collection<InvocationConstraint> combined = new ArrayList<InvocationConstraint>();
+ combined.addAll(discoveryConstraints);
+ combined.addAll(requiredAdditionalConstraints);
+
+ Collection preferred = null;
+
+ constraints = new InvocationConstraints(combined, preferred);
+
+ instance = DiscoveryConstraints.process(constraints);
+ InvocationConstraints expResult
+ = new InvocationConstraints(requiredAdditionalConstraints, preferred);
+ InvocationConstraints result = instance.getUnfulfilledConstraints();
+ assertEquals(expResult, result);
+ }
+
+}
\ No newline at end of file
Propchange: river/jtsk/trunk/test/src/com/sun/jini/discovery/DiscoveryConstraintsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java?rev=1135005&view=auto
==============================================================================
--- river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java (added)
+++ river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java Sun Jun 12 23:40:50 2011
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.discovery.plaintext;
+
+import com.sun.jini.discovery.DatagramBufferFactory;
+import com.sun.jini.discovery.MulticastAnnouncement;
+import com.sun.jini.discovery.MulticastRequest;
+import com.sun.jini.discovery.UnicastResponse;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import net.jini.core.constraint.Confidentiality;
+import net.jini.core.constraint.Integrity;
+import net.jini.core.constraint.InvocationConstraint;
+import net.jini.core.constraint.InvocationConstraints;
+import net.jini.core.constraint.ServerAuthentication;
+import net.jini.io.UnsupportedConstraintException;
+import net.jini.jeri.ssl.ConfidentialityStrength;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ClientTest {
+ Client instance;
+ public ClientTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = new Client();
+ }
+
+ /**
+ * Test of getFormatName method, of class Client.
+ */
+ @Test
+ public void getFormatName() {
+ System.out.println("getFormatName");
+ String expResult = "net.jini.discovery.plaintext";
+ String result = instance.getFormatName();
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+// /**
+// * Test of encodeMulticastRequest method, of class Client.
+// */
+// @Test
+// public void encodeMulticastRequest() throws Exception {
+// System.out.println("encodeMulticastRequest");
+// MulticastRequest request = null;
+// DatagramBufferFactory bufs = null;
+// InvocationConstraints constraints = null;
+// Client instance = new Client();
+// instance.encodeMulticastRequest(request, bufs, constraints);
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+//
+// /**
+// * Test of decodeMulticastAnnouncement method, of class Client.
+// */
+// @Test
+// public void decodeMulticastAnnouncement() throws Exception {
+// System.out.println("decodeMulticastAnnouncement");
+// ByteBuffer buf = null;
+// InvocationConstraints constraints = null;
+// Client instance = new Client();
+// MulticastAnnouncement expResult = null;
+// MulticastAnnouncement result = instance.decodeMulticastAnnouncement(buf, constraints);
+// assertEquals(expResult, result);
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+
+ /**
+ * Test of checkUnicastDiscoveryConstraints method, of class Client.
+ */
+ @Test
+ public void checkUnicastDiscoveryConstraints() throws Exception {
+ System.out.println("checkUnicastDiscoveryConstraints");
+ Collection<InvocationConstraint> required = new ArrayList<InvocationConstraint>(4);
+ InvocationConstraint integrity = Integrity.YES;
+ InvocationConstraint confidential = Confidentiality.YES;
+ InvocationConstraint serverAuth = ServerAuthentication.YES;
+ InvocationConstraint strength = ConfidentialityStrength.STRONG;
+ required.add(integrity);
+ required.add(confidential);
+ required.add(serverAuth);
+ required.add(strength);
+ Collection preferred = null;
+ InvocationConstraints constraints = new InvocationConstraints(required, preferred);
+ Exception ex = null;
+ try {
+ instance.checkUnicastDiscoveryConstraints(constraints);
+ }catch(UnsupportedConstraintException e){
+ ex = e;
+ }
+ assertTrue( ex != null);
+ }
+
+// /**
+// * Test of doUnicastDiscovery method, of class Client.
+// */
+// @Test
+// public void doUnicastDiscovery() throws Exception {
+// System.out.println("doUnicastDiscovery");
+// Socket socket = null;
+// InvocationConstraints constraints = null;
+// ClassLoader defaultLoader = null;
+// ClassLoader verifierLoader = null;
+// Collection context = null;
+// ByteBuffer sent = null;
+// ByteBuffer received = null;
+// Client instance = new Client();
+// UnicastResponse expResult = null;
+// UnicastResponse result = instance.doUnicastDiscovery(socket, constraints, defaultLoader, verifierLoader, context, sent, received);
+// assertEquals(expResult, result);
+// // TODO review the generated test code and remove the default call to fail.
+// fail("The test case is a prototype.");
+// }
+
+}
\ No newline at end of file
Propchange: river/jtsk/trunk/test/src/com/sun/jini/discovery/plaintext/ClientTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java?rev=1135005&view=auto
==============================================================================
--- river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java (added)
+++ river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java Sun Jun 12 23:40:50 2011
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.discovery.ssl;
+
+import com.sun.jini.discovery.UnicastResponse;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
+import net.jini.core.constraint.ClientAuthentication;
+import net.jini.core.constraint.Confidentiality;
+import net.jini.core.constraint.Integrity;
+import net.jini.core.constraint.InvocationConstraint;
+import net.jini.core.constraint.InvocationConstraints;
+import net.jini.core.constraint.ServerAuthentication;
+import net.jini.io.UnsupportedConstraintException;
+import net.jini.jeri.ssl.ConfidentialityStrength;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ClientTest {
+
+ public ClientTest() {
+ }
+ Client instance;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = new Client();
+ }
+
+ /**
+ * Test of getFormatName method, of class Client.
+ */
+ @Test
+ public void getFormatName() {
+ System.out.println("getFormatName");
+ Client instance = new Client();
+ String expResult = "net.jini.discovery.ssl";
+ String result = instance.getFormatName();
+ assertEquals(expResult, result);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ /**
+ * Test of checkUnicastDiscoveryConstraints method, of class Client.
+ */
+ @Test
+ public void checkUnicastDiscoveryConstraints() throws Exception {
+ System.out.println("checkUnicastDiscoveryConstraints");
+ Collection<InvocationConstraint> required = new ArrayList<InvocationConstraint>(4);
+ InvocationConstraint integrity = Integrity.YES;
+ InvocationConstraint confidential = Confidentiality.YES;
+ InvocationConstraint serverAuth = ServerAuthentication.YES;
+ InvocationConstraint strength = ConfidentialityStrength.STRONG;
+ required.add(integrity);
+ required.add(confidential);
+ required.add(serverAuth);
+ required.add(strength);
+ Collection preferred = null;
+ InvocationConstraints constraints = new InvocationConstraints(required, preferred);
+ instance.checkUnicastDiscoveryConstraints(constraints);
+ // TODO review the generated test code and remove the default call to fail.
+ }
+
+ @Test
+ public void checkConstraintFailClientAuth() throws Exception {
+ System.out.println("checkConstraintFailClientAuth");
+ Collection<InvocationConstraint> required = new ArrayList<InvocationConstraint>(4);
+ InvocationConstraint clientAuth = ClientAuthentication.YES;
+ required.add(clientAuth);
+ Collection preferred = null;
+ InvocationConstraints constraints = new InvocationConstraints(required, preferred);
+ UnsupportedConstraintException ex = null;
+ try {
+ instance.checkUnicastDiscoveryConstraints(constraints);
+ } catch (UnsupportedConstraintException e) {
+ ex = e;
+ }
+ assertTrue( ex != null);
+ }
+}
\ No newline at end of file
Propchange: river/jtsk/trunk/test/src/com/sun/jini/discovery/ssl/ClientTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: river/jtsk/trunk/test/src/com/sun/jini/outrigger/FastListTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/test/src/com/sun/jini/outrigger/FastListTest.java?rev=1135005&r1=1135004&r2=1135005&view=diff
==============================================================================
--- river/jtsk/trunk/test/src/com/sun/jini/outrigger/FastListTest.java (original)
+++ river/jtsk/trunk/test/src/com/sun/jini/outrigger/FastListTest.java Sun Jun 12 23:40:50 2011
@@ -29,7 +29,6 @@ public class FastListTest {
public void initialize() {
testee = new FastList<TestNode>();
rawTestee = new Iterable<TestNode>() {
- @Override
public Iterator<TestNode> iterator() {
return testee.rawIterator();
}
@@ -181,7 +180,6 @@ public class FastListTest {
private List<Thread> getAddThreads(final List<List<TestNode>> elements,
final CyclicBarrier barrier) {
NodeListRunnableFactory factory = new NodeListRunnableFactory() {
- @Override
public Runnable getRunnable(final List<TestNode> nodes) {
return new Runnable() {
public void run() {
@@ -207,7 +205,6 @@ public class FastListTest {
private List<Thread> getRemoveThreads(final List<List<TestNode>> elements,
final CyclicBarrier barrier) {
NodeListRunnableFactory factory = new NodeListRunnableFactory() {
- @Override
public Runnable getRunnable(final List<TestNode> nodes) {
return new Runnable() {
public void run() {
@@ -233,7 +230,6 @@ public class FastListTest {
private List<Thread> getRemoveAllThreads(final List<List<TestNode>> elements,
final CyclicBarrier barrier, final int tries) {
NodeListRunnableFactory factory = new NodeListRunnableFactory() {
- @Override
public Runnable getRunnable(final List<TestNode> nodes) {
return new Runnable() {
public void run() {