21
21
import static org .junit .Assert .assertEquals ;
22
22
import static org .junit .Assert .assertNotNull ;
23
23
24
+ import java .math .BigInteger ;
24
25
import java .util .ArrayList ;
25
26
import java .util .Arrays ;
26
27
import java .util .Iterator ;
27
28
import java .util .List ;
29
+ import java .util .UUID ;
28
30
29
31
import org .json .JSONException ;
30
32
import org .junit .Test ;
42
44
import com .redhat .lightblue .metadata .ReferenceField ;
43
45
import com .redhat .lightblue .metadata .SimpleArrayElement ;
44
46
import com .redhat .lightblue .metadata .SimpleField ;
45
- import com .redhat .lightblue .metadata .Type ;
47
+ import com .redhat .lightblue .metadata .types .BigDecimalType ;
48
+ import com .redhat .lightblue .metadata .types .BigIntegerType ;
49
+ import com .redhat .lightblue .metadata .types .BinaryType ;
46
50
import com .redhat .lightblue .metadata .types .BooleanType ;
47
51
import com .redhat .lightblue .metadata .types .DateType ;
52
+ import com .redhat .lightblue .metadata .types .DoubleType ;
48
53
import com .redhat .lightblue .metadata .types .IntegerType ;
49
54
import com .redhat .lightblue .metadata .types .StringType ;
55
+ import com .redhat .lightblue .metadata .types .UIDType ;
56
+ import com .redhat .lightblue .util .JsonDoc ;
50
57
import com .redhat .lightblue .util .Path ;
51
58
import com .unboundid .ldap .sdk .Attribute ;
52
59
import com .unboundid .ldap .sdk .SearchResult ;
@@ -124,15 +131,14 @@ public void testTranslate_SimpleField_Boolean() throws JSONException{
124
131
}
125
132
126
133
@ Test
127
- public void testTranslate_SimpleField_Date () throws JSONException {
128
- //Note in and out data are formatted differently
134
+ public void testTranslate_SimpleField_BigDecimalType () throws JSONException {
129
135
SearchResult result = fakeSearchResult (
130
136
new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
131
- new Attribute ("key" , "20150109201731.570Z" )
137
+ new Attribute ("key" , String . valueOf ( Double . MAX_VALUE ) )
132
138
}));
133
139
134
140
EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
135
- new SimpleField ("key" , DateType .TYPE )
141
+ new SimpleField ("key" , BigDecimalType .TYPE )
136
142
);
137
143
138
144
List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
@@ -141,58 +147,128 @@ public void testTranslate_SimpleField_Date() throws JSONException{
141
147
assertEquals (1 , documents .size ());
142
148
143
149
JSONAssert .assertEquals (
144
- "{\" key\" :\" 20150109T20:17:31.570+0000 \ " ,\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
150
+ "{\" key\" :" + String . valueOf ( Double . MAX_VALUE ) + ",\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
145
151
documents .get (0 ).getOutputDocument ().toString (),
146
152
true );
147
153
}
148
154
149
- @ Test ( expected = UnsupportedOperationException . class )
150
- public void testTranslate_SimpleField_Unknown () throws JSONException {
155
+ @ Test
156
+ public void testTranslate_SimpleField_BigIntegerType () throws JSONException {
151
157
SearchResult result = fakeSearchResult (
152
158
new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
153
- new Attribute ("uid " , "john.doe" )
159
+ new Attribute ("key " , BigInteger . ZERO . toString () )
154
160
}));
155
161
156
162
EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
157
- new SimpleField ("uid" , new Type (){
163
+ new SimpleField ("key" , BigIntegerType .TYPE )
164
+ );
158
165
159
- @ Override
160
- public String getName () {
161
- throw new UnsupportedOperationException ("Method should never be called." );
162
- }
166
+ List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
163
167
164
- @ Override
165
- public boolean supportsEq () {
166
- throw new UnsupportedOperationException ("Method should never be called." );
167
- }
168
+ assertNotNull (documents );
169
+ assertEquals (1 , documents .size ());
168
170
169
- @ Override
170
- public boolean supportsOrdering () {
171
- throw new UnsupportedOperationException ("Method should never be called." );
172
- }
171
+ JSONAssert .assertEquals (
172
+ "{\" key\" :" + BigInteger .ZERO + ",\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
173
+ documents .get (0 ).getOutputDocument ().toString (),
174
+ true );
175
+ }
173
176
174
- @ Override
175
- public JsonNode toJson (JsonNodeFactory factory , Object value ) {
176
- throw new UnsupportedOperationException ("Method should never be called." );
177
- }
177
+ @ Test
178
+ public void testTranslate_SimpleField_DoubleType () throws JSONException {
179
+ SearchResult result = fakeSearchResult (
180
+ new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
181
+ new Attribute ("key" , String .valueOf (Double .MAX_VALUE ))
182
+ }));
178
183
179
- @ Override
180
- public Object fromJson (JsonNode value ) {
181
- throw new UnsupportedOperationException ("Method should never be called." );
182
- }
184
+ EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
185
+ new SimpleField ("key" , DoubleType .TYPE )
186
+ );
183
187
184
- @ Override
185
- public int compare (Object v1 , Object v2 ) {
186
- throw new UnsupportedOperationException ("Method should never be called." );
187
- }
188
+ List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
188
189
189
- @ Override
190
- public Object cast (Object v ) {
191
- throw new UnsupportedOperationException ("Method should never be called." );
192
- }
190
+ assertNotNull (documents );
191
+ assertEquals (1 , documents .size ());
192
+
193
+ JSONAssert .assertEquals (
194
+ "{\" key\" :" + String .valueOf (Double .MAX_VALUE ) + ",\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
195
+ documents .get (0 ).getOutputDocument ().toString (),
196
+ true );
197
+ }
198
+
199
+ @ Test
200
+ public void testTranslate_SimpleField_UIDType () throws JSONException {
201
+ String uuid = UUID .randomUUID ().toString ();
202
+
203
+ SearchResult result = fakeSearchResult (
204
+ new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
205
+ new Attribute ("key" , uuid )
193
206
}));
194
207
195
- new ResultTranslator (factory ).translate (result , md );
208
+ EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
209
+ new SimpleField ("key" , UIDType .TYPE )
210
+ );
211
+
212
+ List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
213
+
214
+ assertNotNull (documents );
215
+ assertEquals (1 , documents .size ());
216
+
217
+ JSONAssert .assertEquals (
218
+ "{\" key\" :" + uuid + ",\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
219
+ documents .get (0 ).getOutputDocument ().toString (),
220
+ true );
221
+ }
222
+
223
+ @ Test
224
+ public void testTranslate_SimpleField_BinaryType () throws Exception {
225
+ byte [] bite = new byte []{1 , 2 , 3 , 'a' , 'b' , 'c' };
226
+
227
+ SearchResult result = fakeSearchResult (
228
+ new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
229
+ new Attribute ("key" , bite )
230
+ }));
231
+
232
+ EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
233
+ new SimpleField ("key" , BinaryType .TYPE )
234
+ );
235
+
236
+ List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
237
+
238
+ assertNotNull (documents );
239
+ assertEquals (1 , documents .size ());
240
+ JsonDoc document = documents .get (0 ).getOutputDocument ();
241
+
242
+ JsonNode keyNode = document .get (new Path ("key" ));
243
+ assertEquals (bite , keyNode .binaryValue ());
244
+
245
+ JSONAssert .assertEquals (
246
+ "{\" key\" :\" " + keyNode .asText () + "\" ,\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
247
+ document .toString (),
248
+ true );
249
+ }
250
+
251
+ @ Test
252
+ public void testTranslate_SimpleField_Date () throws JSONException {
253
+ //Note in and out data are formatted differently
254
+ SearchResult result = fakeSearchResult (
255
+ new SearchResultEntry (-1 , "uid=john.doe,dc=example,dc=com" , new Attribute []{
256
+ new Attribute ("key" , "20150109201731.570Z" )
257
+ }));
258
+
259
+ EntityMetadata md = fakeEntityMetadata ("fakeMetadata" ,
260
+ new SimpleField ("key" , DateType .TYPE )
261
+ );
262
+
263
+ List <DocCtx > documents = new ResultTranslator (factory ).translate (result , md );
264
+
265
+ assertNotNull (documents );
266
+ assertEquals (1 , documents .size ());
267
+
268
+ JSONAssert .assertEquals (
269
+ "{\" key\" :\" 20150109T20:17:31.570+0000\" ,\" dn\" :\" uid=john.doe,dc=example,dc=com\" }" ,
270
+ documents .get (0 ).getOutputDocument ().toString (),
271
+ true );
196
272
}
197
273
198
274
@ Test
0 commit comments