Address issue #50.
[stompngo.git] / suppress_test.go
blob146f22523f7c97585c13fe270637de56b2a23007
1 //
2 // Copyright © 2011-2019 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 package stompngo
19 import "testing"
21 var ()
24 Test suppress_content_length header.
26 func TestSuppressContentLength(t *testing.T) {
27 for _, sp := range Protocols() {
28 n, _ = openConn(t)
29 ch := login_headers
30 ch = headersProtocol(ch, sp)
31 conn, e = Connect(n, ch)
32 if e != nil {
33 t.Fatalf("TestSuppressContentLength CONNECT Failed: e:<%q> connresponse:<%q>\n",
35 conn.ConnectResponse)
38 d := tdest("/queue/suppress.content.length")
39 id := Uuid()
40 sbh := Headers{HK_DESTINATION, d, HK_ID, id}
41 sc, e = conn.Subscribe(sbh)
42 if e != nil {
43 t.Fatalf("TestSuppressContentLength Expected no subscribe error, got [%v]\n",
46 if sc == nil {
47 t.Fatalf("TestSuppressContentLength Expected subscribe channel, got [nil]\n")
50 // Do the work here
51 var v MessageData
52 sh := Headers{HK_DESTINATION, d, HK_SUPPRESS_CL, "yes"}
53 for tn, tv := range tsclData {
55 e = conn.SendBytes(sh, tv.ba)
56 if e != nil {
57 t.Fatalf("TestSuppressContentLength Expected no send error, got [%v]\n",
60 select {
61 case v = <-sc:
62 case v = <-conn.MessageData:
63 t.Fatalf("TestSuppressContentLength Expected no RECEIPT/ERROR error, got [%v]\n",
66 if tv.wanted != string(v.Message.Body) {
67 t.Fatalf("TestSuppressContentLength Expected same data, tn:%d wanted[%v], got [%v]\n",
68 tn, tv.wanted, string(v.Message.Body))
72 // Finally Unsubscribe
73 uh := Headers{HK_DESTINATION, d, HK_ID, id}
74 e = conn.Unsubscribe(uh)
75 if e != nil {
76 t.Fatalf("TestSuppressContentLength Expected no unsubscribe error, got [%v]\n",
80 checkReceived(t, conn, false)
81 e = conn.Disconnect(empty_headers)
82 checkDisconnectError(t, e)
83 _ = closeConn(t, n)
88 Test suppress_content_type header.
90 func TestSuppressContentType(t *testing.T) {
91 for _, sp := range Protocols() {
92 n, _ = openConn(t)
93 ch := login_headers
94 ch = headersProtocol(ch, sp)
95 conn, e = Connect(n, ch)
96 if e != nil {
97 t.Fatalf("TestSuppressContentType CONNECT Failed: e:<%q> connresponse:<%q>\n",
99 conn.ConnectResponse)
101 // l := log.New(os.Stdout, "TSCT", log.Ldate|log.Lmicroseconds)
102 // conn.SetLogger(l)
105 d := tdest("/queue/suppress.content.type")
106 id := Uuid()
107 sbh := Headers{HK_DESTINATION, d, HK_ID, id}
108 sc, e = conn.Subscribe(sbh)
109 if e != nil {
110 t.Fatalf("TestSuppressContentType Expected no subscribe error, got [%v]\n",
113 if sc == nil {
114 t.Fatalf("TestSuppressContentType Expected subscribe channel, got [nil]\n")
117 // Do the work here
118 var v MessageData
119 var sh Headers
120 for tn, tv := range tsctData {
121 if tv.doSuppress {
122 sh = Headers{HK_DESTINATION, d, HK_SUPPRESS_CT, "yes"}
123 } else {
124 // sh = Headers{HK_DESTINATION, d, HK_SUPPRESS_CT}
125 sh = Headers{HK_DESTINATION, d}
128 e = conn.Send(sh, tv.body)
129 if e != nil {
130 t.Fatalf("TestSuppressContentType Expected no send error, got [%v]\n",
133 // fmt.Printf("SCT01 tn:%d sent:%s\n", tn, tv.body)
134 select {
135 case v = <-sc:
136 case v = <-conn.MessageData:
137 t.Fatalf("TestSuppressContentType Expected no RECEIPT/ERROR error, got [%v]\n",
140 _, try := v.Message.Headers.Contains(HK_CONTENT_TYPE)
141 // fmt.Printf("DUMP: md:%#v\n", v)
142 if tv.doSuppress {
143 if try != tv.wanted {
144 t.Fatalf("TestSuppressContentType tn:%d wanted:%t got:%t\n",
145 tn, tv.wanted, try)
149 // Finally Unsubscribe
150 uh := Headers{HK_DESTINATION, d, HK_ID, id}
151 e = conn.Unsubscribe(uh)
152 if e != nil {
153 t.Fatalf("TestSuppressContentType Expected no unsubscribe error, got [%v]\n",
157 checkReceived(t, conn, false)
158 e = conn.Disconnect(empty_headers)
159 checkDisconnectError(t, e)
160 _ = closeConn(t, n)