@@ -18,31 +18,65 @@ public class RpcByteArrayDataSourceTests {
18
18
public void rpcByteArrayDataSource_To_byteArray () {
19
19
String sourceKey = "testByteArray" ;
20
20
String expectedString = "Example String" ;
21
- byte [] inputBytes = expectedString .getBytes ();
21
+ byte [] inputBytes = expectedString .getBytes ();
22
22
ByteString inputByteString = ByteString .copyFrom (inputBytes );
23
23
RpcByteArrayDataSource stringData = new RpcByteArrayDataSource (sourceKey , inputByteString );
24
-
25
24
26
25
Optional <BindingData > actualBindingData = stringData .computeByName (sourceKey , byte [].class );
27
26
BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
28
- byte [] actualBytes = (byte [])actualArg .getValue ();
29
- String actualString = new String (actualBytes );
27
+ byte [] actualBytes = (byte []) actualArg .getValue ();
28
+ String actualString = new String (actualBytes );
30
29
assertEquals (actualString , expectedString );
31
30
}
32
-
31
+
33
32
@ Test
34
33
public void rpcByteArrayDataSource_To_ByteArray () {
35
34
String sourceKey = "testByteArray" ;
36
35
String expectedString = "Example String" ;
37
- byte [] inputBytes = expectedString .getBytes ();
36
+ byte [] inputBytes = expectedString .getBytes ();
38
37
ByteString inputByteString = ByteString .copyFrom (inputBytes );
39
38
RpcByteArrayDataSource stringData = new RpcByteArrayDataSource (sourceKey , inputByteString );
40
-
41
39
42
40
Optional <BindingData > actualBindingData = stringData .computeByName (sourceKey , Byte [].class );
43
41
BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
44
- Byte [] actualBytes = (Byte [])actualArg .getValue ();
45
- String actualString = new String (ArrayUtils .toPrimitive (actualBytes ));
42
+ Byte [] actualBytes = (Byte []) actualArg .getValue ();
43
+ String actualString = new String (ArrayUtils .toPrimitive (actualBytes ));
46
44
assertEquals (actualString , expectedString );
47
45
}
46
+
47
+ @ Test
48
+ public void rpcByteArrayDataSource_To_POJO () {
49
+ String sourceKey = "testByteArray" ;
50
+ String expectedString = "{\" blobText\" :\" Example String\" }" ;
51
+ TestBlobData testBlobData = new TestBlobData ();
52
+ testBlobData .blobText = "Example String" ;
53
+ byte [] inputBytes = expectedString .getBytes ();
54
+ ByteString inputByteString = ByteString .copyFrom (inputBytes );
55
+ RpcByteArrayDataSource stringData = new RpcByteArrayDataSource (sourceKey , inputByteString );
56
+
57
+ Optional <BindingData > actualBindingData = stringData .computeByName (sourceKey ,
58
+ TestBlobData .class );
59
+ BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
60
+ TestBlobData actualBlobData = (TestBlobData ) actualArg .getValue ();
61
+ assertEquals (actualBlobData .blobText , testBlobData .blobText );
62
+ }
63
+
64
+ @ Test
65
+ public void rpcByteArrayDataSource_To_String () {
66
+ String sourceKey = "testByteArray" ;
67
+ String expectedString = "Example String" ;
68
+ byte [] inputBytes = expectedString .getBytes ();
69
+ ByteString inputByteString = ByteString .copyFrom (inputBytes );
70
+ RpcByteArrayDataSource stringData = new RpcByteArrayDataSource (sourceKey , inputByteString );
71
+
72
+ Optional <BindingData > actualBindingData = stringData .computeByName (sourceKey ,
73
+ String .class );
74
+ BindingData actualArg = actualBindingData .orElseThrow (WrongMethodTypeException ::new );
75
+ String actualBlobData = (String ) actualArg .getValue ();
76
+ assertEquals (actualBlobData , expectedString );
77
+ }
78
+
79
+ public static class TestBlobData {
80
+ public String blobText ;
81
+ }
48
82
}
0 commit comments