Skip to content

Commit 0924bac

Browse files
committed
Initial commit for Draft_6455 tests
1 parent 2f0d694 commit 0924bac

6 files changed

Lines changed: 266 additions & 2 deletions

File tree

src/main/java/org/java_websocket/drafts/Draft_6455.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public Draft_6455( List<IExtension> inputExtensions ) {
121121
* @param inputProtocols the protocols which should be used for this draft
122122
*/
123123
public Draft_6455( List<IExtension> inputExtensions , List<IProtocol> inputProtocols ) {
124+
if (inputExtensions == null || inputProtocols == null) {
125+
throw new IllegalArgumentException();
126+
}
124127
knownExtensions = new ArrayList<IExtension>( inputExtensions.size());
125128
knownProtocols = new ArrayList<IProtocol>( inputProtocols.size());
126129
boolean hasDefault = false;
@@ -131,11 +134,11 @@ public Draft_6455( List<IExtension> inputExtensions , List<IProtocol> inputProto
131134
}
132135
}
133136
knownExtensions.addAll( inputExtensions );
134-
knownProtocols.addAll( inputProtocols );
135137
//We always add the DefaultExtension to implement the normal RFC 6455 specification
136138
if( !hasDefault ) {
137139
knownExtensions.add( this.knownExtensions.size(), extension );
138140
}
141+
knownProtocols.addAll( inputProtocols );
139142
}
140143

141144
@Override

src/main/java/org/java_websocket/protocols/Protocol.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public String toString() {
7878
public boolean equals( Object o ) {
7979
if( this == o ) return true;
8080
if( o == null || getClass() != o.getClass() ) return false;
81+
8182
Protocol protocol = ( Protocol ) o;
83+
8284
return providedProtocol.equals( protocol.providedProtocol );
8385
}
8486

src/test/java/org/java_websocket/AllTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
@RunWith(Suite.class)
3333
@Suite.SuiteClasses({
3434
org.java_websocket.util.ByteBufferUtilsTest.class,
35+
org.java_websocket.drafts.AllDraftTests.class,
3536
org.java_websocket.misc.AllMiscTests.class,
3637
org.java_websocket.protocols.AllProtocolTests.class,
3738
org.java_websocket.framing.AllFramingTests.class
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.drafts;
27+
import org.junit.runner.RunWith;
28+
import org.junit.runners.Suite;
29+
30+
31+
@RunWith(Suite.class)
32+
@Suite.SuiteClasses({
33+
org.java_websocket.drafts.Draft_6455Test.class
34+
})
35+
/**
36+
* Start all tests for drafts
37+
*/
38+
public class AllDraftTests {
39+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*
2+
* Copyright (c) 2010-2017 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
package org.java_websocket.drafts;
27+
28+
import org.java_websocket.extensions.DefaultExtension;
29+
import org.java_websocket.extensions.IExtension;
30+
import org.java_websocket.handshake.HandshakeImpl1Client;
31+
import org.java_websocket.protocols.IProtocol;
32+
import org.java_websocket.protocols.Protocol;
33+
import org.junit.Test;
34+
35+
import java.util.Collections;
36+
37+
import static org.junit.Assert.*;
38+
39+
public class Draft_6455Test {
40+
41+
HandshakeImpl1Client handshakedataProtocolExtension;
42+
HandshakeImpl1Client handshakedataProtocol;
43+
HandshakeImpl1Client handshakedataExtension;
44+
HandshakeImpl1Client handshakedata;
45+
46+
public Draft_6455Test() {
47+
handshakedataProtocolExtension = new HandshakeImpl1Client();
48+
handshakedataProtocolExtension.put( "Upgrade", "websocket" );
49+
handshakedataProtocolExtension.put( "Connection", "Upgrade" );
50+
handshakedataProtocolExtension.put( "Sec-WebSocket-Version", "13" );
51+
handshakedataProtocolExtension.put( "Sec-WebSocket-Extension", "permessage-deflate" );
52+
handshakedataProtocolExtension.put( "Sec-WebSocket-Protocol", "chat, test" );
53+
handshakedataProtocol = new HandshakeImpl1Client();
54+
handshakedataProtocol.put( "Upgrade", "websocket" );
55+
handshakedataProtocol.put( "Connection", "Upgrade" );
56+
handshakedataProtocol.put( "Sec-WebSocket-Version", "13" );
57+
handshakedataProtocol.put( "Sec-WebSocket-Protocol", "chat, test" );
58+
handshakedataExtension = new HandshakeImpl1Client();
59+
handshakedataExtension.put( "Upgrade", "websocket" );
60+
handshakedataExtension.put( "Connection", "Upgrade" );
61+
handshakedataExtension.put( "Sec-WebSocket-Version", "13" );
62+
handshakedataExtension.put( "Sec-WebSocket-Extension", "permessage-deflate" );
63+
handshakedata = new HandshakeImpl1Client();
64+
handshakedata.put( "Upgrade", "websocket" );
65+
handshakedata.put( "Connection", "Upgrade" );
66+
handshakedata.put( "Sec-WebSocket-Version", "13" );
67+
}
68+
69+
@Test
70+
public void testConstructor() throws Exception {
71+
try {
72+
Draft_6455 draft_6455 = new Draft_6455( null, null );
73+
fail( "IllegalArgumentException expected" );
74+
} catch ( IllegalArgumentException e ) {
75+
//Fine
76+
}
77+
try {
78+
Draft_6455 draft_6455 = new Draft_6455( Collections.<IExtension>emptyList(), null );
79+
fail( "IllegalArgumentException expected" );
80+
} catch ( IllegalArgumentException e ) {
81+
//Fine
82+
}
83+
try {
84+
Draft_6455 draft_6455 = new Draft_6455( null, Collections.<IProtocol>emptyList() );
85+
fail( "IllegalArgumentException expected" );
86+
} catch ( IllegalArgumentException e ) {
87+
//Fine
88+
}
89+
Draft_6455 draft_6455 = new Draft_6455( Collections.<IExtension>emptyList(), Collections.<IProtocol>emptyList() );
90+
assertEquals( draft_6455.getKnownExtensions().size(), 1 );
91+
assertEquals( draft_6455.getKnownProtocols().size(), 0 );
92+
}
93+
94+
@Test
95+
public void testGetExtension() throws Exception {
96+
Draft_6455 draft_6455 = new Draft_6455();
97+
assertNotNull( draft_6455.getExtension() );
98+
assert ( draft_6455.getExtension() instanceof DefaultExtension );
99+
}
100+
101+
@Test
102+
public void testGetKnownExtensions() throws Exception {
103+
//Wird automatisch default hinzugefügt?
104+
//TODO
105+
}
106+
107+
@Test
108+
public void testGetProtocol() throws Exception {
109+
Draft_6455 draft_6455 = new Draft_6455();
110+
assertNull( draft_6455.getProtocol() );
111+
//TODO
112+
}
113+
114+
@Test
115+
public void testGetKnownProtocols() throws Exception {
116+
}
117+
118+
@Test
119+
public void testCopyInstance() throws Exception {
120+
}
121+
122+
@Test
123+
public void testReset() throws Exception {
124+
}
125+
126+
@Test
127+
public void testGetCloseHandshakeType() throws Exception {
128+
Draft_6455 draft_6455 = new Draft_6455();
129+
assertEquals( draft_6455.getCloseHandshakeType(), Draft.CloseHandshakeType.TWOWAY );
130+
}
131+
132+
@Test
133+
public void testToString() throws Exception {
134+
}
135+
136+
@Test
137+
public void testEquals() throws Exception {
138+
Draft draft0 = new Draft_6455();
139+
Draft draft1 = draft0.copyInstance();
140+
assertEquals( draft0, draft1 );
141+
Draft draft2 = new Draft_6455( Collections.<IExtension>emptyList(), Collections.<IProtocol>singletonList( new Protocol( "chat" ) ) );
142+
Draft draft3 = draft2.copyInstance();
143+
assertEquals( draft2, draft3 );
144+
assertEquals( draft0, draft2 );
145+
//unequal for draft2 due to a provided protocol
146+
draft2.acceptHandshakeAsServer( handshakedataProtocolExtension );
147+
draft1.acceptHandshakeAsServer( handshakedataProtocolExtension );
148+
assertNotEquals( draft2, draft3 );
149+
assertNotEquals( draft0, draft2 );
150+
assertEquals( draft0, draft1 );
151+
draft2 = draft2.copyInstance();
152+
draft1 = draft1.copyInstance();
153+
//unequal for draft draft2 due to a provided protocol
154+
draft2.acceptHandshakeAsServer( handshakedataProtocol );
155+
draft1.acceptHandshakeAsServer( handshakedataProtocol );
156+
assertNotEquals( draft2, draft3 );
157+
assertNotEquals( draft0, draft2 );
158+
assertEquals( draft0, draft1 );
159+
draft2 = draft2.copyInstance();
160+
draft1 = draft1.copyInstance();
161+
//unequal for draft draft0 due to a provided protocol (no protocol)
162+
draft2.acceptHandshakeAsServer( handshakedataExtension );
163+
draft1.acceptHandshakeAsServer( handshakedataExtension );
164+
assertEquals( draft2, draft3 );
165+
assertEquals( draft0, draft2 );
166+
assertNotEquals( draft0, draft1 );
167+
draft2 = draft2.copyInstance();
168+
draft1 = draft1.copyInstance();
169+
//unequal for draft draft0 due to a provided protocol (no protocol)
170+
draft2.acceptHandshakeAsServer( handshakedata );
171+
draft1.acceptHandshakeAsServer( handshakedata );
172+
assertEquals( draft2, draft3 );
173+
assertEquals( draft0, draft2 );
174+
assertNotEquals( draft0, draft1 );
175+
}
176+
177+
@Test
178+
public void testHashCode() throws Exception {
179+
Draft draft0 = new Draft_6455();
180+
Draft draft1 = draft0.copyInstance();
181+
Draft draft2 = new Draft_6455( Collections.<IExtension>emptyList(), Collections.<IProtocol>singletonList( new Protocol( "chat" ) ) );
182+
Draft draft3 = draft2.copyInstance();
183+
assertEquals( draft2.hashCode(), draft3.hashCode() );
184+
assertEquals( draft0.hashCode(), draft2.hashCode() );
185+
assertEquals( draft0.hashCode(), draft1.hashCode() );
186+
//Hashcode changes for draft2 due to a provided protocol
187+
draft2.acceptHandshakeAsServer( handshakedataProtocolExtension );
188+
draft1.acceptHandshakeAsServer( handshakedataProtocolExtension );
189+
assertNotEquals( draft2.hashCode(), draft3.hashCode() );
190+
assertNotEquals( draft0.hashCode(), draft2.hashCode() );
191+
assertEquals( draft0.hashCode(), draft1.hashCode() );
192+
draft2 = draft2.copyInstance();
193+
draft1 = draft1.copyInstance();
194+
//Hashcode changes for draft draft2 due to a provided protocol
195+
draft2.acceptHandshakeAsServer( handshakedataProtocol );
196+
draft1.acceptHandshakeAsServer( handshakedataProtocol );
197+
assertNotEquals( draft2.hashCode(), draft3.hashCode() );
198+
assertNotEquals( draft0.hashCode(), draft2.hashCode() );
199+
assertEquals( draft0.hashCode(), draft1.hashCode() );
200+
draft2 = draft2.copyInstance();
201+
draft1 = draft1.copyInstance();
202+
//Hashcode changes for draft draft0 due to a provided protocol (no protocol)
203+
draft2.acceptHandshakeAsServer( handshakedataExtension );
204+
draft1.acceptHandshakeAsServer( handshakedataExtension );
205+
assertEquals( draft2.hashCode(), draft3.hashCode() );
206+
assertEquals( draft0.hashCode(), draft2.hashCode() );
207+
// THIS IS A DIFFERENCE BETWEEN equals and hashcode since the hashcode of an empty string = 0
208+
assertEquals( draft0.hashCode(), draft1.hashCode() );
209+
draft2 = draft2.copyInstance();
210+
draft1 = draft1.copyInstance();
211+
//Hashcode changes for draft draft0 due to a provided protocol (no protocol)
212+
draft2.acceptHandshakeAsServer( handshakedata );
213+
draft1.acceptHandshakeAsServer( handshakedata );
214+
assertEquals( draft2.hashCode(), draft3.hashCode() );
215+
assertEquals( draft0.hashCode(), draft2.hashCode() );
216+
// THIS IS A DIFFERENCE BETWEEN equals and hashcode since the hashcode of an empty string = 0
217+
assertEquals( draft0.hashCode(), draft1.hashCode() );
218+
}
219+
220+
}

src/test/java/org/java_websocket/protocols/ProtocolTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void testConstructor() throws Exception {
1515
} catch ( IllegalArgumentException e ) {
1616
//Fine
1717
}
18-
1918
}
2019

2120
@Test

0 commit comments

Comments
 (0)