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+ }
0 commit comments