From ed5856810aa411e4c20277e7395f4442d045def1 Mon Sep 17 00:00:00 2001 From: seb Date: Thu, 25 Nov 2010 16:03:44 +0000 Subject: [PATCH] - Add a missing test about foundation to change \"frozen\" candidate pair state to \"waiting\"; - Nominee for a component are now obtained by looking in \"ValidList\" rather than \"CheckList\"; - Checks that are received before we start ours are triggered immediately when ICE state change to RUNNING; - Always use \"BASE\" transport address as source for sending and checking STUN request (peer reflexive cases); - Fix infinite recursivity in DelegatingDatagramSocket; - Various formatting, typos, 80-line cut and missing javadocs fix. --- .../RequestedTransportAttribute.java | 2 +- src/org/ice4j/ice/Agent.java | 30 +++++++-- src/org/ice4j/ice/Candidate.java | 7 +-- src/org/ice4j/ice/CandidatePair.java | 10 +-- src/org/ice4j/ice/CheckList.java | 11 +++- src/org/ice4j/ice/Component.java | 10 +-- .../ice4j/ice/ConnectivityCheckClient.java | 16 +++-- .../ice4j/ice/ConnectivityCheckServer.java | 6 +- src/org/ice4j/ice/IceMediaStream.java | 31 +++++++++- src/org/ice4j/ice/RelayedCandidate.java | 4 +- .../socket/DelegatingDatagramSocket.java | 5 +- .../socket/TurnDatagramPacketFilter.java | 10 +-- .../ice4j/attribute/AddressAttributeTest.java | 62 ++++++++++--------- .../ice4j/attribute/AttributeDecoderTest.java | 12 ++-- .../attribute/ChangeRequestAttributeTest.java | 48 +++++++++----- .../attribute/ErrorCodeAttributeTest.java | 50 +++++++-------- .../OptionalAttributeAttributeTest.java | 2 - .../attribute/SoftwareAttributeTest.java | 3 +- .../UnknownAttributesAttributeTest.java | 47 +++++++++----- .../org/ice4j/message/MessageFactoryTest.java | 57 +++++++++-------- test/org/ice4j/message/MessageTest.java | 36 ++++++----- .../stunclient/StunAddressDiscovererTest.java | 1 - .../StunAddressDiscovererTest_v4v6.java | 3 +- .../StunAddressDiscovererTest_v6.java | 8 +-- 24 files changed, 285 insertions(+), 186 deletions(-) diff --git a/src/org/ice4j/attribute/RequestedTransportAttribute.java b/src/org/ice4j/attribute/RequestedTransportAttribute.java index 442c30a..f206a53 100644 --- a/src/org/ice4j/attribute/RequestedTransportAttribute.java +++ b/src/org/ice4j/attribute/RequestedTransportAttribute.java @@ -13,7 +13,7 @@ import org.ice4j.*; * TURN address of certain transport protocol. * * In the original TURN specification, only UDP is supported. - * Support of TCP is detailed in draft-ietf-behave-turn-tcp-05. + * Support of TCP is detailed in draft-ietf-behave-turn-tcp-07. * * @author Sebastien Vincent */ diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 096be13..7fe7fa6 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -375,6 +375,21 @@ public class Agent //change state before we actually send checks so that we don't //miss responses and hence the possibility to nominate a pair. setState(IceProcessingState.RUNNING); + + //if we have received connectivity checks before RUNNING state, + //trigger a check for those candidate pairs. + if(this.preDiscoveredPairsQueue.size() > 0) + { + Iterator it = preDiscoveredPairsQueue.iterator(); + + while(it.hasNext()) + { + triggerCheck(it.next()); + } + + this.preDiscoveredPairsQueue.clear(); + } + connCheckClient.startChecks(); } } @@ -1029,7 +1044,9 @@ public class Agent = new CandidatePair(localCandidate, remoteCandidate); if(useCandidate) + { triggeredPair.setUseCandidateReceived(); + } synchronized(startLock) { @@ -1042,7 +1059,7 @@ public class Agent else { //we are not started yet so we'd better wait until we get the - //remote candidates incase we are holding to a new PR one. + //remote candidates in case we are holding to a new PR one. this.preDiscoveredPairsQueue.add(triggeredPair); } } @@ -1133,7 +1150,7 @@ public class Agent // Emil: This actually applies for all cases. /* * Lyubomir: The connectivity checks for a CheckList are started - * elsewhere as soon as and only if the CheckList changes from fronzen + * elsewhere as soon as and only if the CheckList changes from frozen * to unfrozen. Since CheckList#scheduleTriggeredCheck will change * triggerPair to Waiting and will thus unfreeze its CheckList, make * sure that the connectivity checks for the CheckList are started. @@ -1176,7 +1193,7 @@ public class Agent * * @see Agent#setNominationStrategy(NominationStrategy) */ - public void nominate(CandidatePair pair) + public synchronized void nominate(CandidatePair pair) throws IllegalStateException { if(! isControlling() ) @@ -1185,12 +1202,14 @@ public class Agent Component parentComponent = pair.getParentComponent(); IceMediaStream parentStream = parentComponent.getParentStream(); - CheckList checkList = parentStream.getCheckList(); + //CheckList checkList = parentStream.getCheckList(); //If the pair is not already nominated and if its parent component //does not already contain a nominated pair - nominate it. if(!pair.isNominated() - && !checkList.containsNomineeForComponent(parentComponent)) + && !parentStream.validListContainsNomineeForComponent( + parentComponent)) + /* && !checkList.containsNomineeForComponent(parentComponent)) */ { pair.nominate(); pair.getParentComponent().getParentStream() @@ -1267,6 +1286,7 @@ public class Agent atLeastOneListSucceeded = true; } } + //Once the state of each check list is Completed: //The agent sets the state of ICE processing overall to Completed. if(allListsEnded) diff --git a/src/org/ice4j/ice/Candidate.java b/src/org/ice4j/ice/Candidate.java index d1dabfe..bae1451 100644 --- a/src/org/ice4j/ice/Candidate.java +++ b/src/org/ice4j/ice/Candidate.java @@ -337,13 +337,13 @@ public abstract class Candidate */ public long computePriorityForType(CandidateType candidateType) { - //According to the ICE speck we compute priority this way: + //According to the ICE spec we compute priority this way: //priority = (2^24)*(type preference) + // (2^8)*(local preference) + // (2^0)*(256 - component ID) - return (long)( getTypePreference(candidateType) << 24 )+ - (long)( getLocalPreference() << 8 )+ + return (long) (getTypePreference(candidateType) << 24) + + (long) (getLocalPreference() << 8 ) + (long) (256 - getParentComponent().getComponentID()); } @@ -422,7 +422,6 @@ public abstract class Candidate if(isVirtual()) return MIN_LOCAL_PREFERENCE; - InetAddress addr = getTransportAddress().getAddress(); //the following tries to reusse precedence from RFC 3484 but that's a diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java index 9cfcfbf..3a92572 100644 --- a/src/org/ice4j/ice/CandidatePair.java +++ b/src/org/ice4j/ice/CandidatePair.java @@ -449,11 +449,11 @@ public class CandidatePair * Indicates whether some other object is "equal to" to this * Comparator. This method must obey the general contract of * Object.equals(Object). Additionally, this method can return - * true only if the specified Object is also a comparator - * and it imposes the same ordering as this comparator. Thus, - * comp1.equals(comp2) implies that sgn(comp1.compare(o1, - * o2))==sgn(comp2.compare(o1, o2)) for every object reference - * o1 and o2.

+ * true only if the specified Object is also a + * comparator and it imposes the same ordering as this comparator. Thus, + * comp1.equals(comp2) implies that + * sgn(comp1.compare(o1,o2))==sgn(comp2.compare(o1, o2)) for + * every object reference o1 and o2.

* * Note that it is always safe not to override * Object.equals(Object). However, overriding this method may, diff --git a/src/org/ice4j/ice/CheckList.java b/src/org/ice4j/ice/CheckList.java index 0ffc555..b202422 100644 --- a/src/org/ice4j/ice/CheckList.java +++ b/src/org/ice4j/ice/CheckList.java @@ -170,6 +170,7 @@ public class CheckList || pair.getPriority() > highestPriorityPair.getPriority()) { highestPriorityPair = pair; + pair.setStateWaiting(); } } } @@ -401,19 +402,23 @@ public class CheckList * nominated {@link CandidatePair} for the specified component * and false otherwise. * - * @param componennt the {@link Component} that we'd whose nominees we are + * @param component the {@link Component} that we'd whose nominees we are * interested in. * * @return true if this CheckList already contains a * nominated {@link CandidatePair} for the specified component * and false otherwise. + * @deprecated This method takes into account only candidates in the + * checklist. In case of peer reflexives candidates nominated, they do not + * appears in checklist but in valid list. */ + @Deprecated public synchronized boolean containsNomineeForComponent( - Component componennt) + Component component) { for (CandidatePair pair : this) { - if (pair.isNominated() && pair.getParentComponent() == componennt) + if (pair.isNominated() && pair.getParentComponent() == component) return true; } diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 63295c5..1b2401f 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -413,11 +413,11 @@ public class Component * Indicates whether some other object is "equal to" this * Comparator. This method must obey the general contract of * Object.equals(Object). Additionally, this method can return - * true only if the specified Object is also a comparator - * and it imposes the same ordering as this comparator. Thus, - * comp1.equals(comp2) implies that sgn(comp1.compare(o1, - * o2))==sgn(comp2.compare(o1, o2)) for every object reference - * o1 and o2.

+ * true only if the specified Object is also a + * comparator and it imposes the same ordering as this comparator. Thus, + * comp1.equals(comp2) implies that + * sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2)) for + * every object reference o1 and o2.

* * Note that it is always safe not to override * Object.equals(Object). However, overriding this method may, diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index dd277ec..2ce8c82 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -164,12 +164,15 @@ class ConnectivityCheckClient try { + TransportAddress localAddr = localCandidate.getBase(). + getTransportAddress(); + tran = stunStack.sendRequest( request, candidatePair .getRemoteCandidate().getTransportAddress(), - localCandidate.getTransportAddress(), + localAddr, this, tran); if(logger.isLoggable(Level.FINEST)) @@ -402,7 +405,8 @@ class ConnectivityCheckClient CheckList parentCheckList = parentStream.getCheckList(); for(CandidatePair pair : parentCheckList) - if (pair.getState() == CandidatePairState.FROZEN) + if ((pair.getState() == CandidatePairState.FROZEN) && + (checkedPair.getFoundation().equals(pair.getFoundation()))) pair.setStateWaiting(); // The agent examines the check list for all other streams in turn @@ -484,9 +488,10 @@ class ConnectivityCheckClient { CandidatePair pair = ((CandidatePair)evt.getTransactionID() .getApplicationData()); + TransportAddress localAddr = pair.getLocalCandidate().getBase(). + getTransportAddress(); - boolean sym = pair.getLocalCandidate().getTransportAddress() - .equals(evt.getLocalAddress()) + boolean sym = localAddr.equals(evt.getLocalAddress()) && pair.getRemoteCandidate().getTransportAddress() .equals(evt.getRemoteAddress()); @@ -640,7 +645,8 @@ class ConnectivityCheckClient } catch (InterruptedException e) { - logger.log(Level.FINER, "PaceMake got interrupted", e); + logger.log(Level.FINER, "PaceMaker got interrupted", + e); } if (!running) diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java index b97bba5..d696b54 100644 --- a/src/org/ice4j/ice/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/ConnectivityCheckServer.java @@ -119,7 +119,7 @@ class ConnectivityCheckServer //tell our address handler we saw a new remote address; parentAgent.incomingCheckReceived(evt.getRemoteAddress(), - evt.getLocalAddress(), priority, remoteUfrag, useCandidate); + evt.getLocalAddress(), priority, remoteUfrag, useCandidate); Response response = MessageFactory.createBindingResponse( request, evt.getRemoteAddress()); @@ -127,7 +127,7 @@ class ConnectivityCheckServer try { stunStack.sendResponse(evt.getTransactionID().getBytes(), - response, evt.getLocalAddress(), evt.getRemoteAddress()); + response, evt.getLocalAddress(), evt.getRemoteAddress()); } catch (Exception e) { @@ -176,7 +176,7 @@ class ConnectivityCheckServer } /** - * Resolves a role conflicts by either sendinf a 487 Role Conflict + * Resolves a role conflicts by either sending a 487 Role Conflict * response or by changing this server's parent agent role. The method * returns true if the role conflict is silently resolved and * processing can continue. It returns false if we had to reply diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 0397c4b..e1b784a 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -493,7 +493,6 @@ public class IceMediaStream return null; } - /** * Returns the {@link CandidatePair} with the specified remote and local * addresses or null if neither of the {@link CheckList}s in this @@ -602,6 +601,34 @@ public class IceMediaStream return false; } + /** + * Returns true if this stream's validList contains a + * pair that is nominated for the specified Component and + * false otherwise. + * + * @param component the Component we'd like to search our + * validList for. + * + * @return true if this stream's validList contains a + * pair that is nominated for the specified Component and + * false otherwise. + */ + protected boolean validListContainsNomineeForComponent(Component component) + { + synchronized(validList) + { + for(CandidatePair pair : validList) + { + if (pair.isNominated() && pair.getParentComponent() == + component) + { + return true; + } + } + } + return false; + } + /** * Returns true if this stream's valid list contains at least * one {@link CandidatePair} for each {@link Component} of the stream and @@ -744,7 +771,7 @@ public class IceMediaStream } PropertyChangeEvent evt = new PropertyChangeEvent( - source, PROPERTY_PAIR_VALIDATED, oldValue, newValue); + source, propertyName, oldValue, newValue); for(PropertyChangeListener l : listenersCopy) { diff --git a/src/org/ice4j/ice/RelayedCandidate.java b/src/org/ice4j/ice/RelayedCandidate.java index 355ea92..ed63809 100644 --- a/src/org/ice4j/ice/RelayedCandidate.java +++ b/src/org/ice4j/ice/RelayedCandidate.java @@ -28,7 +28,7 @@ public class RelayedCandidate /** * The RelayedCandidateDatagramSocket of this - * RelayedCandidate. + * RelayedCandidate. */ private RelayedCandidateDatagramSocket relayedCandidateDatagramSocket; @@ -49,7 +49,7 @@ public class RelayedCandidate * specific TransportAddress harvested through a specific * HostCandidate and a TURN server with a specific * TransportAddress. - * + * * @param transportAddress the TransportAddress to be represented * by the new instance * @param turnCandidateHarvest the TurnCandidateHarvest which has diff --git a/src/org/ice4j/socket/DelegatingDatagramSocket.java b/src/org/ice4j/socket/DelegatingDatagramSocket.java index 30f3027..05e80d2 100644 --- a/src/org/ice4j/socket/DelegatingDatagramSocket.java +++ b/src/org/ice4j/socket/DelegatingDatagramSocket.java @@ -485,7 +485,7 @@ public class DelegatingDatagramSocket @Override public boolean isClosed() { - return (delegate == null) ? super.isClosed() : this.isClosed(); + return (delegate == null) ? super.isClosed() : delegate.isClosed(); } /** @@ -498,7 +498,8 @@ public class DelegatingDatagramSocket @Override public boolean isConnected() { - return (delegate == null) ? super.isConnected() : this.isConnected(); + return (delegate == null) ? super.isConnected() : + delegate.isConnected(); } /** diff --git a/src/org/ice4j/socket/TurnDatagramPacketFilter.java b/src/org/ice4j/socket/TurnDatagramPacketFilter.java index 6bf6e2a..122c3ec 100644 --- a/src/org/ice4j/socket/TurnDatagramPacketFilter.java +++ b/src/org/ice4j/socket/TurnDatagramPacketFilter.java @@ -15,11 +15,11 @@ import org.ice4j.message.*; /** * Implements a DatagramPacketFilter which accepts * DatagramPackets which represent TURN messages defined in - * draft-ietf-behave-turn-16 "Traversal Using Relays around NAT (TURN): Relay - * Extensions to Session Traversal Utilities for NAT (STUN)" and which are part - * of the communication with a specific TURN server. - * TurnDatagramPacketFilter does not accept TURN ChannelData messages - * because they require knowledge of the value of the "Channel Number" field. + * RFC 5766 "Traversal Using Relays around NAT (TURN): Relay Extensions to + * Session Traversal Utilities for NAT (STUN)" and which are part of the + * communication with a specific TURN server. TurnDatagramPacketFilter + * does not accept TURN ChannelData messages because they require knowledge of + * the value of the "Channel Number" field. * * @author Lubomir Marinov */ diff --git a/test/org/ice4j/attribute/AddressAttributeTest.java b/test/org/ice4j/attribute/AddressAttributeTest.java index 97488a2..4bf0262 100644 --- a/test/org/ice4j/attribute/AddressAttributeTest.java +++ b/test/org/ice4j/attribute/AddressAttributeTest.java @@ -320,10 +320,10 @@ public class AddressAttributeTest extends TestCase { assertEquals( "AddressAttribute.decode() did not properly decode the port field.", - msgFixture.ADDRESS_ATTRIBUTE_PORT, addressAttribute.getPort()); + MsgFixture.ADDRESS_ATTRIBUTE_PORT, addressAttribute.getPort()); assertTrue( "AddressAttribute.decode() did not properly decode the address field.", - Arrays.equals( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + Arrays.equals( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, addressAttribute.getAddressBytes())); @@ -342,10 +342,10 @@ public class AddressAttributeTest extends TestCase { assertEquals("decode() failed for an IPv6 Addr's port.", - msgFixture.ADDRESS_ATTRIBUTE_PORT, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, addressAttribute.getPort()); assertTrue("AddressAttribute.decode() failed for an IPv6 address.", - Arrays.equals( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + Arrays.equals( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, addressAttribute.getAddressBytes())); @@ -354,7 +354,7 @@ public class AddressAttributeTest extends TestCase { /** * Test whether attributes are properly encoded. * - * @throws StunException java.lang.Exception if we fail + * @throws Exception java.lang.Exception if we fail */ public void testEncode() throws Exception @@ -362,8 +362,8 @@ public class AddressAttributeTest extends TestCase { byte[] expectedReturn = msgFixture.mappedAddress; addressAttribute.setAddress( - new TransportAddress(msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + new TransportAddress(MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); byte[] actualReturn = addressAttribute.encode(); @@ -375,7 +375,7 @@ public class AddressAttributeTest extends TestCase { /** * Test whether attributes are properly encoded. * - * @throws StunException java.lang.Exception if we fail + * @throws Exception java.lang.Exception if we fail */ public void testEncodev6() throws Exception @@ -383,8 +383,8 @@ public class AddressAttributeTest extends TestCase { byte[] expectedReturn = msgFixture.mappedAddressv6; addressAttribute.setAddress( - new TransportAddress(msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); + new TransportAddress(MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); byte[] actualReturn = addressAttribute.encode(); assertTrue("An AddressAttribute did not properly encode an IPv6 addr.", @@ -396,7 +396,7 @@ public class AddressAttributeTest extends TestCase { * Tests the equals method against a null, a different and an identical * object. * - * @throws StunException java.lang.Exception if we fail + * @throws Exception java.lang.Exception if we fail */ public void testEquals() throws Exception @@ -412,13 +412,13 @@ public class AddressAttributeTest extends TestCase { //difference test target = new MappedAddressAttribute(); - char port = (char)(msgFixture.ADDRESS_ATTRIBUTE_PORT + 1 ); + char port = (char)(MsgFixture.ADDRESS_ATTRIBUTE_PORT + 1 ); target.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, port, Transport.UDP)); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, port, Transport.UDP)); addressAttribute.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); expectedReturn = false; @@ -429,8 +429,8 @@ public class AddressAttributeTest extends TestCase { //equality test target.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP )); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP )); expectedReturn = true; actualReturn = addressAttribute.equals(target); @@ -440,12 +440,12 @@ public class AddressAttributeTest extends TestCase { //ipv6 equality test target.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); addressAttribute.setAddress(new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); expectedReturn = true; @@ -457,7 +457,7 @@ public class AddressAttributeTest extends TestCase { /** * Tests whether data length is properly calculated. * - * @throws StunException java.lang.Exception if we fail + * @throws Exception java.lang.Exception if we fail */ public void testGetDataLength() throws Exception @@ -465,8 +465,8 @@ public class AddressAttributeTest extends TestCase { char expectedReturn = 8;//1-padding + 1-family + 2-port + 4-address addressAttribute.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); char actualReturn = addressAttribute.getDataLength(); @@ -476,8 +476,8 @@ public class AddressAttributeTest extends TestCase { expectedReturn = 20;//1-padding + 1-family + 2-port + 16-address addressAttribute.setAddress( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); actualReturn = addressAttribute.getDataLength(); @@ -487,14 +487,16 @@ public class AddressAttributeTest extends TestCase { /** * Tests that the address family is always 1. + * + * @throws Exception java.lang.Exception if we fail */ public void testGetFamily() throws Exception { byte expectedReturn = 1; addressAttribute.setAddress(new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); byte actualReturn = addressAttribute.getFamily(); assertEquals("Address family was not 1 for an IPv4", expectedReturn, actualReturn); @@ -502,8 +504,8 @@ public class AddressAttributeTest extends TestCase { //ipv6 expectedReturn = 2; addressAttribute.setAddress(new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, - msgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_V6, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); actualReturn = addressAttribute.getFamily(); assertEquals("Address family was not 2 for an IPv6 address", expectedReturn, actualReturn); diff --git a/test/org/ice4j/attribute/AttributeDecoderTest.java b/test/org/ice4j/attribute/AttributeDecoderTest.java index e1b18af..6d107dc 100644 --- a/test/org/ice4j/attribute/AttributeDecoderTest.java +++ b/test/org/ice4j/attribute/AttributeDecoderTest.java @@ -14,15 +14,18 @@ import junit.framework.*; * We have already tested individual decode methods, so our job here * is to verify that that AttributeDecoder.decode distributes the right way. */ -public class AttributeDecoderTest extends TestCase { +public class AttributeDecoderTest extends TestCase +{ private MsgFixture msgFixture; private byte[] expectedAttributeValue = null; - public AttributeDecoderTest(String name) { + public AttributeDecoderTest(String name) + { super(name); } - protected void setUp() throws Exception { + protected void setUp() throws Exception + { super.setUp(); msgFixture = new MsgFixture(); @@ -38,7 +41,8 @@ public class AttributeDecoderTest extends TestCase { msgFixture.setUp(); } - protected void tearDown() throws Exception { + protected void tearDown() throws Exception + { msgFixture.tearDown(); msgFixture = null; diff --git a/test/org/ice4j/attribute/ChangeRequestAttributeTest.java b/test/org/ice4j/attribute/ChangeRequestAttributeTest.java index f53760b..d9762dd 100644 --- a/test/org/ice4j/attribute/ChangeRequestAttributeTest.java +++ b/test/org/ice4j/attribute/ChangeRequestAttributeTest.java @@ -12,15 +12,23 @@ import java.util.Arrays; import org.ice4j.*; -public class ChangeRequestAttributeTest extends TestCase { +/** + * Tests the CHANGE-REQUEST attribute class. + * + * @author Emil Ivov + */ +public class ChangeRequestAttributeTest extends TestCase +{ private ChangeRequestAttribute changeRequestAttribute = null; private MsgFixture binMessagesFixture; - public ChangeRequestAttributeTest(String name) { + public ChangeRequestAttributeTest(String name) + { super(name); } - protected void setUp() throws Exception { + protected void setUp() throws Exception + { super.setUp(); changeRequestAttribute = new ChangeRequestAttribute(); binMessagesFixture = new MsgFixture(); @@ -28,7 +36,8 @@ public class ChangeRequestAttributeTest extends TestCase { binMessagesFixture.setUp(); } - protected void tearDown() throws Exception { + protected void tearDown() throws Exception + { changeRequestAttribute = null; binMessagesFixture.tearDown(); @@ -39,7 +48,8 @@ public class ChangeRequestAttributeTest extends TestCase { /** * Test whether the constructed object has the proper type. */ - public void testChangeRequestAttribute() { + public void testChangeRequestAttribute() + { changeRequestAttribute = new ChangeRequestAttribute(); assertEquals( @@ -64,11 +74,11 @@ public class ChangeRequestAttributeTest extends TestCase { changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length); assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag", - binMessagesFixture.CHANGE_IP_FLAG_1, + MsgFixture.CHANGE_IP_FLAG_1, changeRequestAttribute.getChangeIpFlag() ); assertEquals("decodeAttributeBody() did not properly decode the changePortFlag", - binMessagesFixture.CHANGE_PORT_FLAG_1, + MsgFixture.CHANGE_PORT_FLAG_1, changeRequestAttribute.getChangePortFlag() ); @@ -76,11 +86,11 @@ public class ChangeRequestAttributeTest extends TestCase { attributeValue = binMessagesFixture.chngReqTestValue2; changeRequestAttribute.decodeAttributeBody(attributeValue, offset, length); assertEquals("decodeAttributeBody() did not properly decode the changeIpFlag", - binMessagesFixture.CHANGE_IP_FLAG_2, + MsgFixture.CHANGE_IP_FLAG_2, changeRequestAttribute.getChangeIpFlag() ); assertEquals("decodeAttributeBody() did not properly decode the changePortFlag", - binMessagesFixture.CHANGE_PORT_FLAG_2, + MsgFixture.CHANGE_PORT_FLAG_2, changeRequestAttribute.getChangePortFlag() ); @@ -91,13 +101,14 @@ public class ChangeRequestAttributeTest extends TestCase { /** * Create sample objects and test whether they encode properly. */ - public void testEncode() { + public void testEncode() + { byte[] expectedReturn = binMessagesFixture.chngReqTestValue1; changeRequestAttribute = new ChangeRequestAttribute(); - changeRequestAttribute.setChangeIpFlag(binMessagesFixture.CHANGE_IP_FLAG_1); - changeRequestAttribute.setChangePortFlag(binMessagesFixture.CHANGE_PORT_FLAG_1); + changeRequestAttribute.setChangeIpFlag(MsgFixture.CHANGE_IP_FLAG_1); + changeRequestAttribute.setChangePortFlag(MsgFixture.CHANGE_PORT_FLAG_1); byte[] actualReturn = changeRequestAttribute.encode(); assertTrue("Object did not encode properly.", @@ -107,8 +118,8 @@ public class ChangeRequestAttributeTest extends TestCase { expectedReturn = binMessagesFixture.chngReqTestValue2; changeRequestAttribute = new ChangeRequestAttribute(); - changeRequestAttribute.setChangeIpFlag(binMessagesFixture.CHANGE_IP_FLAG_2); - changeRequestAttribute.setChangePortFlag(binMessagesFixture.CHANGE_PORT_FLAG_2); + changeRequestAttribute.setChangeIpFlag(MsgFixture.CHANGE_IP_FLAG_2); + changeRequestAttribute.setChangePortFlag(MsgFixture.CHANGE_PORT_FLAG_2); actualReturn = changeRequestAttribute.encode(); assertTrue("Object did not encode properly.", @@ -121,7 +132,8 @@ public class ChangeRequestAttributeTest extends TestCase { * Tests the equals method against a null, a different and an identical * object. */ - public void testEquals() { + public void testEquals() + { ChangeRequestAttribute target = null; boolean expectedReturn = false; @@ -161,7 +173,8 @@ public class ChangeRequestAttributeTest extends TestCase { /** * Test whether the returned value is always 4. */ - public void testGetDataLength() { + public void testGetDataLength() + { char expectedReturn = 4; // constant 4 bytes of data char actualReturn = changeRequestAttribute.getDataLength(); assertEquals("data length returned an invalid value", @@ -171,7 +184,8 @@ public class ChangeRequestAttributeTest extends TestCase { /** * Test whether we get a relevant name. */ - public void testGetName() { + public void testGetName() + { String expectedReturn = "CHANGE-REQUEST"; String actualReturn = changeRequestAttribute.getName(); assertEquals("Invalid name", expectedReturn, actualReturn); diff --git a/test/org/ice4j/attribute/ErrorCodeAttributeTest.java b/test/org/ice4j/attribute/ErrorCodeAttributeTest.java index 47f057e..bf7a6f1 100644 --- a/test/org/ice4j/attribute/ErrorCodeAttributeTest.java +++ b/test/org/ice4j/attribute/ErrorCodeAttributeTest.java @@ -66,15 +66,15 @@ public class ErrorCodeAttributeTest extends TestCase { errorCodeAttribute.decodeAttributeBody(attributeValue, offset, length); assertEquals("Error Class was not correctly decoded", - msgFixture.ERROR_CLASS, + MsgFixture.ERROR_CLASS, errorCodeAttribute.getErrorClass()); assertEquals("Error Number was not correctly decoded", - msgFixture.ERROR_NUMBER, + MsgFixture.ERROR_NUMBER, errorCodeAttribute.getErrorNumber()); assertEquals("Reason phrase was not correctly decoded", - msgFixture.REASON_PHRASE.trim(), + MsgFixture.REASON_PHRASE.trim(), errorCodeAttribute.getReasonPhrase().trim()); } @@ -90,10 +90,10 @@ public class ErrorCodeAttributeTest extends TestCase { { byte[] expectedReturn = msgFixture.errCodeTestValue; - errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); - errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); + errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS); + errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER); - errorCodeAttribute.setReasonPhrase(msgFixture.REASON_PHRASE); + errorCodeAttribute.setReasonPhrase(MsgFixture.REASON_PHRASE); byte[] actualReturn = errorCodeAttribute.encode(); @@ -122,11 +122,11 @@ public class ErrorCodeAttributeTest extends TestCase { target = new ErrorCodeAttribute(); expectedReturn = false; - target.setErrorClass(msgFixture.ERROR_CLASS); - target.setErrorNumber(msgFixture.ERROR_NUMBER); + target.setErrorClass(MsgFixture.ERROR_CLASS); + target.setErrorNumber(MsgFixture.ERROR_NUMBER); - errorCodeAttribute.setErrorClass((byte)(msgFixture.ERROR_CLASS+1)); - errorCodeAttribute.setErrorNumber((byte)(msgFixture.ERROR_NUMBER+1)); + errorCodeAttribute.setErrorClass((byte)(MsgFixture.ERROR_CLASS+1)); + errorCodeAttribute.setErrorNumber((byte)(MsgFixture.ERROR_NUMBER+1)); actualReturn = errorCodeAttribute.equals(target); assertEquals("equals() failed against a not equal target.", @@ -137,11 +137,11 @@ public class ErrorCodeAttributeTest extends TestCase { errorCodeAttribute = new ErrorCodeAttribute(); expectedReturn = true; - target.setErrorClass(msgFixture.ERROR_CLASS); - target.setErrorNumber(msgFixture.ERROR_NUMBER); + target.setErrorClass(MsgFixture.ERROR_CLASS); + target.setErrorNumber(MsgFixture.ERROR_NUMBER); - errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); - errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); + errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS); + errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER); actualReturn = errorCodeAttribute.equals(target); assertEquals("equals() failed against a not equal target.", @@ -158,12 +158,12 @@ public class ErrorCodeAttributeTest extends TestCase { public void testGetDataLength() throws StunException { - int expectedReturn = msgFixture.REASON_PHRASE.getBytes().length + int expectedReturn = MsgFixture.REASON_PHRASE.getBytes().length + 4; //error code specific header - errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); - errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); - errorCodeAttribute.setReasonPhrase(msgFixture.REASON_PHRASE); + errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS); + errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER); + errorCodeAttribute.setReasonPhrase(MsgFixture.REASON_PHRASE); char actualReturn = errorCodeAttribute.getDataLength(); assertEquals("data length1", expectedReturn, actualReturn); @@ -177,11 +177,11 @@ public class ErrorCodeAttributeTest extends TestCase { public void testGetErrorCode() throws StunException { - char expectedReturn = (char)(100*msgFixture.ERROR_CLASS - + msgFixture.ERROR_NUMBER); + char expectedReturn = (char)(100*MsgFixture.ERROR_CLASS + + MsgFixture.ERROR_NUMBER); - errorCodeAttribute.setErrorClass(msgFixture.ERROR_CLASS); - errorCodeAttribute.setErrorNumber(msgFixture.ERROR_NUMBER); + errorCodeAttribute.setErrorClass(MsgFixture.ERROR_CLASS); + errorCodeAttribute.setErrorNumber(MsgFixture.ERROR_NUMBER); char actualReturn = errorCodeAttribute.getErrorCode(); assertEquals("return value", expectedReturn, actualReturn); @@ -203,14 +203,14 @@ public class ErrorCodeAttributeTest extends TestCase { * @throws StunException java.lang.Exception if we fail */ public void testSetErrorCode() throws StunException { - char errorCode = (char)(msgFixture.ERROR_CLASS*100 + msgFixture.ERROR_NUMBER); + char errorCode = (char)(MsgFixture.ERROR_CLASS*100 + MsgFixture.ERROR_NUMBER); errorCodeAttribute.setErrorCode(errorCode); assertEquals("An error class was not properly set after decoding an error code.", - (int)msgFixture.ERROR_CLASS, + (int)MsgFixture.ERROR_CLASS, (int)errorCodeAttribute.getErrorClass()); assertEquals("An error number was not properly set after decoding an error code.", - (int)msgFixture.ERROR_NUMBER, + (int)MsgFixture.ERROR_NUMBER, (int)errorCodeAttribute.getErrorNumber()); } diff --git a/test/org/ice4j/attribute/OptionalAttributeAttributeTest.java b/test/org/ice4j/attribute/OptionalAttributeAttributeTest.java index db8906f..be4a31f 100644 --- a/test/org/ice4j/attribute/OptionalAttributeAttributeTest.java +++ b/test/org/ice4j/attribute/OptionalAttributeAttributeTest.java @@ -47,8 +47,6 @@ public class OptionalAttributeAttributeTest extends TestCase super.tearDown(); } - - /** * Test whether sample binary arrays are correctly decoded. * @throws StunException if anything goes wrong. diff --git a/test/org/ice4j/attribute/SoftwareAttributeTest.java b/test/org/ice4j/attribute/SoftwareAttributeTest.java index 49f5988..85b0d76 100644 --- a/test/org/ice4j/attribute/SoftwareAttributeTest.java +++ b/test/org/ice4j/attribute/SoftwareAttributeTest.java @@ -26,7 +26,8 @@ public class SoftwareAttributeTest extends TestCase (byte)(SoftwareAttribute.SOFTWARE>>8), (byte)(SoftwareAttribute.SOFTWARE & 0x00FF), 0, (byte)softwareValue.length(), - 't', 'u', 'r', 'n', 's', 'e', 'r','v', 'e', 'r', '.', 'o', 'r', 'g', 0x00, 0x00}; + 't', 'u', 'r', 'n', 's', 'e', 'r','v', 'e', 'r', '.', 'o', 'r', 'g', + 0x00, 0x00}; protected void setUp() throws Exception { diff --git a/test/org/ice4j/attribute/UnknownAttributesAttributeTest.java b/test/org/ice4j/attribute/UnknownAttributesAttributeTest.java index dfefa46..32c8abc 100644 --- a/test/org/ice4j/attribute/UnknownAttributesAttributeTest.java +++ b/test/org/ice4j/attribute/UnknownAttributesAttributeTest.java @@ -12,15 +12,23 @@ import java.util.*; import org.ice4j.*; -public class UnknownAttributesAttributeTest extends TestCase { +/** + * Tests the UNKNOWN attribute class. + * + * @author Emil Ivov + */ +public class UnknownAttributesAttributeTest extends TestCase +{ private UnknownAttributesAttribute unknownAttributesAttribute = null; private MsgFixture binMessagesFixture; - public UnknownAttributesAttributeTest(String name) { + public UnknownAttributesAttributeTest(String name) + { super(name); } - protected void setUp() throws Exception { + protected void setUp() throws Exception + { super.setUp(); unknownAttributesAttribute = new UnknownAttributesAttribute(); binMessagesFixture = new MsgFixture(); @@ -28,7 +36,8 @@ public class UnknownAttributesAttributeTest extends TestCase { binMessagesFixture.setUp(); } - protected void tearDown() throws Exception { + protected void tearDown() throws Exception + { unknownAttributesAttribute = null; binMessagesFixture.tearDown(); @@ -40,7 +49,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Verify the the constructed object has the correct (UNKNOWN-ATTRIBUTES) * type. */ - public void testUnknownAttributesAttribute() { + public void testUnknownAttributesAttribute() + { unknownAttributesAttribute = new UnknownAttributesAttribute(); assertEquals("UnknownAttributesAttribute() did not properly set the " @@ -55,7 +65,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * and that a second addition of the same id would not augment the attribute * count. */ - public void testAddAttributeID() { + public void testAddAttributeID() + { char attributeID = 0x22; // unknown attribute id unknownAttributesAttribute.addAttributeID(attributeID); @@ -85,7 +96,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Tests whether a sample binary array is properly decoded. * @throws StunException if anything goes wrong. */ - public void testDecodeAttributeBody() throws StunException { + public void testDecodeAttributeBody() throws StunException + { //a copy of the array in the fixture: byte[] attributeValue = binMessagesFixture.unknownAttsDecodeTestValue; @@ -126,7 +138,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Creates a new UnknownAttributesAttribute encodes it and assert equality * with binMessagesFixture.unknownAttsEncodeExpectedResult. */ - public void testEncode() { + public void testEncode() + { byte[] expectedReturn = binMessagesFixture.unknownAttsEncodeExpectedResult; unknownAttributesAttribute.addAttributeID( @@ -145,7 +158,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Tests the equals method against a null, a different and an identical * object. */ - public void testEquals() { + public void testEquals() + { UnknownAttributesAttribute target = new UnknownAttributesAttribute(); boolean expectedReturn = false; @@ -173,7 +187,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Tests that getAttribute() return the correct attribute id, preserving * entry order. */ - public void testGetAttribute() { + public void testGetAttribute() + { char expectedId1 = 20; char expectedId2 = 21; @@ -194,7 +209,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Add some attributes and test whether their number is properly calculated. * Tests duplicate id handling as well. */ - public void testGetAttributeCount() { + public void testGetAttributeCount() + { int expectedReturn = 5; unknownAttributesAttribute.addAttributeID((char)21); @@ -213,7 +229,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Same as testGetAttributeID, only attribute attributes are extracted * through the getAttributes()'s iterator. */ - public void testGetAttributes() { + public void testGetAttributes() + { char expectedId1 = 20; char expectedId2 = 21; @@ -239,7 +256,8 @@ public class UnknownAttributesAttributeTest extends TestCase { * Test is first performed for an odd number of attributes and then again * (after adding another attribute id). Both results should be the same. */ - public void testGetDataLength() { + public void testGetDataLength() + { char expectedReturn = 8; unknownAttributesAttribute.addAttributeID((char)20); @@ -261,7 +279,8 @@ public class UnknownAttributesAttributeTest extends TestCase { /** * Tests whether getName returns a relevant name. */ - public void testGetName() { + public void testGetName() + { String expectedReturn = "UNKNOWN-ATTRIBUTES"; String actualReturn = unknownAttributesAttribute.getName(); assertEquals("getName() return", expectedReturn, actualReturn); diff --git a/test/org/ice4j/message/MessageFactoryTest.java b/test/org/ice4j/message/MessageFactoryTest.java index fc7059c..8bfeb18 100644 --- a/test/org/ice4j/message/MessageFactoryTest.java +++ b/test/org/ice4j/message/MessageFactoryTest.java @@ -11,31 +11,33 @@ import junit.framework.*; import org.ice4j.*; import org.ice4j.attribute.*; -public class MessageFactoryTest extends TestCase { - private MessageFactory messageFactory = null; +public class MessageFactoryTest extends TestCase +{ private MsgFixture msgFixture; - public MessageFactoryTest(String name) { + public MessageFactoryTest(String name) + { super(name); } - protected void setUp() throws Exception { + protected void setUp() throws Exception + { super.setUp(); - messageFactory = new MessageFactory(); msgFixture = new MsgFixture(); msgFixture.setUp(); } - protected void tearDown() throws Exception { - messageFactory = null; + protected void tearDown() throws Exception + { msgFixture.tearDown(); msgFixture = null; super.tearDown(); } - public void testCreateBindingErrorResponse() throws StunException { + public void testCreateBindingErrorResponse() throws StunException + { char errorCode = 400; Response expectedReturn = new Response(); @@ -46,11 +48,12 @@ public class MessageFactoryTest extends TestCase { expectedReturn.addAttribute(errorCodeAtt); Message actualReturn - = messageFactory.createBindingErrorResponse(errorCode); + = MessageFactory.createBindingErrorResponse(errorCode); assertEquals("return value", expectedReturn, actualReturn); } - public void testCreateBindingErrorResponse1() throws StunException { + public void testCreateBindingErrorResponse1() throws StunException + { char errorCode = 400; String reasonPhrase = "Bad Request"; @@ -61,7 +64,7 @@ public class MessageFactoryTest extends TestCase { .createErrorCodeAttribute(errorCode, reasonPhrase); expectedReturn.addAttribute(errorCodeAtt); - Message actualReturn = messageFactory + Message actualReturn = MessageFactory .createBindingErrorResponse(errorCode, reasonPhrase); assertEquals("Failed to create an error code attribute.", expectedReturn, actualReturn); @@ -92,7 +95,7 @@ public class MessageFactoryTest extends TestCase { expectedReturn.addAttribute(unknownAtts); //create the same message using the factory - Message actualReturn = messageFactory + Message actualReturn = MessageFactory .createBindingErrorResponseUnknownAttributes(unknownAttributes); //compare assertEquals("return value", expectedReturn, actualReturn); @@ -121,7 +124,7 @@ public class MessageFactoryTest extends TestCase { } expectedReturn.addAttribute(unknownAtts); - Message actualReturn = messageFactory + Message actualReturn = MessageFactory .createBindingErrorResponseUnknownAttributes( reasonPhrase, unknownAttributes); assertEquals("return value", expectedReturn, actualReturn); @@ -137,7 +140,7 @@ public class MessageFactoryTest extends TestCase { msgFixture.CHANGE_IP_FLAG_1, msgFixture.CHANGE_PORT_FLAG_1); bindingRequest.addAttribute(changeRequest); */ - Request actualReturn = messageFactory.createBindingRequest(); + Request actualReturn = MessageFactory.createBindingRequest(); assertEquals("return value", expectedReturn, actualReturn); } @@ -148,37 +151,37 @@ public class MessageFactoryTest extends TestCase { bindingResponse.setMessageType(Message.BINDING_SUCCESS_RESPONSE); Attribute mappedAddress = AttributeFactory.createMappedAddressAttribute( - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); bindingResponse.addAttribute(mappedAddress); Attribute sourceAddress = AttributeFactory.createSourceAddressAttribute( - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, - msgFixture.ADDRESS_ATTRIBUTE_PORT_2, + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_2, Transport.UDP)); bindingResponse.addAttribute(sourceAddress); Attribute changedAddress = AttributeFactory. createChangedAddressAttribute( - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, - msgFixture.ADDRESS_ATTRIBUTE_PORT_3, + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP)); bindingResponse.addAttribute(changedAddress); Message expectedReturn = bindingResponse; - Message actualReturn = messageFactory.create3482BindingResponse( - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + Message actualReturn = MessageFactory.create3482BindingResponse( + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP), - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, - msgFixture.ADDRESS_ATTRIBUTE_PORT_2, + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_2, Transport.UDP), - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, - msgFixture.ADDRESS_ATTRIBUTE_PORT_3, + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP)); assertEquals("return value", expectedReturn, actualReturn); } diff --git a/test/org/ice4j/message/MessageTest.java b/test/org/ice4j/message/MessageTest.java index 6b03902..93009e7 100644 --- a/test/org/ice4j/message/MessageTest.java +++ b/test/org/ice4j/message/MessageTest.java @@ -14,7 +14,8 @@ import org.ice4j.*; import org.ice4j.attribute.*; import org.ice4j.stack.*; -public class MessageTest extends TestCase { +public class MessageTest extends TestCase +{ private Message bindingRequest = null; private Message bindingResponse = null; @@ -31,7 +32,8 @@ public class MessageTest extends TestCase { */ private StunStack stunStack; - protected void setUp() throws Exception { + protected void setUp() throws Exception + { super.setUp(); msgFixture = new MsgFixture(); @@ -44,9 +46,9 @@ public class MessageTest extends TestCase { bindingRequest.setMessageType(Message.BINDING_REQUEST); changeRequest = AttributeFactory.createChangeRequestAttribute( - msgFixture.CHANGE_IP_FLAG_1, msgFixture.CHANGE_PORT_FLAG_1); + MsgFixture.CHANGE_IP_FLAG_1, MsgFixture.CHANGE_PORT_FLAG_1); bindingRequest.addAttribute(changeRequest); - bindingRequest.setTransactionID(msgFixture.TRANSACTION_ID); + bindingRequest.setTransactionID(MsgFixture.TRANSACTION_ID); //binding response bindingResponse = new Response(); @@ -54,26 +56,26 @@ public class MessageTest extends TestCase { mappedAddress = AttributeFactory.createMappedAddressAttribute( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS, - msgFixture.ADDRESS_ATTRIBUTE_PORT, + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS, + MsgFixture.ADDRESS_ATTRIBUTE_PORT, Transport.UDP)); bindingResponse.addAttribute(mappedAddress); sourceAddress = AttributeFactory.createSourceAddressAttribute( new TransportAddress( - msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, - msgFixture.ADDRESS_ATTRIBUTE_PORT_2, + MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_2, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_2, Transport.UDP)); bindingResponse.addAttribute(sourceAddress); changedAddress = AttributeFactory.createChangedAddressAttribute( - new TransportAddress( msgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, - msgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP)); + new TransportAddress( MsgFixture.ADDRESS_ATTRIBUTE_ADDRESS_3, + MsgFixture.ADDRESS_ATTRIBUTE_PORT_3, Transport.UDP)); bindingResponse.addAttribute(changedAddress); - bindingResponse.setTransactionID(msgFixture.TRANSACTION_ID); + bindingResponse.setTransactionID(MsgFixture.TRANSACTION_ID); } protected void tearDown() throws Exception @@ -101,8 +103,8 @@ public class MessageTest extends TestCase { * * @throws StunException java.lang.Exception if we fail */ - - public void testAddAndGetAttribute() throws StunException { + public void testAddAndGetAttribute() throws StunException + { Response message = new Response(); message.setMessageType(Message.BINDING_SUCCESS_RESPONSE); @@ -157,7 +159,7 @@ public class MessageTest extends TestCase { * Encodes a bindingRequest and then a binding response and checks whether * they match the corresponding binary arrays. * - * @throws StunException java.lang.Exception if we fail + * @throws Exception java.lang.Exception if we fail */ public void testDecode() throws Exception @@ -238,7 +240,8 @@ public class MessageTest extends TestCase { /** * Tests whether attributes are properly counted */ - public void testGetAttributeCount() { + public void testGetAttributeCount() + { int expectedReturn = 1; int actualReturn = bindingRequest.getAttributeCount(); assertEquals("getAttributeCount failed for a bindingRequest", @@ -252,7 +255,8 @@ public class MessageTest extends TestCase { /** * Test whether attributes are properly removed. */ - public void testRemoveAttribute() { + public void testRemoveAttribute() + { bindingRequest.removeAttribute(changeRequest.getAttributeType()); diff --git a/test/org/ice4j/stunclient/StunAddressDiscovererTest.java b/test/org/ice4j/stunclient/StunAddressDiscovererTest.java index 061609b..5167e21 100644 --- a/test/org/ice4j/stunclient/StunAddressDiscovererTest.java +++ b/test/org/ice4j/stunclient/StunAddressDiscovererTest.java @@ -230,7 +230,6 @@ public class StunAddressDiscovererTest assertEquals( "The StunAddressDiscoverer failed for a no-udp environment.", expectedReturn, actualReturn); - } /** diff --git a/test/org/ice4j/stunclient/StunAddressDiscovererTest_v4v6.java b/test/org/ice4j/stunclient/StunAddressDiscovererTest_v4v6.java index a57150f..ff9201a 100644 --- a/test/org/ice4j/stunclient/StunAddressDiscovererTest_v4v6.java +++ b/test/org/ice4j/stunclient/StunAddressDiscovererTest_v4v6.java @@ -27,7 +27,8 @@ import org.ice4j.stack.*; *

Company: Net Research Team, Louis Pasteur University

* @author Emil Ivov */ -public class StunAddressDiscovererTest_v4v6 extends TestCase { +public class StunAddressDiscovererTest_v4v6 extends TestCase +{ private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v6 = null; private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer_v4 diff --git a/test/org/ice4j/stunclient/StunAddressDiscovererTest_v6.java b/test/org/ice4j/stunclient/StunAddressDiscovererTest_v6.java index 7c1f392..c57d53a 100644 --- a/test/org/ice4j/stunclient/StunAddressDiscovererTest_v6.java +++ b/test/org/ice4j/stunclient/StunAddressDiscovererTest_v6.java @@ -22,7 +22,8 @@ import org.ice4j.stack.*; *

Company: Net Research Team, Louis Pasteur University

* @author Emil Ivov */ -public class StunAddressDiscovererTest_v6 extends TestCase { +public class StunAddressDiscovererTest_v6 extends TestCase +{ private NetworkConfigurationDiscoveryProcess stunAddressDiscoverer = null; private TransportAddress discovererAddress = new TransportAddress("::1", 16555, Transport.UDP); @@ -290,9 +291,4 @@ public class StunAddressDiscovererTest_v6 extends TestCase { expectedReturn, actualReturn); } - - - - - }