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 .extensions ;
27+
28+ import org .java_websocket .framing .BinaryFrame ;
29+ import org .java_websocket .framing .TextFrame ;
30+ import org .junit .Test ;
31+
32+ import java .nio .ByteBuffer ;
33+
34+ import static org .junit .Assert .assertEquals ;
35+ import static org .junit .Assert .assertTrue ;
36+ import static org .junit .Assert .fail ;
37+
38+ public class DefaultExtensionTest {
39+ @ Test
40+ public void testDecodeFrame () throws Exception {
41+ DefaultExtension defaultExtension = new DefaultExtension ();
42+ BinaryFrame binaryFrame = new BinaryFrame ();
43+ binaryFrame .setPayload ( ByteBuffer .wrap ( "test" .getBytes () ) );
44+ defaultExtension .decodeFrame ( binaryFrame );
45+ assertEquals ( ByteBuffer .wrap ( "test" .getBytes () ), binaryFrame .getPayloadData () );
46+ }
47+
48+ @ Test
49+ public void testEncodeFrame () throws Exception {
50+ DefaultExtension defaultExtension = new DefaultExtension ();
51+ BinaryFrame binaryFrame = new BinaryFrame ();
52+ binaryFrame .setPayload ( ByteBuffer .wrap ( "test" .getBytes () ) );
53+ defaultExtension .encodeFrame ( binaryFrame );
54+ assertEquals ( ByteBuffer .wrap ( "test" .getBytes () ), binaryFrame .getPayloadData () );
55+ }
56+
57+ @ Test
58+ public void testAcceptProvidedExtensionAsServer () throws Exception {
59+ DefaultExtension defaultExtension = new DefaultExtension ();
60+ assertTrue ( defaultExtension .acceptProvidedExtensionAsServer ( "Test" ) );
61+ assertTrue ( defaultExtension .acceptProvidedExtensionAsServer ( "" ) );
62+ assertTrue ( defaultExtension .acceptProvidedExtensionAsServer ( "Test, ASDC, as, ad" ) );
63+ assertTrue ( defaultExtension .acceptProvidedExtensionAsServer ( "ASDC, as,ad" ) );
64+ assertTrue ( defaultExtension .acceptProvidedExtensionAsServer ( "permessage-deflate" ) );
65+ }
66+
67+ @ Test
68+ public void testAcceptProvidedExtensionAsClient () throws Exception {
69+ DefaultExtension defaultExtension = new DefaultExtension ();
70+ assertTrue ( defaultExtension .acceptProvidedExtensionAsClient ( "Test" ) );
71+ assertTrue ( defaultExtension .acceptProvidedExtensionAsClient ( "" ) );
72+ assertTrue ( defaultExtension .acceptProvidedExtensionAsClient ( "Test, ASDC, as, ad" ) );
73+ assertTrue ( defaultExtension .acceptProvidedExtensionAsClient ( "ASDC, as,ad" ) );
74+ assertTrue ( defaultExtension .acceptProvidedExtensionAsClient ( "permessage-deflate" ) );
75+ }
76+
77+ @ Test
78+ public void testIsFrameValid () throws Exception {
79+ DefaultExtension defaultExtension = new DefaultExtension ();
80+ TextFrame textFrame = new TextFrame ();
81+ try {
82+ defaultExtension .isFrameValid ( textFrame );
83+ } catch ( Exception e ) {
84+ fail ( "This frame is valid" );
85+ }
86+ textFrame .setRSV1 ( true );
87+ try {
88+ defaultExtension .isFrameValid ( textFrame );
89+ fail ( "This frame is not valid" );
90+ } catch ( Exception e ) {
91+ //
92+ }
93+ textFrame .setRSV1 ( false );
94+ textFrame .setRSV2 ( true );
95+ try {
96+ defaultExtension .isFrameValid ( textFrame );
97+ fail ( "This frame is not valid" );
98+ } catch ( Exception e ) {
99+ //
100+ }
101+ textFrame .setRSV2 ( false );
102+ textFrame .setRSV3 ( true );
103+ try {
104+ defaultExtension .isFrameValid ( textFrame );
105+ fail ( "This frame is not valid" );
106+ } catch ( Exception e ) {
107+ //
108+ }
109+ }
110+
111+ @ Test
112+ public void testGetProvidedExtensionAsClient () throws Exception {
113+ DefaultExtension defaultExtension = new DefaultExtension ();
114+ assertEquals ( "" , defaultExtension .getProvidedExtensionAsClient () );
115+ }
116+
117+ @ Test
118+ public void testGetProvidedExtensionAsServer () throws Exception {
119+ DefaultExtension defaultExtension = new DefaultExtension ();
120+ assertEquals ( "" , defaultExtension .getProvidedExtensionAsServer () );
121+ }
122+
123+ @ Test
124+ public void testCopyInstance () throws Exception {
125+ DefaultExtension defaultExtension = new DefaultExtension ();
126+ IExtension extensionCopy = defaultExtension .copyInstance ();
127+ assertEquals ( defaultExtension , extensionCopy );
128+ }
129+
130+ @ Test
131+ public void testToString () throws Exception {
132+ DefaultExtension defaultExtension = new DefaultExtension ();
133+ assertEquals ( "DefaultExtension" , defaultExtension .toString () );
134+ }
135+
136+ @ Test
137+ public void testHashCode () throws Exception {
138+ DefaultExtension defaultExtension0 = new DefaultExtension ();
139+ DefaultExtension defaultExtension1 = new DefaultExtension ();
140+ assertEquals ( defaultExtension0 .hashCode (), defaultExtension1 .hashCode () );
141+ }
142+
143+ @ Test
144+ public void testEquals () throws Exception {
145+ DefaultExtension defaultExtension0 = new DefaultExtension ();
146+ DefaultExtension defaultExtension1 = new DefaultExtension ();
147+ assertEquals ( defaultExtension0 , defaultExtension1 );
148+ }
149+
150+ }
0 commit comments