A correction to the previous commit.
[stompngo.git] / shovel_dupe_headers_test.go
blob4ad682bdd33f0940d401156e03fceb1afae8cdb7
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 (
20 "log"
21 "testing"
24 var _ = log.Println
27 Test a Stomp 1.1+ duplicate header shovel.
28 The Stomp 1.0 specification level is silent on the subject of duplicate
29 headers. For STOMP 1.1+ this client package is strictly compliant: if user
30 logic passes duplicates, they are sent to the broker.
31 The STOMP 1.1 and 1.2 specifications:
32 a) differ slightly in specified broker behavior
33 b) allow quite a bit of variance in broker behavoir.
34 As usual: YMMV.
36 func TestShovelDupeHeaders(t *testing.T) {
37 for _, sp := range oneOnePlusProtos {
38 n, _ = openConn(t)
39 ch := login_headers
40 ch = headersProtocol(ch, sp)
41 conn, e = Connect(n, ch)
42 if e != nil {
43 t.Fatalf("TestShovelDupeHeaders CONNECT expected no error, got [%v]\n", e)
47 ms := "A message"
48 d := tdest("/queue/subunsub.shovel.01")
49 sh := Headers{HK_DESTINATION, d}
50 sh = sh.AddHeaders(tsdhHeaders)
51 _ = conn.Send(sh, ms)
53 sbh := Headers{HK_DESTINATION, d, HK_ID, d}
54 sc, e = conn.Subscribe(sbh)
55 if e != nil {
56 t.Fatalf("TestShovelDupeHeaders Expected no subscribe error, got [%v]\n", e)
58 if sc == nil {
59 t.Fatalf("TestShovelDupeHeaders Expected subscribe channel, got [nil]\n")
62 // Read MessageData
63 var md MessageData
64 select {
65 case md = <-sc:
66 case md = <-conn.MessageData:
67 t.Fatalf("TestShovelDupeHeaders read channel error: expected [nil], got: [%v]\n",
68 md.Message.Command)
72 if md.Error != nil {
73 t.Fatalf("TestShovelDupeHeaders Expected no message data error, got [%v]\n",
74 md.Error)
76 rm := md.Message
77 //log.Printf("TestShovelDupeHeaders SDHT01: %s <%v>\n", conn.Protocol(),
78 // rm.Headers)
79 rd := rm.Headers.Value(HK_DESTINATION)
80 if rd != d {
81 t.Fatalf("TestShovelDupeHeaders Expected destination [%v], got [%v]\n",
82 d, rd)
84 rs := rm.Headers.Value(HK_SUBSCRIPTION)
85 if rs != d {
86 t.Fatalf("TestShovelDupeHeaders Expected subscription [%v], got [%v]\n",
87 d, rs)
90 // Broker behavior can differ WRT repeated header entries
91 // they receive. Here we try to adjust to observed broker behavior
92 // with the brokers used in local testing.
93 // Also note that the wording of the 1.1 and 1.2 specs is slightly
94 // different WRT repeated header entries.
95 // In any case: YMMV.
98 switch brokerid {
99 case TEST_AMQ:
100 if !rm.Headers.ContainsKV("dupkey1", "value0") {
101 t.Fatalf("TestShovelDupeHeaders AMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
103 case TEST_RMQ:
104 if !rm.Headers.ContainsKV("dupkey1", "value0") {
105 t.Fatalf("TestShovelDupeHeaders RMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
107 case TEST_APOLLO:
108 if !rm.Headers.ContainsKV("dupkey1", "value0") {
109 t.Fatalf("TestShovelDupeHeaders APOLLO Expected true for [%v], [%v]\n", "dupkey1", "value0")
111 e = checkDupeHeaders(rm.Headers, wantedDupeVAll)
112 if e != nil {
113 t.Fatalf("TestShovelDupeHeaders APOLLO Expected dupe headers, but something is missing: %v %v\n",
114 rm.Headers, wantedDupeVAll)
116 case TEST_ARTEMIS:
118 if sp == SPL_11 {
119 if !rm.Headers.ContainsKV("dupkey1", "value2") {
120 t.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value2")
122 } else { // This is SPL_12
123 if !rm.Headers.ContainsKV("dupkey1", "value0") {
124 t.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value0")
127 break
129 default:
132 uh := Headers{HK_ID, rs, HK_DESTINATION, d}
133 e = conn.Unsubscribe(uh)
134 if e != nil {
135 t.Fatalf("TestShovelDupeHeaders Expected no unsubscribe error, got [%v]\n",
139 checkReceived(t, conn, false)
140 e = conn.Disconnect(empty_headers)
141 checkDisconnectError(t, e)
142 _ = closeConn(t, n)