-
Notifications
You must be signed in to change notification settings - Fork 114
/
java_lang_test.go
227 lines (193 loc) · 5.96 KB
/
java_lang_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hessian
import (
"testing"
)
import (
"github.com/stretchr/testify/assert"
)
func TestDecodeJavaSingleShort(t *testing.T) {
var i int32 = 123
got, err := decodeJavaResponse(`customReplySingleShort`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, i, got)
}
func TestDecodeJavaShortArray(t *testing.T) {
var a int16 = 123
var b int16 = -456
arr := []*int16{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaShortArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleInteger(t *testing.T) {
var i int32 = 123
got, err := decodeJavaResponse(`customReplySingleInteger`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, i, got)
}
func TestDecodeJavaIntegerArray(t *testing.T) {
var a int32 = 123
var b int32 = -456
arr := []*int32{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaIntegerArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleLong(t *testing.T) {
var i int64 = 12345
got, err := decodeJavaResponse(`customReplySingleLong`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, i, got)
}
func TestDecodeJavaLongArray(t *testing.T) {
var a int64 = 12345
var b int64 = -67890
arr := []*int64{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaLongArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleBoolean(t *testing.T) {
var b = true
got, err := decodeJavaResponse(`customReplySingleBoolean`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, b, got)
}
func TestDecodeJavaBooleanArray(t *testing.T) {
var a = true
var b = false
arr := []*bool{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaBooleanArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleByte(t *testing.T) {
var b int32 = 'A'
got, err := decodeJavaResponse(`customReplySingleByte`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, b, got)
}
func TestDecodeJavaByteArray(t *testing.T) {
var a byte = 'A'
var b byte = 'C'
arr := []*byte{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaByteArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleFloat(t *testing.T) {
var b = 1.23
got, err := decodeJavaResponse(`customReplySingleFloat`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, b, got)
}
func TestDecodeJavaFloatArray(t *testing.T) {
var a float32 = 1.23
var b float32 = 4.56
arr := []*float32{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaFloatArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleDouble(t *testing.T) {
var b = 1.23
got, err := decodeJavaResponse(`customReplySingleDouble`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, b, got)
}
func TestDecodeJavaDoubleArray(t *testing.T) {
var a = 1.23
var b = 4.56
arr := []*float64{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaDoubleArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
func TestDecodeJavaSingleCharacter(t *testing.T) {
var b = "A"
got, err := decodeJavaResponse(`customReplySingleCharacter`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, b, got)
}
func TestDecodeJavaCharacterArray(t *testing.T) {
var a = 'A'
var b = 'C'
arr := []*rune{&a, nil, &b}
got, err := decodeJavaResponse(`customReplyJavaCharacterArray`, ``, false)
assert.NoError(t, err)
t.Logf("%T %+v", got, got)
assert.Equal(t, arr, got)
}
type JavaLangObjectHolder struct {
FieldInteger *int32 `json:"fieldInteger"`
FieldLong *int64 `json:"fieldLong"`
FieldBoolean *bool `json:"fieldBoolean"`
FieldShort *int16 `json:"fieldShort"`
FieldByte *int8 `json:"fieldByte"`
FieldFloat *float32 `json:"fieldFloat"`
FieldDouble *float64 `json:"fieldDouble"`
FieldCharacter *Rune `json:"fieldCharacter"`
}
func (h JavaLangObjectHolder) JavaClassName() string {
return "test.model.JavaLangObjectHolder"
}
func TestDecodeJavaLangObjectHolder(t *testing.T) {
var a int32 = 123
var b int64 = 456
var c = true
var d int16 = 789
var e int8 = 12
var f float32 = 3.45
var g = 6.78
var h Rune = 'A'
obj := &JavaLangObjectHolder{
FieldInteger: &a,
FieldLong: &b,
FieldBoolean: &c,
FieldShort: &d,
FieldByte: &e,
FieldFloat: &f,
FieldDouble: &g,
FieldCharacter: &h,
}
RegisterPOJO(obj)
got, err := decodeJavaResponse(`customReplyJavaLangObjectHolder`, ``, false)
assert.NoError(t, err)
t.Logf("customReplyJavaLangObjectHolder: %T %+v", got, got)
assert.Equal(t, obj, got)
got, err = decodeJavaResponse(`customReplyJavaLangObjectHolderForNull`, ``, false)
assert.NoError(t, err)
t.Logf("customReplyJavaLangObjectHolderForNull: %T %+v", got, got)
assert.Equal(t, &JavaLangObjectHolder{}, got)
}